通过测量协议将跟踪数据发送到 Google Analytics 时的客户端 ID 是什么? [英] What is the client ID when sending tracking data to google analytics via the measurement protocol?
问题描述
我想使用 Google 的新测量协议从我的服务器而不是 JavaScript 发送跟踪事件.
I want to use Google's new measurement protocol for sending tracking events from my server instead of JavaScript.
此页面说需要客户端 ID:https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#required
This page says the client ID is required: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#required
这个页面说它是可选的:https://developers.google.com/analytics/devguides/collection/protocol/v1/参数#visitor
And this page says it's optional: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor
另外,这些文档中定义的格式是不同的——第一页给出了一个整数作为例子,只是说它是一个唯一的值",而第二个链接说它应该是一个 UUID.
Plus, the format defined in these docs is different- the first page gives an integer as an example and just says it's "a unique value" while the second link says it should be a UUID.
如果我在后端发送用户 ID 或生成的 UUID,Google 如何知道将该访问者链接到现有访问者会话?似乎我需要检索 GA 对现有用户的内部引用.
If I send either user IDs or generated UUIDs on my backend, how will Google know to link that visitor to an existing visitor session? It seems like I would need to retrieve GA's internal reference to an existing user.
感谢任何帮助 - 谢谢!
Any help is appreciated - thanks!
推荐答案
整数或 UUID
cid
相当于您使用 javascript 跟踪时 _utma
cookie 中的第二个值.在js跟踪中,它是一个随机整数(由Math.round(2147483647 * Math.random())
生成).但它被存储并作为字符串发送:因此您可以使用两种格式(整数或 UUID).
The cid
is the equivalent of the second value in the _utma
cookie when you use the javascript tracking. In js tracking, it is a random integer (generated by Math.round(2147483647 * Math.random())
). But it is strored and sent as a string : so you can use both formats (integer or UUID).
必需/可选
通过 js 跟踪,分析服务器会忽略发送的缺少用户 ID 的请求.所以假设它是必需的.
With js tracking, a request sent with a missing user id is ignored by Analytics servers. So assume that it is required.
将网络访问者与测量协议操作联系起来
如果您想将您的后端用户与之前使用 Analytics javascript ga.js
跟踪的访问者相关联,您可以从 _utma<获取
cid
值/代码> cookie.但我不推荐它;每次更改(终端或浏览器更改、cookies 清理等)时,您都会失去与客户之前操作的链接.
If you want to link your backend user with a visitor previously tracked with Analytics javascript ga.js
, you can get the cid
value from the _utma
cookie. But I don't recommend it; each time it changes (terminal or browser change, cookies cleaning, etc.), you will lose the link with your customer's previous actions.
更新
提出问题时 analytics.js
不存在.cid
现在存储在 cookie _ga
中.您可以通过以下方式在 javascript 中获取它:
The analytics.js
did not exist when the question was asked. cid
is now stored in the cookie _ga
. You can get it in javascript with:
ga(function(tracker) {
var clientId = tracker.get('clientId');
});
在撰写本文时,当您像上面的代码一样从跟踪器获取 clientId 时,它不会为您提供 UUID,而是两个X.Y"格式的随机 32 位整数.此实现将来可能会更改为 UUID.
As of writing this, when you do get the clientId from the tracker as in the above code it won't give you a UUID but two random 32-bit integers in the format of "X.Y". This implementation may change to the UUID in the future.
或者用你自己的值设置它(比如后端生成的 UUID):
Or set it with your own value (like a backend generated UUID):
ga('create', 'UA-XXXXX-Y', {'clientId': 'your_client_id'});
这篇关于通过测量协议将跟踪数据发送到 Google Analytics 时的客户端 ID 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!