When and how often do you call ga('send', 'pageview') when using Enhanced Ecommerce with Google Analytics?

怎甘沉沦 提交于 2019-12-03 10:19:46

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.

Mike T

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

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')

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!