[英]How to get clientId with custom dimensions in google analytics
I replace my current default " universal google analytics " code to custom JavaScript to get the clientId but I got string value while using ( Like: clientId ). 我将当前默认的“ 通用Google Analytics(分析) ”代码替换为自定义JavaScript,以获取clientId,但是在使用(例如:clientId ) 时却得到了字符串值。
GA code: GA代码:
ga('create', 'UA-xxxxxx-x', 'auto'); ga('create','UA-xxxxxx-x','auto'); ga(function(tracker){ var clientId = tracker.get('clientId'); }); ga(function(tracker){var clientId = tracker.get('clientId');}); ga('set', 'dimension1', clientId); ga('set','dimension1',clientId); ga('send', 'pageview'); ga('send','pageview');
This would hardly work since you're assigning cilentID value to the function scoped variable that can not be seen outside the readyCallback function. 这几乎不起作用,因为您正在将cilentID值分配给在readyCallback函数之外无法看到的函数作用域变量。 Consider the following code: 考虑以下代码:
ga('create', 'UA-XXXXX', 'auto');
ga(function(tracker) {
var cid = tracker.get('clientId');
tracker.set('dimension1', cid); // ID is to be set right after the traker is available
});
ga('send', 'pageview');
UPDATE: clientId is available through the API as ga:clientId 更新:clientId可通过ga:clientId通过API获得
No need to set clientId (or userId) in a custom dimension anymore. 无需再在自定义维度中设置clientId(或userId)。
Note to anyone using the Universal Analytics User ID feature The values returned in ga:clientId is actually the userId Even more interessting. 给使用Universal Analytics用户ID功能的任何人的提示ga:clientId中返回的值实际上是userId,甚至更有趣。 (As of time of writing) GA fails if you request clientId from a User ID view. (截至撰写本文时)如果您从“用户ID”视图中请求clientId,则GA失败。 So you should use a non-User ID view to get the User ID. 因此,您应该使用非用户ID视图来获取用户ID。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.