Adam Howitt's Blog

Dec 14
2006

Smart Marketing with Google Analytics order tracking

Edward had asked about the code I used in Google Analytics to track each transaction. This allows you to see a wealth of information, not just product revenue through the website.  When you add the transaction logging to your order complete or "thank you" page, google updates the basic reports it offers with an extra column so each minute piece of data can be cross referenced against the revenue it generated.  For example:

  1. New vs returning customers - how much revenue (total and average) did each segment generate.  This report can help you focus your marketing efforts to either increase first time spend or provide discounts for returning users to encourage them to buy more and reward their loyalty.
  2. Which referring sources were responsible for the most revenue on the site?  The report columns are all sortable so rather than see which affiliate drove the most traffic to your site, which affiliate drives the biggest spenders?  It can help you review your marketing spend with affiliates so you can focus your budget on the people whose visitors are more likely to buy from you.
  3. What is the ROI on your Google adwords campaign?  One client spent nearly 3000 dollars per month on adwords campaigns that yielded just 21 dollars in revenue and one sale.  He had already asked why Google drove 50% of his traffic and MSN and Yahoo were so small in comparison.  I suggested that moving his adwords budget to the search engines without organic presence would make sure he had the exposure he needed at MSN and Yahoo and help adjust the balance.

The CF code I use comes in two parts.  The first creates a structure of the items in his order in the act file after his order is processed:

<cfscript>
    utm_trans = structNew();
    utm_trans.order_id = client.order_header_id;
    utm_trans.affiliation = 'Name of the Affiliate program';
    utm_trans.total = variables.grandtotal;
    utm_trans.tax = variables.grandtaxes;
    utm_trans.shipping = variables.grandshipcost;
    utm_trans.city = get_shipaddress.city;
    utm_trans.state = get_shipaddress.region;
    utm_trans.country = 'USA';
    utm_trans.items = queryNew('order_id,sku,productname,category,price,quantity');
    //add code to populate utm_trans.items query here
</cfscript>
The second chunk of code is responsible for putting the hidden form on the page in the correct format for Google.  You may note that I use cftry/cfcatch around it all with no action in the cfcatch.  I did this in case anything odd occurred to prevent the google tracking code from creating a customer service call for the client.  You could easily add a simple cfmail to say there was a problem
<cfoutput>
<cftry>
<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|#utm_trans.order_id#|#utm_trans.affiliation#|#utm_trans.total#|#utm_trans.tax#|#utm_trans.shipping#|#utm_trans.city#|#utm_trans.state#|#utm_trans.country#
<cfloop query="utm_trans.items">UTM:I|#utm_trans.items.order_id#|#utm_trans.items.sku#|#utm_trans.items.productname#|#utm_trans.items.category#|#utm_trans.items.price#|#utm_trans.items.quantity#
</cfloop></textarea>
</form>
<script language="text/javascript">
__utmSetTrans();
</script>
<cfcatch type="any"></cfcatch>
</cftry></cfoutput>

The first chunk creates the transaction wrapper (starts with UTM:T) then I loop over my collection of items to build the item rows (start with UTM:I).  The last part is the __utmSetTrans() which sends the transaction to Google.

