Analytics.js:“自动"参数在跟踪对象创建方面有什么作用? [英] Analytics.js: What does 'auto' argument do on tracking object creation?

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

问题描述

我刚刚切换到新的 Google Analytics Universal Analytics 平台,使用新的 javascript API - Analytics.js

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');

请注意 'auto' 参数 - 我无法弄清楚它的用途.

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

我查看了方法参考似乎相关参数是可选的,应该包含配置键/值对.示例可以在字段参考中找到.如果参数是可选的,在此处传递 'auto' 似乎很奇怪,除非它具有重要意义,因此您必须假设它确实如此,但我找不到任何提及.

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');

您的域在他们再次可用时被明确传递的事实表明它做了一些有意义的事情 - 否则他们可能也会在这里使用 'auto' .但同样,没有提到为什么要这样做.

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?

推荐答案

实际上,当我查看代码时,它不会传递我的属性名称,而是传递配置中设置的标准域 - 这更有意义,因为该参数设置 cookie 域(如果 "auto"window.location.hostname 的值到没有子域的主机名).或者,您可以将配置对象作为第三个参数(可能包含 cookie 域设置)传递.尝试设置错误的参数 - 由于代码无法设置 cookie,您将在分析调试器中收到无存储"错误.

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天全站免登陆