因此,我已经为新的 Google Universal Analytics 获得了正确的电子商务跟踪代码,但我对变量的填充方式感到困惑?如何在此脚本中获取正确的商品、价格、类别或商品数量(对于 addItem)?我一直在网上寻找,我不认为我在这里看到了完整的图片。
<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-44464798-1', 'safeway.com');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '200028184', // Transaction ID. Required.
'affiliation': 'Safeway', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5.00', // Shipping.
'tax': '1.00' // Tax.
});
ga('ecommerce:addItem', {
'id': '200028184', // Transaction ID. Required.
'name': 'Apples', // Product name. Required.
'sku': 'CVC2US', // SKU/code.
'category': '', // Category - you can put some category if we have such
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});
// If there are additional items they should be added the same way. The sum of all Items prices should match with the "revenue" data from above.
ga('ecommerce:send'); //
</script>