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

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

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

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

Who doesn't want their blog to have a good appearance and have a good loading speed. The score page load in some tools will detect some scripts that have trouble loading. And Analytic JS or java script from Google Analytics is one of the causes of blog loading to slow down.

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

How to defer js analytics to increase blog speed

For those of you who have installed Google Analityc on a blog template. So generally, the script installation 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>
Or it is usually done using only the caller code
 <b:include data='blog' name='google-analytics'/>  

This script code has actually been optimized using an asynchronous system (async) but this has no effect on loading the blog. I don't know if you use another platform like wordpress. In order not to interfere with the loading of your blog, then change the script with 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 following Google Analitycs Java Script defer code.
 <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 change the code UA-xxxxxxx-x with your blog's Analytics ID.

This method will automatically reduce the [load] of blogs that were slow before due to the influence of JS analytics. So this of course will be able to improve our blog's speed score to be even better. Because as we all know, a slow blog will greatly affect visitors.

Believe me, blog visitors will prefer a fast loading site to a slow loading site.

That's the tutorial this time on how to defer (delay) loading Google Analytics JS to increase blog loading speed, Hopefully this is useful. thank you

Show Comments
Hide Comments

0 Response to "How To Defer Parsing Script Google Analytics To Speed ​​Up Blog Loading"

Post a comment

Top Ad Articles

Top Ad Articles

Top Ad Articles 2

Advertise Articles