How to Lazy Load Google Analytics Code in Blogger

Google Analytics is a commonly used JavaScript code on websites, but it can cause a render-blocking effect during webpage loading.

How to Lazy Load Google Analytics Code in Blogger

It’s important to keep the code that tracks visitors coming to the website. However, you can improve the page speed by Lazyloading the Google Analytics code on the Blogger website. To do this, you can follow the steps given in this article.

Install Lazy Load Google Analytics code in Blogger?

#1: Go to the Blogger settings page and remove the Google Analytics property ID. 

#2: Now go to the theme section and create a backup of your theme. 

#3: Now click on edit HTML and search for old analytics code if any and remove it. 

So generally, the script installation will look like this. 

<script async='async' src=''/>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxxxx-x');

#4: Just remove the highlighted part and add the below script just above it. 

<script type='text/javascript'>//<![CDATA[
var lazyanalisis=!1;window.addEventListener("scroll",function(){(0!=document.documentElement.scrollTop&&!1===lazyanalisis||0!=document.body.scrollTop&&!1===lazyanalisis)&&(!function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src="";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}(),lazyanalisis=!0)},!0);

#5: Here replace the tracking code (highlighted) in both of the codes and paste it just above the </body> tag. 

Now save your theme and the lazy analytics code is added to your blogger website. Now check your analytics code, if it is properly working or not. 

In this way, you can install google analytics code to Blogger and improve the loading speed. 

Disadvantage of Lazyload Google Analytics

Lazyloading Analytics code in a website may result in incomplete tracking of views if a user closes the page before it fully loads.
It doesn’t make sense to track a user who hasn’t fully loaded the page.
It’s important to note that subsequent visits to the website will not affect the cached analytics data in the user’s browser.
I highly recommend implementing lazy loading for Analytics code on your blogger website.

Similar Posts


  1. Great article! I would like to improve my Blogger website speed by implementing the Lazy load but I’m scared of the disadvantages.

Leave a Reply

Your email address will not be published. Required fields are marked *