简体   繁体   English

如何在Google Analytics(分析)中取得具有自订维度的clientId

[英]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.

相关问题 Google Analytics(分析)自定义维度 - Google analytics custom dimensions 如何在Google Analytics(分析)中设置自定义维度 - How to set custom dimensions in Google Analytics Google Analytics空客户端ID - Google Analytics empty clientID 如何注册一个独特的页面视图以及如何使用自定义维度Google Analytics - How to register a uniquePageview and how to use custom dimensions google analytics ionic应用程序中的Google Analytics(分析)自定义维度 - Google Analytics custom dimensions within ionic app 随时修改Google Analytics自定义维度 - Modify Google Analytics custom dimensions on the go Google Analytics 不发送带有网页浏览点击的自定义维度 - Google analytics not sending custom dimensions with pageview hits Google Analytics(分析)使用gtag发送两个自定义维度 - Google Analytics send two custom dimensions with gtag 在Google AnalyticsAPI中使用和查询自定义维度 - Using and querying Custom Dimensions in Google Analytics API 如何为与之前进行的相同调用/匹配的Google Analytics(分析)自定义维度添加代码,并添加一些自定义维度(需要花费一些时间来计算) - How to add code for Google Analytics custom dimensions for the same call/hit made prior, with some custom dimensions ( which take time to calculate )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM