Schedule a 20 minutes consultation

It’s Free. You will get a call from us as per this schedule. Our team will discuss about your requirements and its solution.

Thank you! Your submission has been received!
Invalid email id, please use a valid one
Ayan Sarkar
August 17, 2015

Table of content

Free service is delivered by the search engine giant Google in the form of Analytics to provide free services of monitoring the traffic and conversion rate of users. There are 2 types of allowed tracking for the Magento based websites that are as follows:

  • Page View Tracking
  • Ecommerce Tracking

Steps to set up the Analytics for your website

  • Sign up with http://www.google.com/analytics/sign_up.html . After this your account number will be provided to you. Store this number safely so as to help you with configuring the Magento website.
  • Now start configuring your Analytics for tracking your store. Required path is System-> Configuration-> Sales-> Google API. To expand the Google Analytics section click the “Yes” button. Next add your “Account Number” and click on the “Save Config” button.

Implementation of enhanced Ecommerce tracking

  • How to update the Universal Analytics?

Classic Analytics is unsupported by a website made of enhanced features. For this please upgrade your Analytics settings into its Universal version. Migration steps are as follows:

Let’s see what’s the meaning of this whole process of migration? Unlike what is claimed by Google, the steps are not easy. They claim that your job will be done by clicking on the “Transfer” and replacing it with the codes for the Universal Analytics. There are additional steps.

Here is an example suppose if your implemented tracking codes are not included into the original codes of your Analytics then you have to edit the entire codes to successfully migrate into Universal Analytics. Below is a code example:

2 kinds of Tracking Codes are as follows

i) Ecommerce Tracking for your Google Analytics: There are 3 methods involved-_addTrans(), _addItem() and _TrackTrans().
_addTrans()- This method is created for storing all important information that you need to implement further methods. Syntax: _addTrans(orderID, storeName, total, tax, shipping, city, state, country)

_addItem()- This function is used to add a product name into user transaction or storing the entire information with purchased good. Syntax: _addItem(orderID, Product-SKU, Product-Name, Product-Category, Product-Price, Quantity)

_TrackTrans()- This function is used to send entire Ecommerce data to Google Analytics’ server. Syntax: _gaq.push([“_trackTrans”]);

Steps for setting up your Google Analytics tracking codes

  • Create your Analytics account.
  • Integrate the Google Analytics account with your Ecommerce store.
  • Enable the “Reporting Mode” of your Analytics profile.
  • Set up a funnel for your Checkout process.

Ecommerce tracking for your Universal Analytics: Here 4 main commands are used and they help in to load the Ecommerce plugin. This plugin will further help you to track via the Universal Analytics. Syntax: ga(“require”, “ecommerce”, “ecommerce.js”);

“ecommerce:addTransaction” command- For creating user transaction record and for storing all necessary information, this method should be implemented.

Syntax: ga(“ecommerce:addTransaction”, {
‘id’: ‘1234’, // Transaction ID. Required.
‘affiliation’: ‘custom jeans’, // store name.
‘revenue’: ‘28.8’, // total revenue.
‘shipping’: ‘10.00’, // Shipping.
‘tax’: ‘1.89’ // Tax.
});

‘ecommerce:addItem’ command- This method is required to add a product with users’ transaction record and store entire information related with the product.

Syntax: ga(‘ecommerce:addItem’, {
‘id’: ‘1234’, // Transaction ID. Required. Same as in the transaction data.
‘name’: ‘OKEJeans’, // Product name. Required.
‘sku’: ‘SKJ49’, // Product SKU.
‘category’: ‘Women Jeans’, // Product Category or variation.
‘price’: ‘76.65’, // Product price.
‘quantity’: ‘1’ // Product Quantity.
});

‘ecommerce:send’ command- To send the entire Ecommerce data into the Universal Analytics server, this command is used.

Syntax: ga(‘ecommerce:send’);

Steps for setting up your Universal Analytics tracking codes

  • Creating your account for Universal Analytics is the first step.
  • Next step is to integrate your store with your Universal Analytics account. This enables you to send in data to Analytics.
  • Next you should enable the ‘Reporting Mode’ of your Universal Analytics profile.
  • Then setup the funnel setting of the checkout process.

Creating new properties with your Google Analytics account-

A new property must be created to implement methods of enhance Ecommerce tracking.

Along with this new property, the regular tracking system should be enabled with your Ecommerce store. Data security feature is enabled with your Ecommerce store. In the next step ‘Use enhanced link attribution’ should be enabled.

