Skip to Content

Google Analytics eCommerce Tracking

Google Analytics eCommerce Tracking

The default setup of Google Analytics provides lots of insightful data; however, business owners need to know more about their websites. In particular, they want to see data directly related to their bottom line. This is data that the default data in reports can't provide. Webmasters can enable eCommerce tracking to get in-depth data about monetary transactions happening on their website.

What is eCommerce Tracking?

This tracking configuration for Analytics is a combination of profile settings and code deployed on a website in order to track eCommerce transactions. Normally, when a visitor comes to your site, a pageview is recorded by the Analytics tracking code. This data is then sent to Google to be processed. With eCommerce tracking, instead of the pageview data being processed, eCommerce data is sent to Analytics. Google gets this data by individual website owners using a collection of tracking methods installed manually on elements of a website.

ECommerce tracking is used for (you guessed it) keeping track of transactions on a website. Important data related to transactions can be captured and reported by Analytics. Things like transaction numbers, product numbers, product descriptions, shipping information, purchase price, tax information, store name and affiliate ID are all examples of data that can be captured. This tracking configuration is also instrumental for measuring remarketing success.

Using data from eCommerce tracking, you can make correlations among the elements of your site and visitor behavior. For instance, you can determine if your price point is appropriate or if you are charging too much or too little for shipping. You may be able to infer if your checkout process is too long or if the product pages on your site are too difficult to use. Of course, these are just examples, and you must make your own assumptions based on the products or services that you sell and your own website configuration.

Enabling eCommerce Tracking

ECommerce tracking is not enabled by default, so you must turn it on in the profile of your choice. Follow the steps below to enable eCommerce tracking.

  1. Log in to your Analytics account
  2. Click on the "admin" tab in the top right corner of the screen
  3. Choose the profile that you wish to enable eCommerce tracking on
  4. Click on "profile settings"
  5. For the section that says "eCommerce site?" select yes
  6. Click "apply settings"

You now have eCommerce tracking enabled, but there is some more in-depth work ahead. You also have to install additional tracking code on your site. For these steps, you must have access to the source code of your website. If your website is administered by someone else, you can provide the code to them and instruct them where to apply it.

Adding eCommerce Tracking Code to Your Website


Note:  Make sure to inspect which version of the Anlaytics tracking code you are using as methods for installing eCommerce code will vary depending on what you are using.


eCommerce Tracking code (ga.js)


In most cases, you will configure your code on the final page of an eCommerce transaction to send data to Analytics. Here is a complete example of how eCommerce tracking might look on your HTML "thank you" page. Note that the code example below is the asynchronous code, and is installed in the head section of the page.




<title>Your eCommerce Thank You Page</title>

<script type="text/javascript">


var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-XXXXX-X']);


_gaq.push(['_addTrans',                  //This is your tracking object.  There are many different kinds

'3456',           // transaction ID – required (This is a required element of your tracking code)

'Your Business'// affiliation or store name

'13.99',          // total – required (So is this)

'1.29',           // tax (Note that everything after the preceding line is not required; however, the more information you can provide, the better it is for your overall tracking efforts.)

'5',              // shipping

'a city',       // city

'a state',     // state or province

'USA'             // country



// add item might be called for every item in the shopping cart

// where your eCommerce engine loops through each item in the cart and

// prints out _addItem for each


'1234',           // transaction ID – required

'DD44',           // SKU/code – required

'your item',        // product name

'description of item',   // category or variation

'price of item',          // unit price – required

'some quantity'               // quantity – required


_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers


(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);







This is where the content of your page will go. Note that all the tracking code goes in the head section of your web page.




Note that the first function _addTrans() initializes or starts the transaction. The second function _addItem() associates an item with the transaction by way of the ID number. The last function _trackTrans() sends the information to the Analytics servers to be processed. These functions must be placed in this order to work. For example, you cannot send information to Analytics before it is stored by _addTrans().

Another notable element of the code is the presence of _trackPageview(). Earlier, we talked about how eCommerce tracking sends transaction data and not pageview data to Analytics servers. While this is true, it is a best practice to include the _trackPageview() function so that you can track your eCommerce pages as you would any other page on your website. Should you exclude this from your page, you would not be able to associate transaction data with other reports in Analytics.

This is a basic example similar to the one provided by Google in its eCommerce tracking tutorial. There could be many different ways you set up eCommerce tracking depending on your particular configuration.

ECommerce Tracking (analytics.js)

For analytics.js, you must load the eCommerce plugin (which speeds everything up by not loading the entire analytics.js library). You do this as follows:


Installing the analytics.js version is a bit trickier, and requires a little bit of PHP knowledge. A common snippet might look something like this:



// Function to return the JavaScript representation of a TransactionData object.  This is so Analytics can interpret the data.

function getTransactionJs(&$trans) {

return <<<HTML

ga('ecommerce:addTransaction', {

'id': '{$trans['id']}',

'affiliation': '{$trans['affiliation']}',

'revenue': '{$trans['revenue']}',

'shipping': '{$trans['shipping']}',

'tax': '{$trans['tax']}'





// Function to return the JavaScript representation of an ItemData object.

function getItemJs(&$transId, &$item) {

return <<<HTML

ga('ecommerce:addItem', {

'id': '$transId',

'name': '{$item['name']}',

'sku': '{$item['sku']}',

'category': '{$item['category']}',

'price': '{$item['price']}',

'quantity': '{$item['quantity']}'






Then, in a script tag, output the data for the transaction:


<!– Begin HTML –>


ga('require', 'ecommerce', 'ecommerce.js');


echo getTransactionJs($trans);

foreach ($items as &$item)


echo getItemJs($trans['id'], $item);






Notice how the syntax is different. In the first example, functions were written as _addTrans() and _trackTrans(). In analytics.js, they are called with ga().


Viewing eCommerce Data in Analytics Reports

To look at the data you have collected, log in to Analytics and go to the profile where you have eCommerce tracking enabled. Under "conversions" go to "eCommerce." There, you can see an overview report, product and sales performance, transaction data and time to purchase data. You can do all the same things to these reports as others in Analytics, such as exporting or filtering them.

ECommerce tracking is a great way to get more detailed data for transactions happening on your website. The default setup for Analytics does not provide this information, and with a little copying and pasting of code into your website, you can unlock a whole world of information about your business. Using that data, you can improve your sale processes, product pages and your overall online business activity.

Do you use eCommerce tracking?  How do you use it to make your online business better? Let us know what you think in the comments section below.