您可以在本地主机地址上测试谷歌分析吗? [英] Can you test google analytics on a localhost address?

查看:29
本文介绍了您可以在本地主机地址上测试谷歌分析吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我不想花 24 小时等待看它是否会起作用.

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

推荐答案

这个问题今天仍然有效,但是技术已经发生了变化.旧的 Urchin 跟踪器已被弃用且已过时.新的异步 Google 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.

在谷歌分析中将跟踪域设置为无的当前语法如下所示:

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

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

然后 Google 分析将在本地主机上触发 _utm.gif 跟踪器请求.您可以通过在您喜欢的浏览器中打开开发人员工具并在页面加载期间观察网络请求来验证这一点.如果它正常工作,您将在网络请求列表中看到对 _utm.gif 的请求.

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.

Google 发布了名为Universal Analytics"的新版分析工具;(2012 年底或 2013 年初).在我撰写本文时,该程序仍处于 BETA 阶段,因此仍建议大多数已安装 Google Analytics(分析)的用户使用上述代码.

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.

但是,对于使用新 analytics.js 代码的新开发,Google Analytics,高级配置 - 网络跟踪文档表明我们可以使用这个新代码在本地主机上测试 Universal 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'
});

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

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

全局站点标签 - gtag.js 和 Universal Analytics - analytics.js 都会自动检测 localhost.您无需对配置进行任何更改.

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.

如果 gtag.js 检测到您在本地运行服务器(例如 localhost),它会自动将 cookie_domain 设置为 'none'.

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

这篇关于您可以在本地主机地址上测试谷歌分析吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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