Console returns value but Google Tag Manager varia

2019-09-19 23:58发布

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条回答
够拽才男人
2楼-- · 2019-09-20 00:23

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.

查看更多
登录 后发表回答