我正在尝试使用Google Analytics中的analytics.js
和ecommerce.js
跟踪基于PHP的自定义捐赠表单数据
这是我的输出
` (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-xxxxxxxx-x', 'auto'); ga('send', 'pageview'); ga('require', 'displayfeatures'); ga('require', 'ecommerce', 'ecommerce.js'); function trackEcommerce() { this._addTrans = addTrans; this._addItem = addItems; this._trackTrans = trackTrans; } function addTrans(orderID,store,total,tax,shipping,city,state,country) { ga('ecommerce:addTransaction', { '120573112734': orderID, 'Donation': store, '10.00': total, '': tax, '': shipping, 'test',: city, 'test': state, 'test': country }); } function addItems(orderID,sku,product,variation,price,qty) { ga('ecommerce:addItem', { '120573112734': orderID, 'Donate': sku, 'Donation': product, 'none': variation, '1.00': price, '1': qty }); } function trackTrans() { ga('ecommerce:send'); } var pageTracker = new trackEcommerce(); `
我不确定为什么Google Analytics电子商务部分没有捕获这些数据,虽然我可以在Google Analytics中的“感谢您”页面上看到统计信息
请帮忙如果我没有正确地做到这一点。 再次感谢。
答案 0 :(得分:1)
您的对象将值作为名称而不是实际的属性名称。
(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-xxxxxxxx-x', 'auto');
ga('send', 'pageview');
ga('require', 'displayfeatures');
ga('require', 'ecommerce', 'ecommerce.js');
// Note the different names on the object properties?
ga('ecommerce:addTransaction', {
'orderID': '120573112734',
'store': 'Donation',
'total': '10.00',
'tax': '',
'shipping': '',
'city': 'test',
'state': 'test',
'country': 'test'
});
ga('ecommerce:addItem', {
'orderID': '120573112734',
'sku': 'Donate',
'product': 'Donation',
'variation': 'none',
'price': '1.00',
'qty': '1'
});
ga('ecommerce:send');