The Complete Guide to Setup eCommerce Tracking for Google Analytics

December 20, 2018

Proper implementation of tracking is one of the most important things when advertising on Google, or any digital advertising platform for that matter. In this blog, we will go a complete guide of how to set up ecommerce tracking for Google Analytics.

eCommerce tracking allows businesses to provide transaction details like revenue and product ids directly to Google Analytics for analysis.

The first step to setting up ecommerce tracking for Google Analytics is to enable the ecommerce feature. To do this you must first:

1. Sign into your Google Analytics account

2. Click on admin (the little gear icon in the lower left)

3. Click ‘Ecommerce Settings’ in the view column

Ecommerce settings


4. Enable ecommerce

Ecommerce Enable


5. Save


You aren’t done just yet. Enabling ecommerce in Google Analytics simply makes sure that analytics is ready to handle this sort of data. You now need to write a few pieces of code on your website that will send the appropriate data directly to Google Analytics.

There are two forms of data for ecommerce tracking you can send using analytics; Transaction data and item data.


Transaction data is the entire transaction that occurs on the site and includes; transaction ID, affiliation, revenue, shipping, and tax.

Item data is the product or products that were in the shopping cart. These include; transaction ID, name, SKU, category, price, and quantity.

If you have not set up basic page tracking yet you must first add Google’s JavaScript code to your website to send this Ecommerce data to Google Analytics. You can use your ‘Thank You’ page to install the following JavaScript and send ecommerce data to Google Analytics. If you utilize Google Tag Manager please skip ahead to the ‘Google Tag Manager Ecommerce Setup’ section.


I. Ecommerce setup without Google Tag Manager:

In order to pass this data back to Google Analytics you must load the ecommerce plug in on your ‘Thank You’ page. Use the following command as part of your Analytics tag  to do so:

ga(‘require’, ‘ecommerce’)

In order dynamically input the transaction and item data and send it back to Google Analytics there will need to be some coordination and communication between your server and the analytics JavaScript.

You need to write out some logic that will change the ecommerce data from your server to a snippet of code readable by analytics.js.

// Function to return the JavaScript representation of a TransactionData object.
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’]}’


Once you’ve done this your ecommerce data will be legible by the anlaytics.js. Next you must add some additional code to the

This final piece of code will send all of the transaction and item data back to Google Analytics.


II. Google Tag Manager Ecommerce Set-Up

After you’ve enabled ecommerce within Google Analytics you need to create a Universal Analytics tag and set the track type to transaction. Once you’ve created and configured all of the required fields in the universal analytics tag you’ll need to add the datalayer() object to the transaction page in order to collect and pass the required variables. Lastly, you’ll need to create a trigger to fre the tag on the transaction page. Here is an example of the data layer code could be implemented in JavaScript.

By adding this code above the Tag Manager container snippet you;ll ensure the data layer is ready before the the Tag Manager fires the Google Analytics tag.

As with all coding and tracking implementation it is important to Q/A your work and ensure tracking is in fact working. Refer to Google’s developer documentation if your configuration isn’t work properly during your testing.