gpt4 book ai didi

javascript - 从本地主机测试 Google Analytics

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:31:35 31 4
gpt4 key购买 nike

我看过这个:Can you test google analytics on a localhost address?Getting Google Analytics to see a test server按照建议进行操作,但没有任何效果。

我做了什么:

  • 编辑了我的主机文件以添加多个域。
  • 在我的本地 Apache httpd 服务器上创建虚拟主机。
  • 在 Google Analytics 中创建了一个帐户,在该帐户中创建了几个“属性”(如在属于我的网站中)。
  • 编写了一个测试 HTML 页面,用于向 Google Analytic 服务报告页面 View 。

所有列表如下所示:

c:/Windows/System32/drivers/etc/hosts

127.0.0.1   ad-test             # for testing ad banners
127.0.0.1 testing.foo.tv # for testing ad banners
127.0.0.1 testing.foo-sdk.tv # for testing ad banners

httpd.conf的相关部分

<VirtualHost *:80>
ServerName ad-test
DocumentRoot D:/cygwin/home/wvxvw/projects/AdModule
<Directory "D:/cygwin/home/wvxvw/projects/AdModule">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>

(所有其他主机看起来都一样)

AdModule 目录有以下 index.html 文件:

<html><head></head><body>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-3']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></html>

(还有一个使用较新 API 的变体,但为了简短我没有发布它)

上述 HTML 页面中的 document.domain 属性设置为我在 Google Analytics 帐户设置中指定的域。

当我查看发送到 Google Analytics 服务的请求时,我可以看到正在加载的 JavaScript,然后还有 gif 图像。我可以调用其他 API 函数而不会出现错误,但仪表板中不会显示任何内容。

更新

两天后我回到了我的电脑上,这是我在 Google Analytics(分析)页面上找到的内容:

enter image description here

问题解决了...

最佳答案

您可以使用“实时”-> 左侧导航中的概览来查看实时数据

关于javascript - 从本地主机测试 Google Analytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16218105/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com