Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup
January 22, 2008 by Justin CutroniThis is part 2 in my series on Google Analytics e-commerce tracking. In part 1 I described, at a conceptual level, how GA e-commerce tracking works. In this post I’ll get into the specifics of the code and how to install it.
This isn’t the most exciting stuff (that will be part 3), but a correct setup leads to correct data. :)
Step 1: Activate the Reports
The first step in setting up GA e-commerce tracking is enabling the e-commerce reports. Log into GA and edit the profile settings. Specify that your site is an e-commerce site. This activates the e-commerce reports.

There are other e-commerce settings that don’t get much use (unless you’re an international site). You can specify one of 25 different currencies (wow!) and the number of decimal places you would like displayed (1,2 or 3). Even if you use USD you can specify 3 decimal places. Go ahead and try it, it’s interesting.
Remember, e-commerce reports is a profile setting that is “off” by default. You’ll need to activate the reports for each new profile you create.
Step 2: Tag your Receipt Page
I know this seems like a silly step, but make sure you add the GA tracking code you your receipt page. You must have the standard GA tracking code on your receipt page in order to track transactions. The reason is that the e-commerce tracking code is stored in the ga.js. If this file is not included on the receipt page then you can’t track transactions.
Step 3: Install the Code
This is the hard part: code construction. As we learned in part 1, GA uses a JavaScript collection technique to track e-commerce transactions. Your server code must inject transaction information into the GA JavaScript before sending the receipt page back to the browser. When the receipt page renders in the visitor’s browser the JavaScipt executes and sends the transaction info to GA.

Let’s take a look at the code:
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);
pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);
pageTracker._trackTrans();
</script>
The first thing that you’ll notice is that there are three distinct parts to the JavaScript. Each is a different method. The first section, identified by the _addTrans() method, creates the transaction and stores all the information about the transaction.
The second section, identified by the _addItem() method, is used to add an item to the transaction. You need to create an _addItem() section for each different item, or SKU, in the transaction. The order ID in the _addItem() method must be the same order ID used in the _addTrans() method. That’s how GA ties an item to a transactions.
The final section is the _trackTrans() method. This method actually sends the data to GA by requesting the __utm.gif file once for the transaction and once for each item in the transaction. So if you have 3 different SKUs in a transaction there will be 4 requests fot the __utm.gif.
The above JavaScript can appear anywhere on your receipt page. Just make sure that it appears after the main GA page tag. The reason is that the e-commerce code is part of the pageTracker object. If the pageTracker object has not been created then you can’t call the e-commerce methods.
Just to reiterate a point: you must create server side code that outputs the transaction data in the format above. If you do not have access to your shopping cart code, and your cart provider does not provide e-commerce tracking, then you may be out of luck.
Once the code has been installed you should begin to see e-commerce data in your reports.
Notes and Suggestions
Like many things in Google Analytics, there are some things that can trip you up:
- If you do not wish to pass a certain piece of data to GA then do not add anything between the quotation marks. The only required fields are the order ID, the unit price of each item and the quantity of each item. Everything else is optional.
- Do not use currency identifiers or commas (to separate thousands) in any of the numeric fields (i.e. total, tax, shipping). These characters have caused problems in the past.
- Each piece of transaction data that you send to Google Analytics becomes a data element in GA, just like any other piece of data in GA (geo data, campaign data, browser data, etc.). You can do all sorts of neat things with filters and e-commerce data. More on this later.
- The affiliate or store name field is no longer used in the GA reports. However, the data is still collected by GA so you can use it in a filter.
- The transaction geographic data collected by GA is no longer used BUT it is collected. Google Analytics determines the location of the user, and thus their transaction, based on their IP address. The old version of the GA tracking code used the data specified in the transaction. Like the affiliate field, the data can be used in a filter.
Up Next
In the next post I’m going to talk about some creative ways to use e-commerce tracking. Specifically, why I believe that everyone should use e-commerce tracking on their website.
Subscribe:









11 Responses to “Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup”
How is this data sent to Google? From what I see in the above code, there is no actual way to make sure the data is encrypted before it is sent out. It looks like it is sent in plain text to Google.
Is this really the case?
By Chris on Jan 23, 2008
Thanks so much for these and other articles.
What I like the most is the simple language, detailed explanations, and images of how to implement code, modify and change code for various results.
- Your material has helped me so much in the way of Google Analytics, especially with a recent U.K. PPC client that has several sites and services. I read, collected, and passed along your articles to their programmer and we are on our way to more informed analytics understanding and reports.
Keep up the excellent work!
A new admirer.
Alex
By Alex on Jan 23, 2008
I think I said this last time, but this is a great quick-reference for anyone beginning to do e-commerce implementations - very concise and to the point.
By Jeremy on Jan 23, 2008
Hi, Thanks for your informative post, can you share a detailed example on how to implement this ecom code. I have been trying to get it to work on my website without much luck, GA tracks some transactions but doesnt track others.
Thanks,
Ram
By Ram on Jan 23, 2008
Alex & Jeremy,
Thanks so much. I’m really glad you guys find these posts useful. If you have any suggestions as to how I can improve them please let me know. Or if there is s topic you would like discussed please let me know.
Thanks again,
Justin
By Justin Cutroni on Jan 24, 2008
Chris,
The data is sent to Google via a request for the __utm.gif file. The data is not encrypted, however, if your receipt page is on a secure server, you can use the secure version of the GA tracking code. This creates a secure request for the __utm.gif file.
Thanks for the question,
Justin
By Justin Cutroni on Jan 24, 2008
Hi Ram,
It’s not uncommon for GA to miss some transactions. As long as your data is within 10% of actual then you’re doing OK. Many things can contribute to missing transactions… visitors blocking cookies or disabling JS. It may be that people are navigating away from your receipt page before the transaction is sent to GA.
I know that doesn’t help much, but, as I said before, if you’re within 10% of your actual numbers then you’re doing well.
Sorry I did not have a better answer for you.
Justin
By Justin Cutroni on Jan 24, 2008
Hi Justin,
Thanks for responding, I changed the code to make it more useful & made a few mistakes. I had extra which I realized was a mistake thanks to your post.
Thanks
Ram
By Ram on Jan 25, 2008
Great article. helps a lot, thanks.
By Tech News on Feb 8, 2008
Hey Justin.
For readers who are also using Google Website Optimizer, I just published a simple way to get combine GWO and revenue data in GA:
http://www.prusak.com/archives/2008-02-28/revenue-tracking-with-google-website-optimizer/
- Ophir
By Ophir Prusak on Feb 28, 2008
Hi Justin,
Just wondering when you are going to publish Part III to this helpful article?
By Jeff on Mar 11, 2008