Google Analytics file not found

主宰稳场 提交于 2019-12-04 12:12:50

I found out that if you remove the // from the beginning (e.src), the request works.

<script>
    (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
    function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
    e=o.createElement(i);r=o.getElementsByTagName(i)[0];
    e.src='www.google-analytics.com/analytics.js'; // forward slashes taken out
    r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
    ga('create','not giving this out');ga('send','pageview');
</script>

I hope anyone with this problem in the future finds this helpful.

Is the error happening during local development or on a server?

If local dev then it maybe because it's trying to load it from the local hard disk.

If I don't load my html file via a local webserver I get this error

GET file://www.google-analytics.com/analytics.js net::ERR_FILE_NOT_FOUND

It works fine through a server

This looks like a modified version of the script. When I look at the tracking code information for one of my properties, I see a different script.

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxx-x', 'auto');
  ga('send', 'pageview');

</script>

This is the default script as far as I know. It differs slightly, especially the part where it calls the analytics.js-script. I do think the // should be in the code, as it helps with the relative calls to HTTP or HTTPS, but it might be working anyway like you stated.

Replace //www.google-analytics.com/analytics.js for http://www.google-analytics.com/analytics.js

There is interference between the program trying to read the code and ad blocking software you have on your system. Disable adblock on ie (or chrome or firefox) temporarily. You must also disable any other ad blocking software you may have running. The analytics code will be found, and function normally.

It is not advisable to modify the google analytics code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!