Analytics
2.1K members online now
2.1K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

GA Enhanced Ecommerce eventCallback Required

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Google developer documentation for implementing GA Enhanced Analytics clearly shows eventCallback in specific js code samples. For example, "Measuring Product Clicks" (see code sample copy below). Is it a requirement to use an eventCallback? My understanding is it is required to prevent a race condition. 

For example, if we simply fire dataLayer.push on an anchor tag click then it's not guaranteed that dataLayer.push will run successfully (because page execution may have stopped and the new page loaded). Example jQuery snippet:

$('a.product').click(function() {
   doDataLayerPush();
});

 

<script>
/**
 * Call this function when a user clicks on a product link. This function uses the event
 * callback datalayer variable to handle navigation after the ecommerce data has been sent
 * to Google Analytics.
 * @param {Object} productObj An object representing a product.
 */

function(productObj) {
  dataLayer
.push({
   
'event': 'productClick',
   
'ecommerce': {
     
'click': {
       
'actionField': {'list': 'Search Results'},      // Optional list property.
       
'products': [{
         
'name': productObj.name,                      // Name or ID is required.
         
'id': productObj.id,
         
'price': productObj.price,
         
'brand': productObj.brand,
         
'category': productObj.cat,
         
'variant': productObj.variant,
         
'position': productObj.position
         
}]
       
}
     
},
     
'eventCallback': function() {
       document
.location = productObj.url
     
}
 
});
}
</script>

 

https://developers.google.com/tag-manager/enhanced-ecommerce 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Matthew V
March 2016

Re: GA Enhanced Ecommerce eventCallback Required

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭
We tested both scenarios i.e with and without the eventCallback function. Using the eventCallback is necessary in our environment for correct tracking results.

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Matthew V
March 2016

Re: GA Enhanced Ecommerce eventCallback Required

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭
We tested both scenarios i.e with and without the eventCallback function. Using the eventCallback is necessary in our environment for correct tracking results.