Google Analytics file not found

google-analytics, javascript

Solution

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.

Problem

I am trying to use Google Analytics in my site. I copied the code directly from the Google Analytics website and followed the instructions for embedding it into 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 number of seconds. Without the script, it loads practically instantly. This is how I know the problem is in the Google Analytics code. The following error message appears after the page finally loads: ``` Failed to load resource: net::ERR_FILE_NOT_FOUND ``` After some further investigation, the file not found is from `e.src='//www.google-analytics.com/analytics.js'` on line 5. How can I get this file or script to work correctly?

Original source