Google Analytics - Failed to load resource: http://www.google-analytics.com/ga.js

I've been noticing this error on Chrome's console for a while now:

enter image description here

I modified Google's script so that it logs the error, because it uses try{} catch{}, and this is what I got:

enter image description here

I haven't noticed considerable changes in the stats, it's always in ups and downs.

Also, this isn't only on my sites, but fricking everywhere. I haven't found bug reports or anything like that.

If I go to http://www.google-analytics.com/ga.js on the browser, it loads normally.

Does anyone have a clue of what causes this?


Solution 1:

It was a problem with AdBlock. I disabled it and now it loads it normally.

yagudaev suggests (read answers below) that in order to keep AdBlock from blocking Google Analytics, you need to edit the snippet provided and explicitly use https:// instead of the protocol-relative URL by default. This means changing

'//www.google-analytics.com/analytics.js'

into

'https://www.google-analytics.com/analytics.js'

Example:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXX-XX', 'auto');
  ga('send', 'pageview');
</script>

Solution 2:

It could also be your hosts file, here's mine:

$ grep -ni "google-analytics.com" /etc/hosts
6203:# 127.0.0.1  ssl.google-analytics.com #[disabled = Firefox issues]
6204:127.0.0.1  www.google-analytics.com #[Google Analytics]

Solution 3:

If it's an offline app (ie, you've defined a cache manifest) be sure to allow the network request.

See HTML5 Appcache causing problems with Google Analytics