【问题标题】:Test Google Analytics from localhost从 localhost 测试 Google Analytics
【发布时间】:2013-04-19 13:05:43
【问题描述】:

我已经看到了:Can you test google analytics on a localhost address?Getting Google Analytics to see a test server 遵循了建议,但没有任何效果。

我做了什么:

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

所有列表如下所示:

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(分析)页面上找到的:

问题解决了……

【问题讨论】:

  • 您要等多久才能看到数据?数据需要 24 小时以上才能在 GA 中显示
  • 稍等。 GA 不是实时的。
  • @wvxvw 这只是GA检查是否有页面代码的工具。这与接收数据并在报告中提供数据不同。
  • 我也有同样的问题。发生了什么 ?数据显示了吗?

标签: javascript html seo google-analytics


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2012-05-06
    • 2014-10-26
    • 1970-01-01
    • 2011-10-10
    相关资源
    最近更新 更多