How to Install Lazy Load Google Analytics on a Blog
How to Install Lazy Load Google Analytics to Speed up Loading a Blog or Website.
![]() |
How to Install Lazy Load Google Analytics on a Blog |
How to Install Lazy Load Google Analytics on a Blog - Speeding up blog loading is a good optimization step to provide visitor comfort when loading site pages either via desktop or smartphone.
Lazy Load
the Google Analytics code to speed up blog loading. But before entering the tutorial stage, we will discuss a little about Google Analytics.
What is Google Analytics?
Google Analytics is Google's free online traffic tracking tool that is widely used by blogs or websites to analyze or get accurate, complete information about the state of blog visitors.gtag.js
like the one below into the blog or website html.
<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>
How to Install Lazy Load Google Analytics on a Blog
- Open the Blogger Dashboard
- Go to Themes > Edit HTML
- Find and delete the previous Google Analytics Code (example code as above)
- Then copy and paste the code below just above the </body> tag
- If already then Save
<!-- Global site tag (gtag.js) - Google Analytics --> <script> 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="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}(),lazyanalisis=!0)},!0) </script> <script> window.dataLayer=window.dataLayer||[]; function gtag(){dataLayer.push(arguments)} gtag("js",new Date()); gtag("config","UA-XXXXXXXXX-X") </script>
Don't forget to replace the highlighted part with your Analytics tracking ID .
Lazy Load Google Analytics 4
If your blog or website has upgraded ID Google Analytics 4 , you can use the following GA4 lazy load script:<script type="text/javascript">//<![CDATA[ var LazyAnalytics=false;window.addEventListener("scroll",function(){(0!=document.documentElement.scrollTop&&false===LazyAnalytics||0!=document.body.scrollTop&&false===LazyAnalytics)&&(!function(){var e=document.createElement("script");e.type="text/javascript",e.async=true,e.src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}(),LazyAnalytics=true)},true); //]]></script> <script type="text/javascript">//<![CDATA[ window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); //]]></script>
Post a Comment