Google Analytics 测量协议:如何从服务器上的 cookie 获取客户端 ID? [英] Google Analytics Measurement Protocol: How do I get the client-id from cookie on the server?

查看:19
本文介绍了Google Analytics 测量协议:如何从服务器上的 cookie 获取客户端 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用测量协议从服务器发送谷歌分析事件.

文档指出 cid 是必需的,并且应该是 UUID(https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid).

但是,我想使用与 _ga cookie 中存储的相同的客户端 ID.但根据 this,我不应该解析 id因为它可能会在没有警告的情况下更改.

另外,在浏览器中tracker.get('clientId')返回的字符串不是标准的UUID字符串,所以即使我在浏览器中检索到该值并将其发送到服务器,它仍然不在文档说它应该是的格式.

那么,我需要做什么才能以向前兼容的方式从 cookie 中获取客户端 ID?

解决方案

使用 ga.getAll()[0].get('clientId'); 获取 clientId.

关于他们的文档,Google 只是不希望您直接获取 cookie 并将其解析出来,因为 cookie 将来可能会发生变化.

他们概述的方法是获取 clientId 的首选方法.

关于 clientId 和使用 UUID,您几乎可以传入任何匿名标识某人的值(包括使用 GA 的 clientId).

我们所做的是使用 ga.getAll()[0].get('clientId'); 抓取客户端并将其发送到服务器,我们可以将 clientId 放入测量协议的 require 参数,并向 GA 发送服务器端测量协议请求,其中包含销售成本等交易数据.使用 clientId 可以将交易连接到源/媒介等.

I want to send a google analytics event from the server using the measurement protocol.

The documentation states the cid is required, and should be a UUID (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid).

However, I want to use the same client id as what is stored in the _ga cookie. But according to this, I shouldn't parse the id out of the cookie directly since it could change without warning.

Furthermore, the string returned by tracker.get('clientId') in the browser is not a standard UUID string, so even if I retrieved the value in the browser and sent it to the server, it still isn't in the format the documentation says it should be.

So, what do I need to do to get the client-id from the cookie in a forward compatible way?

解决方案

Use ga.getAll()[0].get('clientId'); to get the clientId.

Regarding their documentaiton, Google just doesn't want you to grab the cookie directly, and parse it out, as the cookie could change in the future.

The method they outlined is the preferred way to grab the clientId.

Regarding the clientId and using UUID, you can pretty much pass in any value that anonymously identifies somebody (including using GA's clientId).

What we've done is use ga.getAll()[0].get('clientId'); to grab the client and send it to the server where we can put the clientId into the require parameter for the measurement protocol, and send back a server-side measurement protocol request to GA with transaction data like Cost of Goods sold, etc. Using the clientId allows you to connect the transaction to the source/medium, etc.

这篇关于Google Analytics 测量协议:如何从服务器上的 cookie 获取客户端 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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