Analytics.js:“自动”参数在跟踪对象创建时做了什么? [英] Analytics.js: What does 'auto' argument do on tracking object creation?

查看:77
本文介绍了Analytics.js:“自动”参数在跟踪对象创建时做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚切换到新的Google Analytics(分析) Universal Analytics(分析)平台,使用新的JavaScript API - Analytics.js



第一个示例代码片段docs 创建一个跟踪对象,然后使用该跟踪对象记录当前页面的综合浏览量。

  ga ('创建','UA-XXXX-Y','自动'); 
ga('send','pageview');

注意'auto'参数 - 我无法计算出的含义。



我浏览了方法参考,似乎相关参数是可选的,并且应该包含配置键/值对。示例可以在字段参考中找到。如果这个参数是可选的,那么在这里传递'auto'似乎很奇怪,除非它有意义,所以你必须假定它确实如此,但我找不到任何提及。



此外,在您帐户中的自动生成代码中,它会执行类似的操作,但会将您的域名传递给您。

  ga('create','UA-XXXX-Y','mydomain.com'); 

当您的域再次可用时,您的域名被明确地传递,这表明它做了一些有意义的事情 - 否则它们'd可能也只是在这里使用'auto'。但是,再一次,没有提到为什么这样做。



我是否错过了一些非常明显的东西?

解决方案

实际上,当我查找代码时,它并没有传递我的属性名称,而是在配置中设置了标准域 - 这使得更有意义,因为参数设置了Cookie域将auto改为 window.location.hostname 的值添加到主机名没有子域)。或者,您可以传递配置对象作为第三个参数(可能包含cookie域设置)。尝试设置一个错误的参数 - 由于代码无法设置cookie,因此分析调试器中会出现无存储错误。


I've just switched to the new Google Analytics Universal Analytics platform, using the new javascript API - Analytics.js

In the first example code snippet from the docs a tracking object is created, then a pageview of the current page is logged using that tracking object.

ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');

Notice the 'auto' argument - I can't work out what that's there for.

I had a look at the method reference and it seems that the relevant parameter is optional and should contain configuration key/value pairs. Examples can be found in the field reference. If the parameter is optional it seems odd to pass 'auto' here unless it does something of significance, so you have to assume it does, but I can't find any mention of this.

Also, in the auto generated code in your account it does a similar thing but passes your domain

ga('create', 'UA-XXXX-Y', 'mydomain.com');

The fact your domain is specifically passed when they have it available again suggests it does something meaningful - otherwise they'd probably just use 'auto' here too. But again, there's no mention of why this is done.

Am I missing something really obvious?

解决方案

Actually when I look in to code it does not pass the name of my property but the standard domain set in the configuration - which makes a lot more sense, since the parameter sets the cookie domain (in case of "auto" to the value of window.location.hostname to the hostname without subdomains). Alternatively you can pass a configuration object as third parameter (which might contain a cookie domain setting). Try and set a wrong parameter - you'll get a "no storage" error in the analytics debugger since the code cannot set a cookie.

这篇关于Analytics.js:“自动”参数在跟踪对象创建时做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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