Knowledgebase: General
Implementing Google Analytics Ecommerce Tracking
Posted by on 11 April 2014 04:19 PM

I recently had to implement Google Universal Analytics Ecommerce tracking and this is to itemise the pitfalls of that experience.

Firstly, you need to declare the Google Javascript library: 

<script type="text/javascript">

    (function (i, s, o, g, r, a, m) {      i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {        (i[r].q = i[r].q || []).push(arguments)      }, i[r].l = 1 * new Date(); a = s.createElement(o),    m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)    })(window, document, 'script', '//', 'ga');


Then, create the tracker object, specifying the correct UA-xxxx account number.  There are a number of forms of this statement, supplying the customer domain name but I couldn't get that work but this form worked for me:

 ga('create', 'UA-45583365-1', { 'cookieDomain': 'none' }); 


Then, load the ecommerce plugin:

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

In my case, I created a function to write out the transaction and item detail so that I could log what was being written for debugging purposes but basically you need to do add a Transaction:

ga('ecommerce:addTransaction', {
id: '98765', // Transaction ID - this is normally generated by your system.
affiliation: 'Hart Publishing', // Affiliation or store name
revenue: '89.00', // Grand Total
shipping: '0' , // Shipping cost
tax: '5.99' }); // Tax.

Then a number of these, one for each item in the transaction:
ga('ecommerce:addItem', {
id: '98765', // Transaction ID.
sku: 'LTAFD', // SKU/code.
name: 'One Day Adult Lift Ticket', // Product name.
category: 'Lift Tickets', // Category or variation.
price: '89.00', // Unit price.
quantity: '1'}); // Quantity.


Things that caused me problems:

I tried to add extra keywords into the transaction, city, country which were not recognised.

I had the Adblock Plus extension installed in my browser which was causing the ecommerce plugin to not be loaded.

I installed the GA debugger plugin to work out what was going on.

(1 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
Full Name:
Help Desk Software by Kayako Fusion