通过 GTM for Magento 集成增强型电子商务的 JS 代码错误

Error in JS-code for integrating enhanced e-commerce through GTM for Magento

我目前正致力于通过 Google 标签管理器将 Google Analytics Enhanced Ecommerce 集成到 Magento 网上商店。

我正在使用 Panalysis 的扩展和指南:https://www.panalysis.com/resources/tag-manager-plus-user-manual/part-2c-set-gtm-tags

目前,我遇到了以下代码的问题:

<script>
 (function(){
 function sendOneStepCheckout(obj){
 dataLayer.push({
 event: 'onestepcheckout',
 ecommerce: obj
 });
 }

 function hasClass( elem, clas ) {
 try {
 return (" " + elem.className + " " ).indexOf( " "+clas+" " ) > -1;
 }catch(e){return false}
 }

 function checkActiveStep(){
 var step2=document.getElementById('opc-login');
 if (hasClass(step2, 'active')){ return '2' }
 var step3=document.getElementById('opc-billing');
 if (hasClass(step3, 'active')){ return '3' }
 var step4=document.getElementById('opc-shipping');
 if (hasClass(step4, 'active')){ return '4' }
 var step5=document.getElementById('opc-shipping_method');
 if (hasClass(step5, 'active')){ return '5' }
 var step6=document.getElementById('opc-payment');
 if (hasClass(step6, 'active')){ return '6' }
 var step7=document.getElementById('opc-review');
 if (hasClass(step7, 'active')){ return '7' }
 }

 var currentStep = '2';

 try {
 var ec = {{DL - ecommerce}};
 var cos = ec.checkout.actionField.step;
 if (cos == '1') {
 ec.checkout.actionField.step = '2';
 sendOneStepCheckout(ec);
 }
 if (cos == '2') {
 sendOneStepCheckout(ec);
 }
 function timeout() {
 setTimeout(function () {
 var activeStep = checkActiveStep();
 if (activeStep != currentStep){
 var ec = {{DL - ecommerce}};
 ec.checkout.actionField.step = activeStep;
 sendOneStepCheckout(ec);
 currentStep = activeStep;
 }
 timeout();
 }, 1000);
 }

 timeout();
 } catch(e){console.log(e.message)}
 })();
</script>

Google 跟踪代码管理器报告第 43 行第 2 个标志存在错误:

"this language feature is only supported for ECMASCRIPT6 mode or better: block-scoped function declaration. Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT or higher to enable ES6 features."

我尝试搜索错误消息但没有成功。

谁能告诉我如何解决这个问题?我运行头靠在墙上..

此致, 克里斯蒂安.

尝试删除 <script> 标签,有时 Google 标签管理器会在代码不是严格的 JS 语法时出现问题。