【问题标题】:send user id to analytics through google tag manager通过谷歌标签管理器将用户 ID 发送到分析
【发布时间】:2020-01-16 22:27:48
【问题描述】:

我正在尝试通过谷歌标签管理器将用户 ID 发送到谷歌分析。

我要在我的 gtm 触发器中设置一个字段,将变量 userId 设置为 {{userId}} 的值。

然后我尝试通过以下方式在我的 javascript 中设置它window.dataLayer.push({'userId': parseInt(account.id)});

在 chrome 中使用分析调试器后,我可以看到用户 ID 未应用于事后报告的事件。

【问题讨论】:

    标签: javascript html google-analytics gtag.js


    【解决方案1】:

    HEAD中的GTM sn-p之前添加此代码:

    dataLayer.push({'userId': parseInt(account.id)});
    

    【讨论】:

    • 我在 HEAD 中有 this snippet,我也将它包含在主 gtm sn-p 中 like this
    • 我还尝试在 gtm 控制台中将 userId 的默认值设置为 -1 之类的值,即使报告的事件仍然显示为 null :(
    • gtag chrome 调试器看到了这条消息,但 gtm 显然没有做任何事情
    • 你在使用dataLayer.push时有同样的问题吗...?
    • 是的,这两种方法产生相同的结果
    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 2014-07-15
    • 1970-01-01
    • 2018-06-14
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多