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

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

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


当前回答

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

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

其他回答

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

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

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

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

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>结束标记之前。

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

以下是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

2014年更新

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

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

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