If you have found this useful or have any questions about Google Analytics, feel free to let me know in the comments section.  I have worked very closely with both the code implementation and reviewing the results to make recommendations. 

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
[Add Comment] [Subscribe to Comments]
  1. Adam, Thanks for posting your code and instructions. It was really helpful.

    Edward

  2. Adam,

    I use Google Analytics, and I'd like to do segmentation based on revenue. I'd like to focus on customers who produce a lot of revenue and see which AdWords key words bring in these valuable customers.

    The problem is, when someone becomes a customer on our site, they have not yet spent any money. The revenue rolls in over the months.

    Is there a clever way in Google Analytics to focus on high revenue customers, so I can see where they come from and optimize marketing to attract more high revenue customers?

    Thanks!

  3. Hi Greg, Great question! First I'll show you how to find high revenue customers generally then address your issue where people spend money over several months.

    In the new reporting interface if you go to the "traffic sources" menu item on the left of your reporting interface and select "all traffic sources" you are nearly there. If you have correctly configured e-commerce tracking you should see three tabs above the table of results on the page "Site usage", "Goal Conversion" and "Ecommerce". Select "Ecommerce" and the table shows different columns. Left-click your mouse on the column "revenue" and your report is now a sorted list of the referring sites generating the highest revenue for you.

    The other sort order you can use would be to click the "average value" comment to see which site refers the customers with the highest average order value which sounds like it might be what you are looking for.

    The last report you may want to look at is under "Traffic Sources" > "Keywords" then select the "Ecommerce" tab and sort the table by "revenue" or "average value".

    Google's cookie typically will keep track of a returning customer to your site so the original referer is maintained. This means the reports I describe above will still help you identify the best keywords and sites for visitors who keep coming back - just look for the highest average revenue referer and keyword.

    If you need to track the average number of transactions per referer you can either set a cookie on the visitors browser incremented each time they place an order and pass that as a custom parameter on the checkout page or a more robust solution would be to query your customer order database on the checkout page to count how many orders they have placed and pass it in the same way. This is more robust because it doesn't rely on the client not deleting cookies periodically. This solution would also allow you to track a different stat too - you could pass the lifetime revenue as a custom parameter on the checkout page. A filter would allow you to translate the values into revenue bands and then under "Visitors" > "User Defined" you could review each revenue band. You have the option of looking at each user defined value cross-referenced by segment (the dropdown) so you can see which referers and keywords are responsible for the highest lifetime value customers.

    Bottom line I think the average revenue will be fine!

    Adam

  4. How would you suggest doing this for an offsite processor such as paypal?

    I actually submit the order on my site and generate an order number then show a button to pay, so was thinking to display the cart code for google on the pay page as though done and have an onclick on the button to go to paypal to pay so that that can be tracked to, the onclick registering a hit to an imaginary paying.cfm?t=paypal (or another processor as we offer a couple).

    Problems I see are:

    1) can I have a goal that is the final imaginary gopay.cfm page but the page before it is actually the one with the cart code for google? (what they confusingly call the "receipt page," I gather.)

    2) It won't actually track carts not paid for. People submit the order then can't pay or just never do sometimes.

    Any ideas?

    Thanks. -I'll try your code, btw, though I don't understand reason behind the cftry. If it fails to call google, it fails, no problem.

  5. Oops, should read:

    -"so that that can be tracked too"

    -"is the final imaginary paying.cfm page."

  6. Hi Ziggy - sorry I missed your note before now. You have a couple of options: 1. I believe this is the most attractive. With PayPal you can specify an auto return URL in the settings so that when the user has finished paying they are auto redirected to a receipt page on your site. On this page you show your custom receipt and include the Google cart tracking code. There is a silent POST option in the API to allow you to get an acknowledgment that the transaction was successful by hitting a CFM page on your server. This is how you can update your records to flag the order as completed so the receipt page accurately reflects the payment 2. If you're not locked in to paypal, I believe Google Checkout automatically tags and captures conversion data and revenue for you http://analytics.blogspot.com/2006/10/google-analytics-google-checkout.html 3. PayPal Standard doesn't allow custom pages but PayPal's payflow link allows you to host pages including your google tracking code on their servers. The next step from there is PayFlow Pro which allows you to process payments from your own site allowing you to track every click. If you go with PayFlow Link you will need to use the cross-site Google Analytics script to let Google know your customer is still in your pipeline otherwise it shows up as a lost customer: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55532&hl=en

    If you need any more help with this I'm becoming an independent consultant in 2 weeks and will be available to help you with the installation if you want. See http://www.adamhowitt.com for my contact form and let me know how to get in touch with you.

    Thanks, Adam

  7. The issue we have is trying to track a customer who comes in to the site and then rings up to complete their order. How do we tell google analytics that they are the same thing?

  8. Hi Phil, This is a big gap right now and a challenge faced by a lot of people. One approach requires some work on your part but you can create a campaign code for each keyword or advertising source and display it on each page in the footer as they browse around. If they call, you have your staff ask them for their unique code. The staff member would do a lookup and store the campaign source in your sales tracking system so you can then review this data with your Google Analytics info.

    If anyone else has come up against this, let us know what you have done. Adam

  9. Interesting but doesn't really help as it would involve matching up two different tracking systems - defeating the object of the analytics.

    I wonder if it is possible to feedback the unique campaign code for that user session back to analytics through the google api? er.. no because Google Analytics does not have an API - damn them!

  10. Well clearly a bit of legwork would be required but there is maybe another way. If you have a unique user session id they can give you over the phone, you could develop a simple web page to take the code, which then submits another page to Google Analytics by recreating the cookie required to maintain their session. It is a programming solution but if you're comfortable with that it might solve the problem. I might work on this early in the new year if I have the time available. I take it that you would be interested in such a system if it existed?

  11. Hi Guys,

    I’ve been trying to integrate GA E-commerce tracking with Paypal for a few weeks now. There doesn’t seem to be a lot of info out there on the subject.

    After a few weeks and a few hundred dollars, I’ve come up with a script that fully integrates Paypal with GA E-commerce. I’ve wrote a free ebook that includes the script you’ll need at no cost.

    There is nothing for sell here. I just wanted to see this info more widely available.

    You can get the ebook from this link.

    http://www.brentcrouch.com/2008/03/02/google-analytics-e-commerce-tracking-using-paypal-pdt/

    Good Luck,

    Brent Crouch

[Add Comment]