How To Defer Parsing Script Google Analytics To Speed ​​Up Blog Loading

Posting Komentar

defer analitycs js untuk mempercepat loading blog

Defer java script google analityc to speed up blog speed and loading is not long, of course it will be very good for the health of our blog. Analitycs JS from google is one of the high load scores for blog. And this is undeniably a common problem for bloggers.

Who doesn't want their blog to have a good appearance and have good loading speed. The score page load on some tools will detected some scripts that had problems loading. And Analytic JS or java script from google analitycs is one of the causes of loading a blog so slow down.

Several ways that can be done to lighten loading a blog are reduce some unnecessary widgets and JS. Several ways to lighten the loading of blogs that I have shared before, namely: How to defer Loading images and How to Install Lazy load JS Adsense.

By using this defer method, we can avoid the blocking effect rendering from Google Analytics by Delaying and saving JavaScript snippets analytics (caching) for faster page loading and improvements user experience.

How to defer js analytics to increase blog speed

For those of you who have installed Google Analityc on a blog template. Then generally, the installation script will look like this.

<script async='async' src='https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x'/>
<script>
//<![CDATA[
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxxxx-x');
//]]>
</script>

This script code has actually been optimized using the system Asynchronous (async) but this has no effect on loading blog. I don't know if you use another platform like wordpress.

In order not to interfere with the loading of your blog, change the script to the code below.

<script>
//<![CDATA[
function downloadJSAtOnload(){var d=document.createElement("script");d.src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x",document.body.appendChild(d)}window.addEventListener?window.addEventListener("load",downloadJSAtOnload,!1):window.attachEvent?window.attachEvent("onload",downloadJSAtOnload):window.onload=downloadJSAtOnload;
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxxxx-x');
//]]>
</script>

For other references, you can also apply the Google Analitycs Java defer code The following script.

<script>
//<![CDATA[
(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();
    i.initAnalytics = function() {
        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');
ga('send', 'pageview'); function atOnload() { initAnalytics(); } if (window.addEventListener) window.addEventListener("load", atOnload, false); else if (window.attachEvent) window.attachEvent("onload", atOnload); else window.onload = atOnload; //]]> </script>
Please replace the UA-xxxxxxx-x code with the blog Analytics ID You.

This method will automatically reduce the load [load] of the blog that was previously slow due to the influence of JS analityc. Then this will certainly improve our blog speed score is even better. Because as we are know that, a slow blog will greatly affect visitors.

Believe me, blog visitors will prefer a fast loading site rather than slow loading sites.

Thus this tutorial on how to defer (delay) loading Google Analityc JS to increase blog loading speed, Hopefully useful. thank you

Lori LikTik
Lori LikTik
Admin Situs Ini Suka Warna Ungu,Biru,Hijau dan Kelahiran tahun 1998, Blasteran Jawa Tengah (Magelang) - Jawa Barat (Bandung)

Related Posts

Posting Komentar