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

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.

    Comments

    1. says

      We are seeing duplicate orders, and also missing orders. I have asked our vendor to move the GA tracking code higher up on the page, so that it will load before the customer moves on to another page. But they are resisting, saying Google instructs that the code be placed before the closing tag – they also refuse to implement the asynch code. It does say that here: http://support.google.com/googleanalytics/bin/static.py?hl=en&selected=a9_a9h1_a9h1t2&page=troubleshooter.cs&ctx=gatsc_a9_a9h1_a9h1t2_55574&problem=gatsc

      But I was hoping there was newer instructions out there, something official from Google, that would back up my request to move the code up.

      Any other recommendations to fix our missing or duplicate orders would be greatly appreciated. Thanks!

      • says

        @Jodi: If you’re missing more than 10% of the orders then there is definitely a code problem. Depending on the size and weight of the page moving the code may not help. But I think that’s a good first step. You can try sending them to this article about placing the async code in the head.

        As for the duplicate orders, this is almost always a problem with outputting the ecommerce tracking code multiple times on the receipt page. Which is an issue that the vendor needs to clean up. The other thing to check is all the fringe cases when a person can view their order summary. Make sure the ecommerce code is not embedded in any of those pages.

        Good luck.

    2. maximus says

      Hello,

      Could you please clarify following for me.

      We have e-commerce site that sells subsriptions.

      To get subscription customers go through the funnel:
      1. Register
      2. Select product
      3. Basket
      4. Confirm basket
      5. Pay
      6. Thank you page

      On stage 5 (pay) we redirect customer to payment-processing-site (billing company). After successful payment payment-processing-site invites customers to return to our site on our thank you page. But most of the customers don’t click on link. They go directly to our site and miss the thank you page.

      Approximately 50% of customers fails with the payment.
      We also have 4 different payment-processing-companies with 4 different independent sites.

      How can we implement GA e-commerce in our case?

      Thank you.

      • says

        @Maximus: Implementing ecommerce depend on the third-party processing site. If they will let you add Google Analytics to your pages on their site, then you can track transactions. However, you will also need to implement cross-domain tracking to correctly attribute transactions to marketing activities. But, if they do not let you add the code, then you don’t have many options.

    Trackbacks

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>