我必须在本地机器上测试我的新GA帐户。

仅仅通过将谷歌提供的标准代码片段复制到页面上就可以工作吗?

我不想花24小时等着看它是否有效。


当前回答

I just want to add to what's been said so far, it may save a lot of headache, you don't need to wait 24 hour to see if it works, yes the total overview take 24 hour, but in Reporting tab, there is a link on left side to Real-Time result and it will show if anyone currently visiting your site, also I didn't have to set 'cookieDomain': 'none' for it to work on localhost, my setting is on 'auto' and it works just fine (I'm using MVC 5), on top of that I've added the script at the end of head tag as google stated in this page:

将您的代码片段(未更改,完整)粘贴到您想要跟踪的每个网页。将它粘贴在</head>结束标记之前。

这里有更多关于如何检查分析是否正常工作的信息。

其他回答

如果您使用IP或设置域为none,它将工作。 细节:

http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/

对于那些使用谷歌标签管理器与谷歌分析事件集成的人,你可以做那些家伙提到的从GTM自己设置cookie标志为none

打开GTM >变量>谷歌分析变量>,并将cookies标签设置为none

我也遇到了同样的问题,所有的解决方案都不起作用,直到我做了两件事:

明显的代码:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);   
_gaq.push(['_trackPageview']);

AND

我添加了localhost另一个FQDN -域名。我在Windows系统上通过编辑:

C:\Windows\System32\drivers\etc\hosts

文件中,我输入了以下内容:

127.0.0.1   my.domain.org

然后我去了http://my.domain.org/WebApp,这是包含谷歌分析JS的服务页面。

如果你在unix上,编辑/etc/hosts得到相同的结果。

它认为谷歌应该把Intranet配置放在GA FAQ中。他们只说你需要FQDA。是的,你做,但不是为了让他们访问你,你只需要在HTTP请求中有主机属性。

我认为FQDN的另一个原因是COOKIES!cookie是用来跟踪数据的,如果你没有FQDN, cookie就无法设置,JS代码就会停止,不会得到gif。

2014年更新

这现在可以通过简单地将域设置为none来实现。

ga('create', 'UA-XXXX-Y', 'none');

见:https://developers.google.com/analytics/devguides/collection/analyticsjs/domains localhost

以下是Tuong Lu Kim的回答:

假设:

ga(“create”、“aa - xxxxx - y”、“auto”);

...如果analysis .js检测到你在本地运行一个服务器(例如localhost),它会自动将cookie域设置为“none”....

摘录:

自动cookie域配置将_ga cookie设置在最高级别域上。例如,如果您的网站地址是blog.example.co。js将cookie域设置为。example.co. Uk。此外,如果analysis .js检测到你在本地运行一个服务器(例如localhost),它会自动将cookie域设置为“none”。 推荐的JavaScript跟踪代码片段为cookieDomain字段设置字符串'auto':


来源:https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id automatic_cookie_domain_configuration