Console returns value but Google Tag Manager variable does not

眉间皱痕 提交于 2019-12-25 17:57:08

问题


When I put dataLayer[1].ecommerce.checkout.products[0].metric2 in the console, it return the correct value.

However, when I try to extract the value from a Custom JavaScript variable ('Test') in Google Tag Manager, it returns undefined when Google Tag Manager is in preview mode.

The JavaScript code:

function(){
var basketSize = dataLayer[1].ecommerce.checkout.products[0].metric2;
return basketSize;
}

回答1:


In case your questions hasn't been answered yet: The thing is you yon't want to reference the dataLayer array inside a dataLayer variable in GTM. This does not make sense, because you already are in the dataLayer "namespace". If you reference the field by simply writing ecommerce./*...*/.metric2 and leaving out the dataLayer[1] part, it will work.



来源:https://stackoverflow.com/questions/30502800/console-returns-value-but-google-tag-manager-variable-does-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!