我正在尝试添加以下标记来跟踪页面检出:
<script>
var step1 = step2 = /*step3 =*/ 0;
window.onhashchange = function(e) {
if (e.newURL.indexOf('#shipping') !== false) {
setTimeout(function() {
step_onblur(1);
step_onblur(2);
}, 2000);
}
/*else if (e.newURL.indexOf('#payment') !== false) {
step_onblur(3);
}*/
};
function step_onblur(stepnumber) {
switch (stepnumber) {
case 1:
var element_step = document.querySelectorAll('div#shipping-new-address-form.fieldset.address select, form#co-shipping-form.form.form-shipping-address input');
listenerType = 'blur';
break;
case 2:
var element_step = document.querySelectorAll('div.checkout-shipping-method select, div.checkout-shipping-method input');
listenerType = 'click';
break;
/*case 3:
break;*/
}
console.log(element_step);
for (var i = 0; i < element_step.length; i++) {
element_step[i].addEventListener(listenerType, function(e) {
console.log(listenerType);
if (stepnumber == 1) {
step_onblur(2);
}
if (eval('step' + stepnumber) == 0) {
stepPush(stepnumber);
eval('step' + stepnumber + '=1');
}
});
}
if (typeof dataLayer != null) {
dataLayer.push({
"event": "checkout" + stepnumber,
"ecommerce": {
"checkout": {
"actionField": {
"step": stepnumber,
"action": "checkout"
},
"products": arrkkproducts
}
}
});
}
}
}
</script>
当客户完成添加运输详细信息后,功能step_onblur(stepnumber)
将切换步骤,并转到下一步(选择运输方法)。
当我尝试查看此标签的预览时,它注册了第一步但没有切换该步骤,也没有注册第一步完成了多少个字段。
任何想法如何解决?