Now 2 separate tracking processes are operating- one for regular data and the other for enhanced ecommerce data.

Adding new usage data with new property
Creation of 2 separate tracking objects should be initialised rather than copy-pasting the codes. Otherwise its usage would be inflated.

Let’s modify the code as is defined below:
ga(‘create’, ‘UA-12345-1′,’auto’);
ga(‘create’, ‘UA-12345-2′,’auto’,

{‘name’:’newTracker’}); //creation of a new object for tracking and after associating it with new web property give it a new name as New Tracker
ga(‘send’,’pageview’);// sending the data of pageview to the new object for tracker.
ga(‘newTracker.send’,’pageview’);

Process for enabling enhanced Ecommerce plus configuring the steps for checkout

Admin section of the new property should be opened and ‘Ecommerce Settings’ plus ‘Reporting Option’ should be enabled. Next separate names should be given for checkout funnel.

At Conversions->Ecommerce you can view the new reports.

How to measure internal promotion impression via the tracking codes?

For measuring internal promotion impression you should add the ec:addPromo command and promotion details at promoFieldObject. Following codes should be added on proper pages:

<script>
(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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘[ENTER MAIN PROPERTY ID]’, ‘auto’);
ga(‘create’, ‘[ENTER TEST PROPERTY ID]’, ‘auto’,{‘name’: ‘newTracker’}); // New tracker
ga(‘require’, ‘ec’);
ga(‘ec:addPromo’,{

// promoFieldObject stores internal promotion data

‘id’: ‘[Server Variable]’, // Promotion ID – Required ‘ Type: string

‘name’: ‘[Server Variable]’, // Promotion Name – Type: string

‘creative’: ‘[Server Variable]’, // Creative ad used for promotion – Type: string

‘position’: ‘[Server Variable]’ // Position of the creative ad – Type: string

});
ga(‘send’, ‘pageview’);
ga(‘newTracker.send’, ‘pageview’);

</script>
Next you should add data related to actual products in place of variables.

How to measure number of clicks?

It is highly necessary to keep tab upon total number of clicks when going for an internal campaign and ec:addPromo is the required code. Next step is to add the ec:set Action plus setting the action type to ‘promo_click’. The JavaScript event handler onClick() would help you measure the count.
function onPromoClick() {
ga(‘ec:addPromo’, {
// promoFieldObject stores internal promotion data

‘id’: ‘[Server Variable]’, // Promotion ID – Required ‘Type: string

‘name’: ‘[Server Variable]’, // Promotion Name – Type: string

‘creative’: ‘[Server Variable]’, // Creative ad used for promotion – Type: string

‘position’: ‘[Server Variable]’ // Position of the creative ad – Type: string

});

// Send the promo_click action with an event.
ga(‘ec:setAction’, ‘promo_click’);
ga(‘newTracker.send’, ‘event’, ‘Internal Promotions’, ‘click’, ‘[ENTER PROMOTION NAME]’);
}
To implement the function onPromoClick, add this 1 line code-
<a href=’/tops/’ onClick=’onPromoClick();’><img src=’/prod/summersalepromo.jpg’></a>

Now replace the server variables with actual product data.

Want to measure product impressions? Then add tracking code

After adding ec:addImpression function implement product details at impressionFieldObject.
Tracking codes for product impression should be added at product listing.

<script>
(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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘[ENTER MAIN PROPERTY ID]’, ‘auto’);
ga(‘create’, ‘[ENTER TEST PROPERTY ID]’, ‘auto’,{‘name’: ‘newTracker’}); // New tracker
ga(‘require’, ‘ec’);
ga(‘ec:addImpression’,{

// ImpressionFieldObject stores product impression data

‘id’: ‘[Server Variable]’, // Product ID/SKU – Type: string

‘name’: ‘[Server Variable]’, // Product name – Type: string

‘category’: ‘[Server Variable]’,// Product category. Use / as a delimiter to specify up to 5 levels of hierarchy (e.g Men/Shirts/T-Shirts) – Type: string

‘brand’: ‘[Server Variable]’,// Product brand – Type: string

‘variant’: ‘[Server Variable]’, // Variant of the product like color, size etc – Type:string

‘price’: [Server Variable], // Product price – Type: numeric

‘list’: ‘[Server Variable]’, // Product list – Type: string

‘position’: [Server Variable] // Product position in a list – Type: numeric

});

});
ga(‘newTracker.send’, ‘pageview’); // Send product impressions with initial pageview
ga(‘send’, ‘pageview’);
</script>
Next job is your developer’s who should loop the server side script via every product page to send Product Impression data for every product.

