JavaScript

Tracking your Product Sales, Views and Searches with Google Enhanced E-commerce Analytics

Enhanced E-commerce helps improving tracking of an e-commerce website. It gives Statistics in variable measurements. It is not be used alongside analytics plugin, as this EE  Plugin also tracks pages.

Admin Section of Google Analytics Property will have three sub-sections: Account, Property View.

To enable Enhanced E-commerce you need to navigate to View > Ecommerce Settings > Turn Status & Enable Related Products to "ON" and click Submit.

Your normal Analytics Snippet will look like

<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', 'UA-xxxxxxxx-1', 'auto');
  ga('send', 'pageview');
</script>

Here  ga('create', 'UA-xxxxxxxx-1', 'auto') will create a page object and  ga('send', 'pageview') will send the object to google tracker. So all the Ecommerce tracking will happen in between these Lines.

Add

ga('require', 'ec');

to load e-commerce plugin, this should be after the creation of page object.

ga('create', 'UA-xxxxxxxx-1', 'auto')
ga('require', 'ec');
ga('ec:addProduct', {               // Provide product details in a productFieldObject.
  'id': 'E60152',                   // Product ID (string).
  'name': 'Sandisk Pen Drive', // Product name (string).
  'category': 'electronics',            // Product category (string).
  'brand': 'Sandisk',                // Product brand (string).
  'variant': 'On-The-Go Pendrive',               // Product variant (string).
  'custom-dimension': 'custom-answer'
});
ga('ec:setAction', 'click', {       // click action.
  'list': 'Search Results'          // Product list (string).
});
ga('send', 'pageview')
  1. Impression data - Data of product that is already viewed
  2. product data -  Data of a product under view.
  3. promotion data -Data of Promotion object
  4. action data. - Type of Action

In our case scenario to Track Products Sales and views, we will use product data + Action data

Similarly,

ga('ec:addProduct', {               // Provide product details in a productFieldObject.
  'id': 'E60152',                   // Product ID (string).
  'name': 'Sandisk Pen Drive', // Product name (string).
  'category': 'electronics',            // Product category (string).
  'brand': 'Sandisk',                // Product brand (string).
  'variant': 'On-The-Go Pendrive',               // Product variant (string).
  'custom-dimension': 'custom-answer'
});

ga('ec:setAction', 'detail');         ----------> Action Data
ga('ec:addProduct', {               // Provide product details in a productFieldObject.
  'id': 'E60152',                   // Product ID (string).
  'name': 'Sandisk Pen Drive', // Product name (string).
  'category': 'electronics',            // Product category (string).
  'brand': 'Sandisk',                // Product brand (string).
  'variant': 'On-The-Go Pendrive',               // Product variant (string).
  'custom-dimension': 'custom-answer'
});

ga('ec:addProduct', {
  'id': 'H25482',
  'name': 'Skull Candy Go Pro Headset',
  'category': 'Accessories',
  'brand': 'Skull candy', 
  'variant': 'blue',               
});

ga('set', '&cu', 'EUR');

ga('ec:setAction', 'purchase', {
  'id': '1054412477',                         
  'revenue': '37.39',                     
});

You can view this data in Reporting > Conversions > Ecommerce.

In case if you're facing any issues, you can use GA Debug, an official chrome plugin offered by Google to view data being sent.

This can only be possible if search queries are GET queries, where we use special terms like "q=" or "/q//" .. etc.,

Navigate to View Section of your account and click on "View Settings", Under "Site Search Settings" , change "Site search Tracking" to on and query parameter as the keyword after which search keyword follows, like in both the above cases query parameters is: "q".

Now you can see all the queries being made in Google Analytics under Reporting > Behaviour > Site Search.

Share this Blog post