Вопрос

We are trying to track page views and ecommerce transactions across 3 different GA properties (tracking id's). After following the integration and developers guide exactly as defined and using properly name spaced trackers we are getting inconsistent data. Some transactions are tracked, others not. Seems like some sort of conflict within the methodology but after trying various iterations we have not found resolution.

Code is as follows:

(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-1','auto',{'name': 'location1'});
ga('location1.send','pageview',{'dimension1': 'location-1-name'});
ga('location1.require','ecommerce','ecommerce.js'); 

ga('create','UA-XXXX-2','auto',{'name': 'location2'});  
ga('location2.send','pageview',{'dimension1': 'location-2-name'});
ga('location2.require','ecommerce','ecommerce.js'); 

ga('create', 'UA-XXXX-3','auto',{'name': 'location3'});
ga('location3.send','pageview');
ga('location3.require','ecommerce','ecommerce.js'); 

var transaction = {
'id': '1234',
'affiliation': 'store', 
'revenue': '10.50',
'shipping': '5.00',
'tax': '0.00'
};

ga('location1.ecommerce:addTransaction', transaction);

ga('location1.ecommerce:addItem', {
'id': '<?php echo $order->order_no; ?>',
'name': '<?php echo $item->name; ?>',
'sku': '<?php echo $item->item_no; ?>',
'category': '<?php echo $item->item_type; ?>',
'price': '<?php echo number_format($item->item_sale_price,2); ?>',
'quantity': '<?php echo $item->qty; ?>'
});
<?php   }   ?>

ga('location2.ecommerce:addTransaction', transaction);

<?php   foreach ($items as &$item) {    ?>
ga('location2.ecommerce:addItem', {
'id': '<?php echo $order->order_no; ?>',
'name': '<?php echo $item->name; ?>',
'sku': '<?php echo $item->item_no; ?>',
'category': '<?php echo $item->item_type; ?>',
'price': '<?php echo number_format($item->item_sale_price,2); ?>',
'quantity': '<?php echo $item->qty; ?>'
});
<?php   }   ?>  

ga('location3.ecommerce:addTransaction', transaction);

<?php       foreach ($items as &$item) {    ?>
ga('location3.ecommerce:addItem', {
'id': '<?php echo $order->order_no; ?>',
'name': '<?php echo $item->name; ?>',
'sku': '<?php echo $item->item_no; ?>',
'category': '<?php echo $item->item_type; ?>',
'price': '<?php echo number_format($item->item_sale_price,2); ?>',
'quantity': '<?php echo $item->qty; ?>'
});
<?php       }   ?>

ga('location1.ecommerce:send');
ga('location2.ecommerce:send');
ga('location3.ecommerce:send');
Это было полезно?

Решение

I thought I would go ahead and answer this as we did determine why our transactions were not being tracked.

The devious apostrophe inside the javascript block.

On some transactions the item name getting passed into the addItem object had a single apostrophe in the text string, therefore the entire script was error-ing. So in the end, when in doubt addslashes() to any string that could possibly have an apostrophe. Seems obvious but easy to forget.

Also came across a Chrome addon (Google Analytics Debugger) that helps you to see exactly what is getting passed to GA. Pretty helpful when managing a complicated multiple tracker setup like this.

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en

Hope that helps someone else not make the same mistake.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top