使用Google跟踪代码管理器的trackingId和clientId [英] trackingId and clientId with Google tag manager

查看:622
本文介绍了使用Google跟踪代码管理器的trackingId和clientId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用analytics.js,我可以通过以下功能访问trackingId或clientId:

Using analytics.js, i can access to trackingId or clientId with this functions:

ga.getAll()[0].get('trackingId')
ga.getAll()[0].get('clientId')

使用Google跟踪代码管理器时,没有ga对象. 我如何获得这些参数?

With Google tag manager, there is no ga object. How i can get that parameters?

推荐答案

跟踪ID是通过常量字符串宏(出于可重用性)或作为字符串输入到GTM中的.可以通过自定义Java脚本(从我要提到的博客中)获取客户端ID:

The tracking ID is input into GTM either through a constant string macro (for reusability), or just as a string. The client ID can be fetched through custom Javascript (from the blog I am about to mention):

function() {
    try {
       var tracker = ga.getAll()[0];
       return tracker.get('clientId');
    }
    catch(e) {
       console.log("Error fetching clientId");
       return "n/a";
    }
}

查看此博客: http://www.simoahava .com/analytics/macro-magic-google-tag-manager/#7

这篇关于使用Google跟踪代码管理器的trackingId和clientId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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