E-Commerce Tracking with Universal Google Analytics

Ecommerce Tracking with Universal Google analyticsWith the coming upgrade of Google Analytics from Classical to Universal we may have to change the tracking codes on our websites. I have reached out to Google Analytics in many forms (Twitter, G+, and Email) but I haven’t gotten a response. In the Universal Google Analytics Reference articles it is indicated that a change in the tracking code on all websites will be imminent.

With the change from ga.js (Classical Analytics Tracking) to analytics.js (Universal Analytics Tracking) we will see a difference in the way we track things such as ecommerce transactions and event tracking. We are required to implement our tracking codes using jQuery instead of oldschool javascript. If you are not a coder this may be a bit difficult.

First Implementing the Ecommerce Tracking Code

This is what every tracking code needs to start with on every page you are tracking. The important factor is to add this line of code ga(‘require’, ‘ecommerce’, ‘ecommerce.js’); so that every tracking code starts like this:

ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');   // Load the ecommerce plug-in.

The require command must be called after you create your tracker object, but before you use any of the ecommerce-specific functionality.

Adding Products to the Cart

Everytime a visitor adds a product to the cart we need to notify Google Analytics for reporting.
With this information we can see important metrics such as cart abandonment rate and more.
Add this code to every page that you are going to have Add to Cart Buttons on.

<script src="//"></script>
$('#AddToCart').on('click', function() {
ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required
  'name': 'T-Shirt',                // Product name. Required
  'sku': 'DD44',                    // SKU/code
  'category': 'Green Medium',       // Category or variation
  'price': '11.99',                 // Unit price
  'quantity': '1'                   // Quantity

ga('send', 'ecommerce');      // Send item data to Google Analytics.



For pages with a single product and an add to cart button fill in the values in the code for that product. For pages with multiple products and add to cart buttons create a “#AddToCart” object for each product on the page. You will need to use a server-side scripting language such as PHP to dynamically change the values of the quantity upon change of quantity.

To send the data to Analytics just add the action to the add to cart button like this:

 <a href="#" id="AddToCart">Add To Cart Button</a>

Sending the Final Transaction to Analytics

When the visitor completes the transaction we need to see this within Analytics.
Again with this code you will need to have the data such as revenue and id dynamically inserted using a server-side scripting language such as PHP.

Add this code to the checkout page.

<script src="//"></script>

$('#checkout').on('click', function() {
ga('ecommerce:addTransaction', {
  'id': '1234',                     // Transaction ID. Required
  'affiliation': 'Acme Clothing',   // Affiliation or store name
  'revenue': '11.99',               // Grand Total
  'shipping': '5',                  // Shipping
  'tax': '1.29'                     // Tax

ga('send', 'ecommerce');      // Send transaction to Google Analytics.

Once the visitor is ready to complete the transaction we need to send this information to Google Analytics.
We do this by adding this action to the Checkout button.

  <a href="#" id="checkout">Checkout Button</a>

This Concludes Our Tutorial on Ecommerce Tracking in Universal Analytics

We hope this helps you get your ecommerce tracking in order. It is hard to find a good tutorial on ecommerce tracking setup so let me know if you have any questions or comments in the comments area and I will address them right away. Remember, this is for Universal Google Analytics. To make sure which version of Analytics you are using check out the Analytics Reference and your tracking code.

Ryan Davis ()

Ryan is a Senior PPC Manager for PPC Blast.
He has been working in web design/developement for over 16 years and PPC for over 3 years. He is Google Adwords Certified and Bing Ads Certified.

Posted in: Analytics

Leave a Comment (4) ↓
Loading Disqus Comments ...
Loading Facebook Comments ...


  1. Mike November 20, 2013

    Nice article Ryan, I am a little hesitant to make the plunge since I still heavily use Re-marketing. Do you know if at some point this will be available in Universal Analytics?

    • Ryan Davis November 20, 2013

      Hey Mike, thank you for the comment. I get that. That was something I found weird with Google Analytics. No Re-marketing lists!
      I did read that Universal Analytics will be re-integrating all features including Remarketing lists. Just not sure when.
      Thank you again for the comment!

  2. Lashawn November 26, 2013

    Thanks for another fantastic post. Where else may anybody get that kind of information in such a perfect approach of writing? I’ve a presentation subsequent week, and I am at the look for such information.

    • Ryan Davis November 26, 2013

      I appreciate the awesome comment. What kind of info are you looking for? I offer a little bit of PPC info here and PPC Hero offers a great deal of excellent content on PPC marketing. I hope that helps! Stop back by again soon!


Leave a Comment

Help Us Improve The PPC Blast Blog
Follow Us or Leave A Comment Below!