Google Analytics file not found.

I am trying to use Google Analytics on my site. I copied the code directly from the Google Analytics website and followed the instructions for embedding it in my HTML.

Here is my code:

<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'; // this is the file
    r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
    ga('create','not giving this out');ga('send','pageview');
</script>

When I load my page with this script, it takes a few seconds. Without a script, it loads almost instantly. This is how I know the problem is with the Google Analytics code.

After the page loads, the following error message appears:

Failed to load resource: net::ERR_FILE_NOT_FOUND

After some further investigation, the file was not found from e.src='//www.google-analytics.com/analytics.js'on line 5.

How can I make this file or script work correctly?

+4
source share
5 answers

, // (e.src), .

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

, - .

+6

?

dev, , .

html -,

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

+4

script. , 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>

script, . , , analytics.js- script. , // , HTTP HTTPS, , .

0

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

0

Between a program trying to read code and ad blocking software that you have on your system. Temporarily disable adblock on (or chrome or firefox). You must also disable any other ad blocking software. have a run. The analytics code will be found and function normally.

It is not recommended to change google analytics code.

0
source

Source: https://habr.com/ru/post/1547858/


All Articles