Add tracking code to measure product clicks-

By adding ec:addProduct command you can count on number of clicks for your internal promotion campaigns. Now use ec:set action command to enable actions. Next set it to ‘click’. Following function should be added with every enlisted product.

function onProductClick() {
ga(‘ec:addProduct’,{

// productFieldObject stores product click and other details

‘id’: ‘[Server Variable]’, // Product ID/SKU – Type: string

‘name’: ‘[Server Variable]’, // Product name – Type: string

‘category’: ‘[Server Variable]’, // Product category – Type: string

‘brand’: ‘[Server Variable]’, // Product brand – Type: string

‘variant’: ‘[Server Variable]’, // Variant of the product like color, size etc – Type: string

‘position’: [Server Variable] // Product position in a list – Type: numeric

});

ga(‘ec:setAction’, ‘click’, {list: ‘[Server Variable]’});

// Send click with an event, then send user to product page.
ga(‘newTracker.send’, ‘event’, ‘UX’, ‘click’, ‘Results’, {
‘hitCallback’: function() {
document.location = ‘[Server Variable]’;
}
});
}
To enable the function of sending the click data, add the server-side script. Add this code for implementing onProductClick function:
<a href=’/tops/figber/’ onClick=’onProductClick();’><img src=’/prod/figber.jpg’></a>

After addition of tracking code you can measure the detail views of products

Number of views would be measured by adding the ec:addProduct and ec:setAction commands and then setting the action type to ‘detail’.
<script>
(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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘[ENTER MAIN PROPERTY ID]’, ‘auto’);
ga(‘create’, ‘[ENTER TEST PROPERTY ID]’, ‘auto’,{‘name’: ‘newTracker’}); // New tracker
ga(‘require’, ‘ec’);
ga(‘ec:addProduct’,{

// productFieldObject stores product click and other details

‘id’: ‘[Server Variable]’, // Product ID/SKU – Type: string

‘name’: ‘[Server Variable]’, // Product name – Type: string

‘category’: ‘[Server Variable]’, // Product category – Type: string

‘brand’: ‘[Server Variable]’, // Product brand – Type: string

‘variant’: ‘[Server Variable]’, // Variant of the product like color, size etc – Type: string

});

ga(‘ec:setAction’, ‘detail’);

});
ga(‘newTracker.send’, ‘pageview’); // Send product impressions with initial pageview
ga(‘send’, ‘pageview’);
</script>

How to count the products addition or removal numbers with tracking codes?

While purchasing a product, a customer may either buy otherwise remove the product from cart. For this purpose commands ec:addProduct and ec:setAction should be added and the actions should be set to either ‘add’ or ‘remove’. Nest add the following function with the help of onClick() event handler with add/remove options at every product detail page plus the checkout page.

function addRemoveCart(product,x) {
ga(‘ec:addProduct’,{

// productFieldObject stores product click and other details

‘id’: ‘[Server Variable]’, // Product ID/SKU – Type: string

‘name’: ‘[Server Variable]’, // Product name – Type: string

‘category’: ‘[Server Variable]’, // Product category – Type: string

‘brand’: ‘[Server Variable]’, // Product brand – Type: string

‘variant’: ‘[Server Variable]’, // Variant of the product like color, size etc – Type: string

‘price’: [Server Variable], // Product price – Type: numeric

‘quantity’: [Server Variable], // Product quantity – Type: numeric

});

ga(‘ec:setAction’, ‘[Server Variable]’); // send ‘add’ or ‘remove’
ga(‘newTracker.send’, ‘event’, ‘UX’, ‘click’, ‘[Server Variable]’); // Send ‘add to cart’ or ‘remove from cart’ using an event.
}
For adding addRemoveCart function, add this code:
<button onclick=’addRemoveCart(product,’add’);’>Add to Cart</button>

<button onclick=’addRemoveCart(product,’remove’);’>Remove from Cart</button>

How to count checkout steps with the help of tracking codes?

To count individual checkout steps add commands ec:addProduct and ec:setAction. Type of action should be set to ‘checkout’ and the ‘step field’ should be set up to the step number.
Call the following function before the checkout action is initiated by the user:
/*
* Called when the user begins the checkout process.
* @param {Array} cart An array representing the user’s shopping cart.
*/
function checkout(cart) {
for(var i = 0; i < cart.length; i++) {
var product = cart[i];
ga(‘ec:addProduct’, {
‘id’: product.id,
‘name’: product.name,
‘category’: product.category,
‘brand’: product.brand,
‘variant’: product.variant,
‘price’: product.price,
‘quantity’: product.qty
});
}

// In the case of checkout actions, an additional actionFieldObject can
// specify a checkout step and option.
ga(‘ec:setAction’,’checkout’, {
‘step’: 1, // A value of 1 indicates first checkout step.Value of 2 indicates second checkout step
‘option’: ‘Visa’ // Used to specify additional info about a checkout stage, e.g. payment method.
});
Next call the following functions for adding checkout steps when additional information has been added:
function onAdditionalInformation(stepNumber, optionSelected) {
ga(‘ec:setAction’, ‘checkout_option’, {
‘step’: stepNumber,
‘option’: optionSelected
});

ga(‘newTracker.send’, ‘event’, ‘Checkout’, ‘Option’,
{hitCallback: function() {
// Advance to next page.
});

How to count number of transactions via addition of tracking code?

For measuring total number of transactions you should add ec:addProduct command with each product and set ec:setAction command to ‘purchase’.
Next code lines should be added to order confirmation page:
<script>
(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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘[ENTER MAIN PROPERTY ID]’, ‘auto’);
ga(‘create’, ‘[ENTER TEST PROPERTY ID]’, ‘auto’,{‘name’: ‘newTracker’}); // New tracker
ga(‘require’, ‘ec’);
ga(‘ec:addProduct’,{

// productFieldObject stores product click and other details

‘id’: ‘[Server Variable]’, // Product ID/SKU – Type: string

‘name’: ‘[Server Variable]’, // Product name – Type: string

‘category’: ‘[Server Variable]’, // Product category – Type: string

‘brand’: ‘[Server Variable]’, // Product brand – Type: string

‘variant’: ‘[Server Variable]’, // Variant of the product like color, size etc – Type: string

‘price’: [Server Variable], // Product price – Type: numeric

‘quantity’: [Server Variable], // Product quantity – Type: numeric

});

// Transaction level information is provided via actionFieldObject.

ga(‘ec:setAction’, ‘purchase’,{

// actionFieldObject stores action data

‘id’: ‘[Server Variable]’, // Transaction id – Type: string

‘affiliation’: ‘[Server Variable]’, // Store name – Type: string

‘revenue’: ‘[Server Variable]’, // Total Revenue – Type: numeric

‘tax’: ‘[Server Variable]’, // Tax – Type: numeric

‘shipping’: ‘[Server Variable]’, // Shipping – Type: numeric

‘coupon’: ‘[Server Variable]’ // Order/Transaction coupon – Type: string

});

ga(‘newTracker.send’, ‘pageview’); // Send transaction data with initial pageview.
</script>

How to process the test property?

Impact of a full or a partial refunding at your business bottom-line can be either manually or automatically measured. Universal Analytics offers ‘Date Import’ feature and you can measure the impact through this. Automatically API of Management is implemented to measure it. Next step is to upload the refund data.

Now onwards you can put a tab upon the ‘Sales Performance Report’.

How to migrate to enhanced Ecommerce?

After being assured of 100% performance of your tracking codes, following steps should be taken for actual migration action.

i) Enable the Enhanced Ecommerce tracking for main property and then configure the steps of checkout process.
ii) Erase the previous tracking code.
iii) Remove the following code line:
ga(‘create’, ‘[ENTER TEST PROPERTY ID]’, ‘auto’,{‘name’: ‘newTracker’}); // New tracker
iv) Replace the ‘newTracker.send’ command with command for ‘send’. Now Enhanced Ecommerce data would be moved at main web property and not towards the test property.

Final thoughts

For exact implementation of Universal Analytics with your Ecommerce website you can hire Magento developers from a reputed and experienced company. Intelligent business is done after you can measure your performance at every step. This will help you to edge over your competitors.

Ayan Sarkar

Ayan Sarkar is one of the youngest entrepreneurs of India. Possessing the talent of creative designing and development, Ayan is also interested in innovative technologies and believes in compiling them together to build unique digital solutions. He has worked as a consultant for various companies and has proved to be a value-added asset for each of them. With years of experience in web development, product managing and building domains for customers, he currently holds the position of the CTO in Webskitters Technology Solutions Pvt. Ltd.