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

January 22, 2008 by Justin Cutroni

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

Share:
  • Digg
  • Technorati
  • del.icio.us
  • Slashdot
  • StumbleUpon
  • Ma.gnolia
  • YahooMyWeb
  • co.mments
  • Reddit
  • Facebook
  • SphereIt
  • TwitThis
  • Yahoo! Buzz
Subscribe:
  1. 48 Responses to “Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup”

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

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

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

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

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

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

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

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

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

    By Lisa on Jan 28, 2008

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

    By Kunal on Feb 7, 2008

  12. Great article. helps a lot, thanks.

    By Tech News on Feb 8, 2008

  13. Hi Justin,

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

    Regards,
    Anand

    By Anand on Feb 15, 2008

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

    By Lisa on Feb 15, 2008

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

    By Swoany on Feb 20, 2008

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

    By Chuck Robinson on Feb 21, 2008

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

  18. Hi Justin,

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

    By Jeff on Mar 11, 2008

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

    By Jonathan on Apr 29, 2008

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

    By Sanjay on May 22, 2008

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

    By John on Jun 6, 2008

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

    By Heidi Strom Moon on Jun 16, 2008

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

    By john on Jun 20, 2008

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

    By john on Jun 24, 2008

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

    By Justin Cutroni on Jun 24, 2008

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

    By Justin Cutroni on Jun 25, 2008

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

    By Justin Cutroni on Jun 25, 2008

  28. Lisa,

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

    Thanks for reading,

    Justin

    By Justin Cutroni on Jun 25, 2008

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

    By Justin Cutroni on Jun 25, 2008

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

    By Justin Cutroni on Jun 25, 2008

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

    Thanks!

    By stuart on Jun 26, 2008

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

    By Jacques Warren on Jul 15, 2008

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

    By Justin Cutroni on Jul 15, 2008

  34. Anyone aware of a Magento module that integrates this?

    By Collective on Jul 24, 2008

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

    By Justin Cutroni on Jul 25, 2008

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

    By George on Aug 14, 2008

  37. Hi George,

    Yes, you can set the code up that way.

    Thanks for the question,

    Justin

    By Justin Cutroni on Aug 15, 2008

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

    By Jinqiu on Sep 26, 2008

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

    By Justin Cutroni on Sep 29, 2008

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

    By Moe on Oct 14, 2008

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

    By Todd on Oct 15, 2008

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

    By Justin Cutroni on Oct 23, 2008

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

    By Diego on Nov 7, 2008

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

    By Nathan on Jan 21, 2009

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

    By Justin Cutroni on Feb 11, 2009

  1. 4 Trackback(s)

  2. Jun 25, 2008: Analytics Talk » Blog Archive » Google Analytics E-Commerce Tracking Pt. 3: Why EVERYONE Should Use It
  3. Jan 12, 2009: Using Google Analytics Conversion Tracking… « YCA Solar Lights Weblog
  4. Feb 16, 2009: The Missing Google Analytics Manual | FutureNow's GrokDotCom / Marketing Optimization Blog
  5. Apr 2, 2009: Google Analytics: Tutorials, Tools und Tipps

Post a Comment