1

The relevant line of the Google script is:

(window,document,'script','//www.google-analytics.com/analytics.js','ga');

I am running this particular file locally (as in, I double-click "index.html" on Windows Explorer and it opens in Chrome.

After about a minute of trying to load this file it fails with net::ERR_FILE_NOT_FOUND reported in the Developer Console.

I understand why this is happening, it is trying to load this as a local file. If I do this it works just fine:

(window,document,'script','www.google-analytics.com/analytics.js','ga');

In other words, I eliminated the //. This would work just as well:

(window,document,'script','http://www.google-analytics.com/analytics.js','ga');

Is going explicitly doing it this way to only track real websites?

If so, how are you dealing with this issue for local development?

I do run a VM with Ubuntu server for local development of more elaborate sites. In this case I was working on a single file landing page that I knocked out quickly and wanted to just test just as easily but ran into the browser hanging waiting for analytics.js

Is it safe to remove the // or add http: in general terms. I don't generally like to modify Google code unless I fully understand why they are doing things in a specific way and what the consequences of my actions might be.

martin's
  • 3,853
  • 6
  • 32
  • 58

2 Answers2

0

Instead of viewing the file locally, run it through a local webserver. Two easy options are

  1. XAMPP: http://portableapps.com/apps/development/xampp
  2. Uniform Server: http://www.uniformserver.com/

Both require no installation. If you have Visual Studio or WebMatrix, you can also run it through Cassini or IISExpress.

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
  • Thanks. I run a VM with Ubuntu 14.04 LTS as my development server. So, I would not normally have this issue. This one got me because I got lazy and simply wanted to work on this simple isolated html file directly off the Windows file system. Now I am wondering about whether or not it would be advisable to edit the Google URL as I indicated in my question on files that deploy to real production servers. I can't think of one negative consequence. – martin's Aug 24 '14 at 08:02
  • Specifically, don't change it to `http://`; you want to use `https://` if the site itself is running under SSL. Using `//` lets the script 'inherit' the same protocol. – Tieson T. Aug 24 '14 at 08:10
0

It can be that you are using a VPN(Virtual private network) which analytics blocks. Try loading https://www.google-analytics.com/analytics.js If id does not work try disabling the VPN and try again.

Or as someone else mentioned it could be that your AdBlock is blocking it.

Sharthan
  • 123
  • 1
  • 8