Reputation: 385
Is this acceptable? Calling the pageview in the header, and then sending an event(s) further down the page?
//head
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
ga('send', 'pageview');
//inside product details/body
ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'category': 'Apparel',
'brand': 'Google',
'variant': 'black'
});
ga('ec:setAction', 'detail');
ga('send', 'event')
Would this be better practice?
//head
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
//inside product details/body
ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'category': 'Apparel',
'brand': 'Google',
'variant': 'black'
});
ga('ec:setAction', 'detail');
//somewhere near footer
ga('send', 'pageview');
Upvotes: 1
Views: 1788
Reputation: 150
Yes, your suggested ga('send', 'pageview') at the bottom is the correct way.
Since you "know" when you render the page that the visitor will see the product detail page you might as well send it with the page view.
Use an event to send enhanced ecommerce tracking that hasn't happened when the page renders, like if the visitor adds the product to their cart. Use a non-interaction event to make it not affect bounce rate (and as suggested above, you should specify a category and an action for your event).
Upvotes: 1
Reputation: 8907
In terms of the syntax for the event push, when you send an event to GA, you have to include the category and action (as specified here https://developers.google.com/analytics/devguides/collection/analyticsjs/events). So you would have in your event push:
ga('send', 'event', 'eventCategory', 'eventAction');
Your eCommerce transaction looks fine.
Not sure about the strategy of sending an event with your pageview though. Usually an event is associated with some action (like a button or link click).
Hope this helps.
Upvotes: 0