在本地主机上测试 Google Analytics [英] Test Google Analytics on Localhost

查看:37
本文介绍了在本地主机上测试 Google Analytics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Google Analytics 测试一些自定义触发事件.我想在本地环境中进行测试.

I need to test some custom firing events using Google Analytics. I'd like to test in a local environment.

我已经使用 apache 设置了我的测试站点,服务器名称为:my-ga-test.localhost/

I've set up my test site using apache with server name: my-ga-test.localhost/

根据你能在本地主机地址上测试谷歌分析吗?Google Analytics 文档,我能够调整我的 GA 代码以使用:

According to Can you test google analytics on a localhost address? and Google Analytics docs, I'm able to adjust my GA code to use:

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

我尝试设置新帐户以获取此网站的跟踪 ID,但出现以下错误:

I tried to set up a new account to get a tracking ID for this site, but I'm getting the following error:

URL 以无效的顶级域名结尾

URL ends with an invalid top-level domain name

如何使用 localhost 域生成代码,以便我可以更改跟踪 ID 代码以放置在我的 localhost 上?

How do I generate the code using localhost domain so I can alter the tracking ID code to put on my localhost?

推荐答案

创建新的 Google Analytics(分析)媒体资源时的网站 URL"字段不必与生产中使用的实际 URL 相同.它主要用于解析相对链接,而不是用于验证命中.

The "Website URL" field when creating a new Google Analytics property does not have to be the same as the actual URL that's used in production. It's primarily used for resolving relative links, not for validating hits.

只需将其更改为其他内容(例如 example.com),一切都会正常运行.

Just change it to something else (like example.com), and everything should work fine.

这篇关于在本地主机上测试 Google Analytics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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