How to Boost Site Speed By Hosting gtag.js Locally

Disclosure: Your support keeps the site running! We may earn a referral fee for some of the recommended services on this page. These are services we have tried or use. Learn more.

In today’s article I’m going to show you how to optimize your WordPress website’s page speed by hosting gtag.js locally. And fix the “leverage browser caching” problem in Pingdom and GTmetrix speed tests.

Although, the Google Analytic code is a must have JavaScript for tracking analytic data. It causes your website to fail speed tests created by Google itself. The global site tag (gtag.js) can significantly cause your page speed to dwindle.

Of course, there are many contributing factors that might slow down a site for users. So, optimizing for speed can be super confusing and frustrating. However, one persistent problem that cripples almost every site, is the negative effect of external Javascript files.

How to boost website speed in WordPress

It is undeniably true that site speed plays a vital role in your online success. Most especially for E-commerce websites. Google made this clear with it’s core web vitals update; which made page loading time a search ranking factor. The logic here is, faster page loads translates into better user experience and higher conversion rates. It’s no big secret at all, site visitors will leave if a page loads longer than necessary.

There are many ways of improving user experience in this regard. And one of them is to ensure that your site meets the recommended Core Web Vitals scores.

But one difficult challenge you might face, is improving the loading of external JavaScript. Caching might help Google Analytics code load time in our case, but not always. However, there are still some few things that you can do to optimize loading speeds of these files.

So, let us take a look at two ways to fix this.

Hosting gtag.js locally

As mentioned earlier, hosting gtag.js locally is one method that reduces the amount of time needed to load the Analytics code.

This is a strategy that Napeza uses to improve core web vitals scores. But, since only a few site owners know about this, here is how to add it to your WordPress site.

Before Hosting the Analytics script

You need to install and activate the following:

  • MonsterInsights pro plugin. If you don’t have it, get it here.
  • Ensure that MonsterInsights’s new Performance Addon feature is enabled.

MonsterInsights is currently the #1 Google Analytics plugin for WordPress.

monsterinsights best ga plugin for wordpress

Want to Add Google Analytics?

By far MonsterInsights has been our number one Google Analytics plugin for. for WordPress

MonsterInsights offers an unconditional money back guarantee of up to 14 days.

Rating: 5 out of 5.

MonsterInsights via the performance feature. Allows you to host the gtag.js code on your server; without any need for a developer.

To use this feature, ensure that you are using MonsterInsights pro as stated above. Then in your WordPress admin menu, go to Insights >> Addons. Scroll to the bottom. On the Performance addon, toggle Add Gtag.js File Locally to blue. That’s it.

Once enabled, the Performance Addon feature will locally host and automatically fetch the latest Gtag.js file from Google every after 24hrs. This is to make sure it’s up to date. Or you can manually fetch for any updates to the file in between the automation circle.

Use an optimized Google Analytics plugin for WordPress

Other known factors that might affect your site loading speeds for users. Are your plugins, themes and other webhosting related issues.

Since Google Analytics requires inserting a Javascript code into every page and post on your site. It’s recommended to use a plugin to avoid overriding the code when you change your theme. Plus other benefits like Analytics reports within WordPress. But Google Analytics plugins for WordPress are not the same. Some plugins are database-intensive which will slow down your site and are quite not worth it.

Again, the only plugin you need for this is, MonsterInsights. The recent MonsterInsights update, version 7.18 now offers a faster script loading time for better Core Web Vitals scores.

All you need to do is install, activate and set up the plugin with your Google Analytics account.

MonsterInsights ranks as the best Google Analytics plugin for WordPress. Get it for free!

I hope you can now improve your site user experience using MonsterInsights new performance feature. You can further use the plugin to get user optimization insights and speed recommendations.

Spread the love
traffic analysis tools
.COM for just $5.98 at Namecheap

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.