Page speed is important because it contributes to the user experience. Everyone expects the Internet to be more or less instant when browsing the web. If your content takes too long to load, you increase the risk of site visitors leaving your site to move on to another page that loads faster.
Is your website suffering from slow loading times and low PageSpeed scores? In this article, we’ll explore how to fix issues with Google Analytics slowing down your site, allowing it to load faster and achieve higher scores on PageSpeed Insights.
Why does the website load Google Analytics super slow?
When you add the Google Analytics code to the website, those default snippets will definitely reduce the page load speed and lower the score when testing with tools like Gtmetrix or Google PageSpeed Insights. The reason is that when the web page starts to load, the code will send a request to the application’s source to download and display its functions. That will increase the original page size and, of course, slow down your website due to Google Analytics.
Speeding Up When Google Analytics Slows Down Your Website
There may be many ways, but the approach that we have found effective to fix the issue of Google Analytics slowing down your website is to load the code only when the user interacts with the website via a scroll event, which means only when the user scrolls with the mouse or clicks. This way, the code won’t load or execute until the user interacts with the browser for the first time, and it won’t affect the user experience or slow down the initial website load due to Google Analytics.
Once you have a piece of code to add to your site, by default it will look like this:
Here is the edited code with the scroll
load event. Using this code will ensure Google Analytics no longer slows down your website. Don’t forget to replace your gtag id (G-xxxxxxx
) with your actual ID.
To add the code to your WordPress site, you can use the wp_footer
function and paste it at the end of the functions.php
file in your theme. It will look like this:
By implementing the scroll load event technique for Google Analytics, you can significantly improve your website’s page speed, boost performance scores, and deliver a better user experience overall.
Read more: How to Fix Google Adsense Ads Slowing Down Your Website