16
votes

I'm attempting to migrate our site to Universal Analytics as well as the Enhanced Ecommerce services. After some experimentation using the GA debugger, it appears that you must call ga('send', 'pageview') after you have called your ga('ec:addProduct') and ga('ec:setAction') methods to actually send the data. When looking through the doc (https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce) some examples show that they call ga('send', 'pageview') twice, once at the beginning and a second time after setting the product data, while in other examples, ga('send', 'pageview') is only present at the end.

ga('create', 'UA-XXXXX-Y');
ga('send', 'pageview'); /*FIRST PAGE VIEW CALLED HERE */
ga('require', 'ec', 'ec.js');

ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black'
  'price': '29.20',
  'quantity': 1
});

// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', {
  'id': 'T12345',
  'affiliation': 'Google Store - Online',
  'revenue': '37.39',
  'tax': '2.85',
  'shipping': '5.34',
  'coupon': 'SUMMER2013'    // User added a coupon at checkout.
});

ga('send', 'pageview');     // Send transaction data with initial pageview. /*BUT WE ALREADY CALLED IT AT THE TOP */

Will the above code result in the page view being logged twice?

We also want to track our customers progression through the checkout using ga('ec:setAction', 'checkout', {'step' : step}); and specifiying the step number which we have defined in our analytics account. It appears we need to call send pageview again to send this data as well. I attempted to send all the data in a single page view but it appears you can only set one action (ga('ec.setAction')) per pageview so we can't send both the product transaction data as well as the checkout step data in a single page view. Will calling ga('send', 'pageview') multiple times log multiple page views in analytics or does google detect that your simple sending additional data and doesn't log the extra page views?

I've found that when using normal eCommerce tracking you can use ga('ecommerce:send');, is their an equivalent in enhanced eCommerce tracking?

4
Hello I'm encountering the same issue. Can you give me how did you make it work?rj tubera
Did you all find a solution to this? I'm sending one pageview at the bottom of my page and it will record my addProduct event, but not my purchase action.Trey Copeland

4 Answers

7
votes

Every time you call ga('send', 'pageview'), a new pageview will be sent to GA. If you just want to send more data you can also send an event to avoid the double pageview tracking.

7
votes

It looks like you should send the event as nonInteractive:

ga('send', 'event', 'ecommerce', 'purchase', {'nonInteraction': true});

This is taken and slightly modified from @Blexy here:

Tracking catalog product impressions - Enhanced Ecommerce Google Analytics

2
votes

Google suggests this in their example, however, I have to spread this code out among the page:

ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');

ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black'
});

ga('ec:setAction', 'detail');

ga('send', 'pageview');  

I have replaced the above code with the following:

ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
ga('send', 'pageview');  

ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black'
});

ga('ec:setAction', 'detail');
ga('send', 'event')
0
votes

I have the same problem.
The analytics.js code (including the tracker reference) needs to be loaded on every page before an ec event can be fired. So if you fire the analytics standard pixel on each page and fire some additional events you probably double count the pageview plus your bounce rate is not calculated properly

A solution could be to only fire the "normal" analytics page code on each page except of those you would like to enrich information.

<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-XXXX-Y', 'auto');  // Replace with your property ID.
ga('require', 'ec');

ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black'
});

ga('ec:setAction', 'detail');

ga('send', 'pageview'); 
</script>

Any better ideas?