我想在购物车中添加或删除某些内容时触发一些跟踪代码。虽然这些工作可以独立完成但是当一个项目被移除和添加时,我遇到了问题。此代码位于文档就绪函数内,但仅在加载页面时执行最后定义的函数。
我尝试制作匿名函数,延期,自行执行等等。没有运气..任何人都有建议吗?
var addTag = "${flash.getAttribute('triggerAddAbandonCartTag')}",
removeTag = "${flash.getAttribute('triggerAbandonCartTag')}";
if(removeTag === "true"){
var removeSku = "${flash.getAttribute('abandonCartRemoveItemSku')}",
removePrice = "${flash.getAttribute('abandonCartRemoveItemPrice')}",
removeAction = "${flash.getAttribute('removeActionTag')}";
setTimeout(function() {
bkClient.postUserData(doTag(removeSku, removePrice, removeAction));
}, 2000);
}
if (addTag === "true"){
var addSku = "${flash.getAttribute('abandonCartAddItemSku')}",
addPrice = "${flash.getAttribute('abandonCartAddItemPrice')}",
addAction = "${flash.getAttribute('addActionTag')}";
setTimeout(function() {
bkClient.postUserData(doTag(addSku, addPrice, addAction));
}, 2000);
}
function doTag(sku, price, action){
var dt = new Date().getTime(),
data = {
"AID": "${dswConstants.rapidRetargeterSiteId}",
"Etype": "CART",
"Action": action,
"Stage": "AddtoBag",
"PID": sku,
"Pprice": price,
"TagTriggeredDt": dt
}
return data;
}