_ga cookie 中的值是什么? [英] what are the values in _ga cookie?

查看:47
本文介绍了_ga cookie 中的值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通用分析.通用分析创建第一方 cookie _ga

I am using universal analytics. universal analytics creates first party cookie _ga

 _ga=1.2.286403989.1366364567;

286403989 是 clientId

286403989 is clientId

1366364567 是时间戳

1366364567 is timestamp

什么是_ga cookie中的12?

what is 1 and 2 in _ga cookie?

推荐答案

_ga=1.2.286403989.1366364567;

第一个字段

这是一个版本号.以防将来 cookie 格式发生变化.目前似乎固定为 1.上面的那个是旧格式.较新的 cookie 将此值设置为GA1"

1st Field

This is a versioning number. In case the cookie format changes in the future. Seems to be fixed at 1 at the moment. The one above is an old format. Newer cookies have this value set at "GA1"

如果在不同的路径或域中设置了多个 cookie,此字段用于确定正确的 cookie.

This field is used to figure out the correct cookie in case multiple cookies are setup in different paths or domains.

默认情况下,cookie 设置在路径 / 和 document.location.hostname 上的域(去掉 www. 前缀).

By default cookie are setup at path / and at the domain on document.location.hostname (with the www. prefix removed).

您可以在 sub.example.com 上设置一个 _ga cookie,在 example.com 上设置另一个 cookie.由于浏览器上的 cookie API 的工作方式,无法判断您使用的 cookie 是正确的.

You could have a _ga cookie set at sub.example.com and another cookie set at example.com. Because the way the cookie API on browsers works there's no way to tell which is the correct cookie you use.

所以第二个数字是域中组件的数量(点分隔).

So the second number is the number of components (dot separated) at the domain.

  • 对于 sub.example.com,数字为 3
  • 对于 example.com,数字为 2

路径默认为 /,但您也可以通过将 cookiePath 选项传递给 ga.create 方法来更改它.如果你通过它,这个字段会变成 2 个数字,用破折号隔开.第二个数字是路径中的数字斜线.

The path defaults to / but you can also change it by passing the cookiePath option to the ga.create method. If you pass it this field becomes 2 numbers dash separated. And the second number is the number slashes in the path.

使用这些数字,analytics.js 脚本可以正确识别要使用的 cookie,以防设置多个 cookie.

Using these numbers the analytics.js script can correctly identify the cookie to be used in case there are multiple cookies set.

例如:想象一下,您有一个位于 sub1.sub2.example.com/folder1 的站点,如果您只想将 cookie 存储在您的站点上而不使其对其他子域或文件夹可见,您可以使用以下配置:

eg: Imagine that you have a site that lives at sub1.sub2.example.com/folder1 in case you want to store the cookie only on your site and not make it visible to other subdomains or folders you can use the following configs:

ga('create', 'UA-XXXX-Y', {
  'cookiePath': '/folder1/',
  'cookieDomain': 'sub1.sub2.example.com'
});

在这种情况下,cookie 看起来像这样;

In this case the cookie will look somoething like this;

_ga=1.4-2.XXXXXXXX.YYYYYYY

第三场

这是一个随机生成的用户 ID.用于识别不同的用户.

3rd Field

This is a random generated user ID. Used to identify different users.

这是第一次为该用户设置 cookie 的时间戳.

It's a timestamp of the first time the cookie was set for that user.

new Date(1366364567*1000)
> Fri Apr 19 2013 06:42:47 GMT-0300 (BRT)

这也用于在 userId 冲突的情况下唯一标识用户.

This is also used to uniquely identify users in case of userId collisions.

值得一提的是,cookie 不是 API.将来它可能会完全改变.Google 不建议直接读取/写入 _ga cookie.您应该通过其中一个跟踪库(例如 analytics.js)与 Google Analytics 进行交互.除了好奇心之外,这些信息没有太多用处.

Worth mentioning that a cookie is not an API. In the future it may completely change. Google doesn't recommend reading/writing the _ga cookie directly. You should interact with Google Analytics through one of the tracking libraries such as analytics.js. There's not a lot of use for this information other than curiosity.

如果您直接读取/写入 cookie,那您就做错了.

If you are reading/writing directly the cookie you are doing it wrong.

这篇关于_ga cookie 中的值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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