您可以在本地主机地址上测试Google Analytics(分析)吗?(Can you test google analytics on a localhost address?)

编程入门 行业动态 更新时间:2024-10-24 08:30:19
您可以在本地主机地址上测试Google Analytics(分析)吗?(Can you test google analytics on a localhost address?)

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

这是否只是将Google提供的标准代码段复制到页面上?

我不想花24小时等待看看是否会或不行。

I have to test out my new GA account on my local machine.

Will this work just by copying the standard snippet supplied by Google onto the page ?

I don't want to spend 24 hours waiting to see if it will or won't work.

最满意答案

这个问题今天仍然有效,但技术发生了变化。 旧的Urchin跟踪器已弃用并已过时。 新的异步Google Analytics(分析)跟踪代码使用稍微不同的代码来实现相同的结果。

Google Analytics(分析)经典 - 异步语法 - ga.js

Google Analytics(分析)的跟踪域设置为none的当前语法如下所示:

_gaq.push(['_setDomainName', 'none']);

Google Analytics(分析)将会在本地主机上启用_utm.gif跟踪器请求。 您可以通过打开您喜爱的浏览器中的开发人员工具并在页面加载期间观察网络请求来验证这一点。 如果它正在运行,您将在网络请求列表中看到对_utm.gif的请求。

通用Analytics(分析) - analytics.js更新了2013年

Google发布了一个名为“Universal Analytics”的新版本的分析(2012年底或2013年初)。 在我写的这个程序仍然在BETA,所以上述代码仍然推荐给大多数现有Google Analytics(分析)安装的用户。

然而,对于使用新的analytics.js代码的新开发, Google Analytics(分析),高级配置 - Web跟踪文档显示,我们可以使用此新代码在localhost上测试Universal Analytics:

ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'none' });

查看链接的文档,了解有关Universal Analytics高级配置的更多详细信息。

This question remains valid today, however the technology has changed. The old Urchin tracker is deprecated and obsolete. The new asynchronous Google Analytics tracking code uses slightly different code to achieve the same results.

Google Analytics Classic - Asynchronous Syntax - ga.js

The current syntax for setting the tracking domain to none on google analytics looks like this:

_gaq.push(['_setDomainName', 'none']);

Google analytics will then fire off the _utm.gif tracker request on localhost. You can verify this by opening the developer tools in your favorite browser and watching the network requests during page load. If it is working you will see a request for _utm.gif in the network requests list.

Updated 2013 for Universal Analytics - analytics.js

Google released a new version of analytics called "Universal Analytics" (late 2012 or early 2013). As I write, this the program is still in BETA so the above code is still recommended for most users with existing installations of Google Analytics.

However, for new developments using the new analytics.js code, the Google Analytics, Advanced Configuration - Web Tracking Documentation shows that we can test Universal Analytics on localhost with this new code:

ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'none' });

Check out the linked documentation for more details on advanced configuration of Universal Analytics.

Update 2019

Both Global Site Tag - gtag.js and Universal Analytics - analytics.js will detect localhost automatically. You do not need to make any change to the configuration.

If gtag.js detects that you're running a server locally (e.g. localhost), it automatically sets the cookie_domain to 'none'.

- developers.google.com

更多推荐

本文发布于:2023-08-07 20:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您可以   主机   地址   测试   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!