通过测量协议向Google Analytics(分析)发送跟踪数据时,客户端ID是什么? [英] What is the client ID when sending tracking data to google analytics via the measurement protocol?
问题描述
我想使用Google的新测量协议从我的服务器发送跟踪事件而不是JavaScript。
此页面显示客户端ID是必需的:
https://developers.google.com/analytics/devguides/collection/protocol/v1/ devguide#required
此页面显示它是可选的:
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor
另外,这些文档中定义的格式是不同的 - 第一页给出一个整数作为示例,并且只是说它是唯一值,而第二个链接表示它应该是一个UUID。
如果我在后端发送用户ID或生成的UUID,Google会如何知道将该访问者链接到现有访客会话?看起来我需要检索GA对现有用户的内部引用。
感谢任何帮助 - 谢谢!
整数或UUID
$ b
必需/可选 通过js跟踪,Analytics(分析)服务器会忽略发送缺少用户标识的请求。所以假设它是必需的。 使用测量协议操作链接网络访问者 如果您希望将您的后端用户与以前使用Google Analytics(分析)javascript 更新 在撰写本文时,如果您从跟踪器获取clientId,给你一个UUID,但是两个随机的32位整数格式为XY。此实现将来可能会更改为UUID。 或者用您自己的值设置它(如后端生成的UUID): I want to use Google's new measurement protocol for sending tracking events from my server instead of JavaScript. This page says the client ID is required:
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#required And this page says it's optional:
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor 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. 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! Integer or UUID The Required/Optional With js tracking, a request sent with a missing user id is ignored by Analytics servers. So assume that it is required. Link web visitor with measurement protocol actions If you want to link your backend user with a visitor previously tracked with Analytics javascript Update The 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. Or set it with your own value (like a backend generated UUID):
这篇关于通过测量协议向Google Analytics(分析)发送跟踪数据时,客户端ID是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! _utma
cookie中的第二个值。在js跟踪中,它是一个随机整数(由 Math.round(2147483647 * Math.random())
)生成。但是它是作为字符串进行存档和发送的:所以您可以使用这两种格式(整数或UUID)。
ga.js
跟踪的访问者关联起来,则可以获取 cid
来自 _utma
cookie的值。但我不推荐它。每当它发生变化时(终端或浏览器更改,Cookie清理等),您都将失去与客户之前操作的链接。
cid
现在存储在cookie _ga
中。你可以在javascript中获得它:
ga(function(tracker){
var clientId = tracker.get 'clientId');
});
<$ c'c> ga('create','UA-XXXXX-Y',{'clientId':'your_client_id'});
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).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
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');
});
ga('create', 'UA-XXXXX-Y', {'clientId': 'your_client_id'});