问题描述
当我将dataLayer[1].ecommerce.checkout.products[0].metric2
放入控制台时,它将返回正确的值.
When I put dataLayer[1].ecommerce.checkout.products[0].metric2
in the console, it return the correct value.
但是,当我尝试从Google跟踪代码管理器中的自定义JavaScript变量(测试")中提取值时,当Google跟踪代码管理器处于预览模式时,它将返回undefined
.
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.
JavaScript代码:
The JavaScript code:
function(){
var basketSize = dataLayer[1].ecommerce.checkout.products[0].metric2;
return basketSize;
}
推荐答案
如果尚未回答您的问题:问题是您不想引用GTM中dataLayer变量内的dataLayer数组.这没有任何意义,因为您已经在dataLayer
命名空间"中.如果仅通过编写ecommerce./*...*/.metric2
并省略dataLayer[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.
这篇关于控制台返回值,但Google跟踪代码管理器变量未返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!