简体   繁体   中英

Test Google Analytics from localhost

I've seen this: Can you test google analytics on a localhost address? and Getting Google Analytics to see a test server followed what was suggested, but nothing works.

What I did:

  • Edited my hosts file to have several additional domains.
  • Created virtual hosts on my local Apache httpd server.
  • Created an account in Google Analytics, created several "properties" (as in websites that belong to me) in that account.
  • Wrote a testing HTML page that would report a page view to the Google Analytic service.

All listings are shown below:

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

The relevant part of 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>

(looks the same for all other hosts)

The AdModule directory has the following index.html file:

<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>

(There is also a variation that uses newer API, but I'm not posting it for shortness)

The document.domain property in the above HTML page is set to the domain I specified in the Google Analytics account settings.

When I look at the requests sent to Google Analytics service, I can see the JavaScript being loaded and then the gif image, too. I can call other API functions w/o errors, but nothing gets displayed in the dashboard.

UPDATE

I was back on my PC in two days and here's what I found on the Google Analytics page:

在此处输入图片说明

Problem solved...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM