Google Analytics Enhanced Ecommerce

Analytics & Tracking|Basic SEO - Last updated April 23, 2018

If you have a Google Analytics account you can turn on enhanced ecommerce to track detailed ecommerce activity on your website such as cart abandonment.

Google Analytics enhanced ecommerce step naming

 

Below are instructions on how you can add the enhanced ecommerce tracking to your ShopSite website.

Add a GA Enhanced Ecommerce Include File

Start by copying the code below, and paste it into an include file called "GA-EnhancedEcommerce.sst" in your ShopSite store. Replace the "UA-XXXXXXX-X" with your Google Analytics UA- accont number and "YourDomain.com" with your website.

[-- IF VAR.Type "more" --]<script>var prnme = '[-- PRODUCT.Name REMOVE_HTML --]';</script>
[-- ELSE_IF VAR.Type "cart" --]
<script>
var products = new Array();var product = '';
for(n=0; n<ss_sku.length; n++){
        product = {'id': ss_sku[n],'name': ss_name[n],'price': ss_price[n],'quantity': ss_quantity[n]};
        products.push(product);
}</script>
[-- END_IF --]
<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');
function __utmLinkPost(a){return true;}function __utmLinker(a){return a;}
ga('create', 'UA-XXXXXXX-X');
[-- IF VAR.Type "more" --]
ga('require','ec');
ga('ec:addProduct', {'id': '[-- PRODUCT.SKU --]','name': prnme[-- IF PRODUCT.Brand --],'brand': '[-- PRODUCT.Brand --]'[-- END_IF --]});
[-- ELSE_IF VAR.Type "cart" --]
ga('require','ec');
[-- IF VAR.SubType "cart" --]ga('ec:addProduct', products);ga('ec:setAction','checkout', {'step': 1});
[-- ELSE_IF VAR.SubType "checkout" --]ga('ec:addProduct', products);ga('ec:setAction', 'checkout', {'step': 2});
[-- ELSE_IF VAR.SubType "confirmation" --]ga('ec:addProduct', products);ga('ec:setAction', 'checkout', {'step': 3});
[-- ELSE_IF VAR.SubType "thankyou" --]ga('ec:addProduct', products);ga('ec:setAction', 'checkout', {'step': 4});ga('ec:setAction', 'purchase', {
  'id': ss_ordernum,
  'affiliation': 'YourDomain.com',
  'revenue': ss_ordertotal,
  'tax': ss_taxtotal,
  'shipping': ss_shiptotal
});
[-- END_IF --]
[-- END_IF --]
ga('send', 'pageview');
</script>

Link Include File In All Template Types

In each of your template types, page, product, search and cart (you can also add this into the wishlist, customer registration and gift certificate pages if you want to track those) add the following code, as well as the corresponding [-- VAR.Type --] tag.

Page Template

Add [-- VAR.Type "page" --] just after the [-- DEFINE PAGE --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag.


Product Template

Add [-- VAR.Type "more" --] just after the [-- DEFINE MORE_INFO --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag.


Search Template

Add [-- VAR.Type "search" --] just after the [-- DEFINE PAGE --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag.


Cart Template

Add [-- VAR.Type "cart" --][-- VAR.SubType "cart" --] just after the [-- DEFINE SHOPPING_CART --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag in that same section.

Add [-- VAR.Type "cart" --][-- VAR.SubType "checkout" --] just after the [-- DEFINE SHIPPING --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag in that same section.

Add [-- VAR.Type "cart" --] just after the [-- DEFINE Confirmation --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag in that same section.

Add [-- VAR.Type "cart" --][-- VAR.SubType "thankyou" --] just after the [-- DEFINE ThankYou --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag in that same section.


Other Templates

Add [-- VAR.Type "" --] just after the [-- DEFINE XXX --] tag.

Add [-- INCLUDE GA-EnhancedEcommerce.sst PROCESS --] just before the </head> tag.



Publish Your Website and Start Tracking

With this tracking option you can turn off the default ShopSite Google Analytics tracking option under Merchandising > Google > Analytics.

Go to Utilities > Publish > Regenerate, to recreate all store pages using the updated template files. You should now start receiving tracking information in your Google Analytics account.