Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup

This 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.

Google Analytics 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.

Get ready for some construction.

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 three parts of GA e-commerce trackingThe 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.

This is part 1 in a multi-part series on e-commerce tracking:

Google Analytics E-Commerce Tracking Pt. 1: How It Works
Google Analytics E-Commerce Tracking Pt. 3: Why EVERYONE Should Use It
Google Analytics E-Commerce Tracking Pt. 4: Tacking Lead Gen Forms

Like this post? Share it:


And how about checking out these related posts:

  1. Google Analytics E-Commerce Tracking Pt. 1: How It Works
  2. Google Analytics Installation Guide
  3. GA On Site Search Pt. 1: Overview & Setup
  4. Breaking Up Is Hard To Do: GA Account Setup Tip
  5. Event Tracking Pt. 2: Implementations

Comments

  1. Chris says:

    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?

  2. Alex says:

    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

  3. Jeremy says:

    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.

  4. Ram says:

    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

  5. 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

  6. 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

  7. 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

  8. Ram says:

    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

  9. Lisa says:

    We do a lot of banner advertising on third-part sites. These ads are served through Dart/Double Click, but we want to track via Google Analytics. Any conflicts there? We’ve had some problems utilizing the GA-generated URLs with Double Click in the past, but we’re having a hard time deteriming the root cause.
    Any insights would be helpful.

    Thanks,
    Lisa

  10. Kunal says:

    Hi Justin,

    Your blog is excellent by the way, im finding it extremely helpful!
    Just a quick question (though it might come up in your third ecommerce tracking part):
    We have a site with a US and UK separate URL
    (oursite.com/uk and oursite.com/us). Include filters ensure all our stats are separated fine. However for the commerce tracking, it seems the profile filters do not apply – instead both profiles add together both the UK and US revenue figures etc. Are custom filters able to help me solve this problem and if so how would i go about this?

    Many thanks for your time,
    Kunal

  11. Tech News says:

    Great article. helps a lot, thanks.

  12. Anand says:

    Hi Justin,

    Thanx for this useful information. I have the following question regarding Order with multiple items. Can we repeat pageTracker._addItem ()?

    Regards,
    Anand

  13. Lisa says:

    Justin,
    I appreciate your posts–your delivery is very clear and approachable. Quick question about GA e-commerce tracking: when e-commerce reports are activated, are conversions still based on pageviews or does the new code allow conversions to be calculated by transaction?

    Thank you for your insight,
    Lisa

  14. Swoany says:

    Hi,

    good post…

    i have a question: i want to track more information in the _addItem or _addTrans

    An example:

    pageTracker._addItem(
    “343212″, //order ID
    “DD4444″, //sku
    “Lava Lamp”, // product name
    “Decor”, // category or product variation
    “34.99″, // price
    “1″ //quantity

    “amsterdam” //Departure
    “NewYork” //Destination
    ect..
    );

    Is that possibly in GA ??

    Grtz..swoany

  15. Another great article Justin.

    We have been using GA transaction information for years now. But recently it occured to us that GA’s ROI and Margin metrics may be skewed due to the fact that they reflect gross and not net revenue. We were wondering if perhaps it would be better to send net profit totals for each item and the net profit total.

    For example, if we sell an item for $2.00 that costs us $1.00 to purchase wholesale, should we use $1.00 for the net profit instead of the $2.00? Do you think this provides better ROI and margin information?

    Or should we leave it at the retail price and do the analysis on the backend, ignoring GA for ROI and margin numbers?

    I wish GA would have a product cost field we could populate.

  16. Ophir Prusak says:

    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

  17. Jeff says:

    Hi Justin,

    Just wondering when you are going to publish Part III to this helpful article?

  18. Jonathan says:

    Hey Justin, Where ya been? Keep these great posts coming….

  19. Sanjay says:

    Bought your nice book. Which tips are no longer valid? I wonder because the tracking code is old. Thanks.

  20. John says:

    Great article.

    Am I right in thinking that using this code will allow us to check the price/value of purchases made by a customer?

    It’s sort of making sense to me. It’s the code installation that is confusing me :(

    Thank You

  21. Justin:

    We’ve implemented the ecommerce tracking code exactly as you’ve described, but are still seeing 0 conversions in our goal funnel and $0 on the ecommerce tab, despite making several test purchases.

    Any suggestions on where to begin trouble-shooting?

    Thanks.

  22. john says:

    I noticed eCommerce collects

    pageTracker._addTrans(“order-id”, “affiliate or store name”,”total”,”tax”,”shipping”,”city”,”state”,”country”);

    How do I find the “affiliate or store name”,”city” and “state” information? I tried to check out the map overlay but that just gives me the internet service provider location.

    thanks,
    -John

  23. john says:

    Hi, I noticed eCommerce collects the data:

    pageTracker._addTrans(“order-id”,”affiliate or store name”,”total”,”tax”,”shipping”,”city”,”state”,”country”)

    from all my transactions. I am able to recover “order-id”,”total”,”tax”,and “shipping” from the eCommerce report. I cannot retrieve the “city”,”state”,”country” data acquired.

    I tried viewing the map-overlay but I think this tracks visitors from their ISP. Am I wrong? Is there a way to obtain the “city”,”state”,”country” data acquired in eCommerce?

    thanks,
    -John

  24. Lisa,

    You should be able to use GA to track DoubleClick ads. I would make sure that there are no redirects that are stripping off the campaign parameters. That’s usually the culprit when it comes to campaign tracking issues.

    Thanks for reading,

    Justin

  25. HI Kunal,

    Segmenting e-commerce data is a bit different tan segmenting clickstream traffic. It can be done, but you need to segment it using the Affiliate field.

    What we’ve done in the past is to populate the Affiliate field with something similar to the country value into the affiliate field and then create an include filter based on the affiliate field.

    Hopefully that puts you on the right track.

    Thanks for reading,

    Justin

  26. Anand,

    Yes you can in fact have multiple occurance of adItem(). In fact, you should have a different addItem() section for each different SKU or product in the transaction.

    Justin

  27. Lisa,

    Excellent question. When e-commerce tracing is used, goal conversion for a purchase are based on purchases, not pageviews.

    Thanks for reading,

    Justin

  28. Hi Grtz,

    Yes, you can track more information, but you can not add it in the format that you describe. The data must fit in the format that is specified by Google. You must place any additional informatuon that you want to track in the product field, category field or some other field that Google has defined.

    Good luck,

    Justin

  29. Hi Chuck,

    You make a great point. I think the key is to configure Google Analytics to fit your needs. If you want to measure ROI and Margin based on Net then configure GA appropriately.

    Great observation.

    Justin

  30. stuart says:

    Very helpful write-up — got it up and running in 15 minutes.

    Thanks!

  31. Hi Justin,

    Very useful post! Here a **late** question: you suggest that the basic GATC be somewhere on the page before the transaction code, whereas B. Clifton shows it as embedded in it (p. 117). Does either method work the same?

    Thanks!

  32. Hi Jaques,

    Good to hear from you. Thanks for the question. I don’t have Brian’s book in front of me, but I’m 99% sure it shows the e-commerce code below the main GA tracking code. The format I reference is practically identical to Brian’s. Both will work.

    The key thing is to make sure that you’ve created the pageTracker object before you invoke addTrans or addItem.

    I hope that makes sense.

    Thanks for the question and thanks for reading.

    Justin

  33. Collective says:

    Anyone aware of a Magento module that integrates this?

  34. Hi Collective,

    While I am unfamiliar with Magento, I just did a quick search on Google and found this result.

    Hopefully it has the information that you need.

    Best of luck and thanks for the question.

    Justin

  35. George says:

    Justin,I put the GA code into the js file,
    http://www.yidaba.com/js/topseo.js in page head;
    http://www.yidaba.com/js/bottomseo.js in page bottom.
    For example:http://management.yidaba.com/cwgl/rzzd/6789221.shtml
    Reasonable to do so?

  36. Hi George,

    Yes, you can set the code up that way.

    Thanks for the question,

    Justin

  37. Jinqiu says:

    Hi, could we get the ex-ante surf information before the transaction? I means the pages visited and the average time passed on the site before each purchase?

    Thanks.

  38. Hi Jinqiu,

    There are not a lot of path analysis options in GA. I would suggest using the $Index value is you’re looking to gauge the value of content.

    Hope that helps,

    Justin

  39. Moe says:

    Great post, Justin. I’m at my wits end trying to customise the e-commerce script to my situation, and am hoping you could provide a small bit of advice.

    I’m running a Google Adwords campaign that drives traffic to a survey page.

    I understand that it’s possible to track which ad groups lead to a survey completion by using e-commerce goals.

    But I have no idea how to alter the e-commerce script to include the one variable that I would like to track (i.e. the survey response ID).

    Any suggestions for how a non-techie could learn how to do this?

  40. Todd says:

    I have installed the e-commerce tracking code on my receipts page and have been able to track checkout conversions,however my average order value and revenue indicators are not reporting, can anyone help me trouble shoot this problem.

    Thanks
    TC

  41. Moe,

    If you want to pull one specific value into the ecommerce code then you need to add it to the JavaScript that appears on the receipt page. I suggest adding it to the product name, product description or product category field. Then use the corresponding report to find your data.

    TC,

    There’s probably an issue with the data you’re collecting for revenue and transactions. The two metrics that you’re having trouble are directly related to the data collection, so I would check that first.

    Thanks for the questions,
    Justin

  42. Diego says:

    Thank you very much for this article. Amazingly, the Google documentation incorrectly tells users to put an ‘item number’ where the order id should be placed when using _addItem.

    See this page:
    http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528

    In the example on the page, they even use clearly different values for ‘order id’ and ‘item number’:

    pageTracker._addTrans(
    “1234″,// Order ID

    );
    pageTracker._addItem(
    “5678″,// Item Number

    );

    …this caused analytics to register empty transactions (without any products) and create a new transaction for each item with amount £0. It made a complete mess of my stats and I couldn’t figure out why until I read your article. All makes sense now.

    Thank you!

  43. Nathan says:

    What about any other character problems? I found that double quotes in the product name is a problem. I am thinking single quotes would also be a problem. I am not sure about parens. Are there any others that you’ve come across? GA is only tracking about 25% of our transactions so far.

  44. Hey Nathan,

    You’re right, you want to avoid quotes and any other special characters in the names of products or categories. I would also avoid parens and anything that involves the SHIFT key :)

    Thanks for the comment,

    Justin

  45. Irina says:

    Great comments on reasons why GA sometimes not capturing all the transactions. THANK YOU.

  46. TMosley says:

    In the transaction reports in Google Analytics why would 20-25% of the transactions be missing?

  47. Aswati says:

    Hi,

    I liked the article on using e-commerce on lead generation forms to get more detailed in formation. I was wondering what modifications you would recommend if I wanted to get more detailed information from my booking online form. The information required would be location of hotel they select, the hotel they select, the room the user selects, number of people etc.

    Thanks

  48. Justin says:

    @TMosley: Missing transactions in GA Ecommerce can be for a few different reasons. The most common problem is visitor navigating away from the receipt page before the GA tracking code has a chance to send the data to Google. You may want to move your ecommerce tracking code to the top of the page to increase the likelihood that it’s sent to Google.

    @Aswati: You’re on the right track. If you’ve got a booking form then think of the reservation as a product. What are the characteristics of a reservation? Hotel, room type, etc. You may want to consider capturing visitor choices as part of the ‘product’ information.

    Thanks for the comments,

    Justin

  49. Jon says:

    Still a little unclear on the coding to be put on the receipt page. So are we supppose to put the code into our thankyou.htm page with all the possible variables of an order?
    ie. 1 gallon, color blue, etc..

    or do I put this code into one of our asp page that dynamically retrieves the appropriate page of the orders coming in?

  50. Justin Cutroni says:

    @Jon: The latter. You want to add code to your asp page. The code needs to generate the appropriate GA JS for each order in real time.

    Hope that helps.

