11 December 2007 ~ 2 Comments

Tracking E-Commerce Transactions in Google Analytics

A question that any Google Analytics user has is how do I get Dollar Values showing on transactions that take place on my site? The easy answer is giving a Goal Value a specific dollar amount but what if you sell more than one product on your website all of them with different prices? After all, most businesses sell more than one product or service. To do this you need to setup Google Analytics in a dynamic manner that allows you to record the price of any product being sold on your website. Don’t worry for now about which payment gateway your site uses because the basic idea is the same.

The first thing that you need to do is enable Google Analytics by telling it that you are running an e-commerce site with the article I wrote a little while back. Once you’ve done this then the next step is to format and code the receipt page to show dynamic transactions in Google Analytics and you can do this by taking the following steps. The first thing that you need to do is install the basic tracking code, if you haven’t done this then please read my article on installing Google Analytics tracking codes.

<script src=”http://www.google-analytics.com/urchin.js” type=”text/javascript”>
</script>
<script type=”text/javascript”>
_uacct=”UA-xxxx-x”;
urchinTracker();
</script>

Below the tracking code you will want to add the following code. You’ll want to replace the parameters with actual values for it to work correctly.

<form style=”display:none;” name=”utmform”>
<textarea id=”utmtrans”>

UTM:T|[order-id]|[affiliation]| [total]|[tax]| [shipping]|[city]|[state]|[country]

UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|[quantity]
UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|[quantity]
UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|[quantity]
UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|[quantity]
</textarea>
</form>

The next thing to add into the receipt page is a function called utmSetTrans() in the body tag, that allows you to record data related to the purchase of goods on your website in Google Analytics. The code looks like this…

<body onLoad=”javascript:__utmSetTrans()”>

If you cannot edit the body tag then you can always write this function which does exactly the same thing and it looks like this…

<script type=”text/javascript”>
__utmSetTrans();
< /script>

Here is an example of what the code should look like when you are done installing and tweaking the code on your website…

<script src=”http://www.google-analytics.com/urchin.js” type=”text/javascript”>
</script>
<script type=”text/javascript”>
_uacct = “UA-XXXXXXX-X”;
urchinTracker();
</script>

<form style=”display:none;” name=”utmform”>
<textarea id=”utmtrans”>

UTM:T | 12345 | my store | 250.00 | 0.00 | 0.00 | Toronto | Ontario | Canada

UTM:I | 12345 | WF_BB_HandHeld | Pearl BlackBerry | Handheld PDAs | 159.00 | 27
UTM:I | 12345 | WF_Motorola_KRZRv3 | Motorola KRZR v3 | Cell Phones | 195.00 | 13
UTM:I | 12345 | WF_Motorola_RAZRv2 | Motorola RAZR v2 | Cell Phones | 149.00 | 9

</textarea>
</form>

<script type=”text/javascript”>
__utmSetTrans();
< /script>

</body>
</html>

Just make sure that you add the code after the form and you should be good to go. It never fails to amaze me that there is so much that you can do with Google Analytics.

Luc

Related Articles:

2 Responses to “Tracking E-Commerce Transactions in Google Analytics”

  1. Brent Crouch 2 March 2008 at 7:43 pm Permalink

    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


Leave a Reply