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

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

问题描述

我想使用测量协议从服务器发送google analytics事件。



文档声明了cid是必需的,并且应为UUID( https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid )。



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



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



所以,我需要做什么来获取客户端id

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



关于他们的文档,Google不希望你直接抓取cookie,并解析它,因为以后可能会改变cookie。



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



关于clientId和使用UUID,传入任何匿名标识某人的值(包括使用GA的clientId)。



我们所做的是使用 ga.getAll ] .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天全站免登陆