[英]Updating Big Commerce to the new analytics.js
我在一个网站上工作,并将跟踪代码更新为新的analytics.js,我转移了他们的网站,除转换外,其他所有功能均正常。 这是一个大型商务网站,所以我无法触摸服务器端脚本,但这是他们生成的
<script type="text/javascript">
$(document).ready(function() {
if(typeof(pageTracker) != 'undefined') {
pageTracker._addTrans(
'358',
'Backyard Toy Company ',
'0.01',
'0.00',
'0.00',
'Lakewood',
'New Jersey',
'United States'
);
pageTracker._addItem(
'358',
'1336',
'test',
'',
'0.01',
'1'
);
pageTracker._trackTrans();
}
});
</script>
我将客户端代码更新为此
ga('require', 'ecommerce', 'ecommerce.js'); // Load the ecommerce plug-in.
// START CUSTOM CODE
function old2new() {
// define object that can route old methods to new methods
this._addTrans = addTrans;
this._addItem = addItem;
this._trackTrans = trackTrans;
}
function addTrans(orderID,store,total,tax,shipping,city,state,country) {
// remap _addTrans
ga('ecommerce:addTransaction', {
'id': orderID,
'affiliation': store,
'revenue': total,
'tax': tax,
'shipping': shipping,
});
}
function addItem(orderID,sku,product,variation,price,qty) {
// remap _addItem
ga('ecommerce:addItem', {
'id': orderID,
'sku': sku,
'name': product,
'category': variation,
'price': price,
'quantity': qty
});
}
function trackTrans() {
ga('send', 'ecommerce');
}
// instantiate converter using name of old Google tracking object
// bigcommerce code will use this and be none the wiser
var pageTracker = new old2new();
// END CUSTOM CODE
对不起,我是新手,但到处都看不出为什么它不起作用。
我认为send方法应该是这样的:
ga('ecommerce:send');
如果这不起作用,则可以执行以下操作,查看是否找到其他错误的地方:
您是否可以在所有三个功能中放置警报,并确保已正确调用它?
另外,代码中可能存在一个错误,该错误可能会受到覆盖this
影响。 您可以重写以下方法,看看是否可行:
function addTrans(orderID,store,total,tax,shipping,city,state,country) {
// alert("in addTrans");
ga.call(window, 'ecommerce:addTransaction', {
'id': orderID,
'affiliation': store,
'revenue': total,
'tax': tax,
'shipping': shipping,
});
}
function addItem(orderID,sku,product,variation,price,qty) {
// alert("in addTrans");
ga.call(window, 'ecommerce:addItem', {
'id': orderID,
'sku': sku,
'name': product,
'category': variation,
'price': price,
'quantity': qty
});
}
function trackTrans() {
// alert("in Trans");
ga.call(window, 'ecommerce:send');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.