Trackbacks

  1. [...] There are three basic steps necessary to use the e-commerce tracking code on a non e-commerce site. While the steps are similar to those described in my previous post on installation there is one big difference. Let’s walk through each step. [...]

  2. [...] Take, for example, the fact that I truly have no clue how to get this google analytics conversion tracking down.  I’ve found this: [...]

  3. [...] Analytics E-Commerce TrackingThis series of article has 4 parts: 1 | 2 | 3 | [...]

  4. [...] Analytics E-Commerce Tracking This series of article has 4 parts: 1 | 2 | 3 | [...]

  5. [...] looks really nice, right? Now, how to get this? You can find here a complete installation & setup tutorial, or, if you are using osCommerce, you can find here an [...]

  6. [...] a PPC advert).Google Analytics E-Commerce Tracking This series of article has 4 parts: 1 | 2 | 3 | 4 Blogs about Google AnalyticsThe official Google Analytics BlogAdvanced Web Metrics A blog [...]

  7. [...] Analytics E-Commerce Tracking This series of article has 4 parts: 1 | 2 | 3 | [...]

  8. [...] can do this varies from cart to cart, but if you’re a “code elf”, the google tutorial and this article do a pretty good job of explaining it in programming terms. Many popular carts have plug-and-play [...]

Speak Your Mind

*