How to Defer Google Analytics JS on a Blog

May 20, 2021

Blogger SEO

t f B! P L
How to Defer Google Analytics JS on a Blog

There is no need to doubt the link between web pages and Google Analytics. All matters relating to visitor data and other activities are obtained from these services.

Its use is also expected to help bloggers in terms of data management. That way, everyone can run a more integrated and algorithmic analysis.

But Google Analytics also has a negative effect. Many have complained about the access speed that is getting longer after it is installed. This can be proven by the appearance of cache duration in the PageSpeed ​​Insights test.

PageSpeed Insights - /analytics.js

Source: PageSpeed Insights

Not only PageSpeed ​​Insights, GTmetrix also often displays JS Analytics as an element that affects blog loading.

Why is Google Analytics slowing down access?

As information, Google as the developer always updates this service all the time. Now in the last update, added a Global Site Tag for more complex tracking.

The addition of these features certainly makes the script load heavier. As a result, page loads are slower.

Older Version of Google Analytics

Generally, every Google Analytics script has been equipped with asynchronous commands to load faster. But still, the access speed is not as effective as before use.

<script async src="https://www.google-analytics.com/analytics.js"></script>

What is Defer?

Defer is a command to load scripts in the background first. After the page has been successfully loaded 100%, then the script can be executed directly to the page.

Meanwhile, according to the language, defer means delay. This command has a working system that is almost similar to lazy load ads and images.

How to Defer Google Analytics JS on a Blog

  • Go to BLOGGER
  • Select menu THEME
  • Select EDIT HTML
  • Paste above </body>:

<script>

function downloadJSAtOnload(){var d=document.createElement("script");d.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(d)}window.addEventListener?window.addEventListener("load",downloadJSAtOnload,!1):window.attachEvent?window.attachEvent("onload",downloadJSAtOnload):window.onload=downloadJSAtOnload;
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga("create", "UA-*********-*", "auto");
ga("send", "pageview");

</script>

  • Paste above </head>:

<link as="script" href="https://www.google-analytics.com/analytics.js" rel="preload" />

  • Select SAVE
  • Done.

Conclusion

Although it has a very important and vital role, what we often need is tracking the source of traffic. Not the current tracking system.

Especially in May 2021, Google plans to update its algorithm to Google Page Experience. The algorithm is very concerned about the speed of access when loaded by visitors.

If you don't want to go down the rankings, fix all the factors that have a large size from now on.

Enough of the articles on How to Defer Google Analytics JS on this Blog, Thank you.

Search

Label

TechWebMate