控制台返回值,但Google跟踪代码管理器变量未返回 [英] Console returns value but Google Tag Manager variable does not

查看:68
本文介绍了控制台返回值,但Google跟踪代码管理器变量未返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将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跟踪代码管理器变量未返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