Eliminate render blocking of Google Analytics

I have just tested my website on Google’s PageSpeed Insights and it says I need to Remove render-blocking JavaScript of my https://www.WEBSITE.com/google_analytics_auto.js file, which when opened looks like

 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'ACCOUNT NUMBER-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

I am not sure what I need to do in order to remove the render blocking, any thoughts please?

Where on the page did you put the script?

before the closing section

Does anybody have any ideas? Can it go in the footer for instance?

I can only guess because I am unable to test the page.

I always have Google Analytics and other JavaScript inserted last on the web page and just before the closing </body></hrml> statements.

Give your web page a try with the JavaScript loaded at the end and see if there are any problems.

Edit:
Google AMP Pages are a special case and require JavaScript to be loaded in the header in order to calculate scripts which require loading above the fold. The remainder of the web page is “Wiki Lazy loaded”

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.