How To Host Google Analytics Locally on WordPress Site?

Share this post -

Core Web Vitals update has already been rolled out by Google. This update is bad for websites that load slow & good for fast-loading sites.

If you are looking for some simple ways to speed up your WordPress site, you can take a look at this article. These might help you to achieve a good score in terms of speed & web vitals.

Now, another thing that is recommended to speed up the site is reducing external requests. This also includes the popular Google Analytics. Really?

Yes. Google analytics is important to know your visitors but it also adds an external request that makes your website slow. So, how can you tackle this problem?


Host Google Analytics Locally

Host google analytics locally

The best thing you can do is to host the javascript file locally. This method includes hosting the gtag.js file on your web hosting server. This will eliminate the external request.

Whenever you run an analysis of your website on Google Pagespeed Insights, Pingdom, or GTMetrix, it’ll tell you to leverage browser cache when you’re using Google Analytics. Because Google has set the cache expiry time to 2 hours.

This method will get you a higher score on Pagespeed and Pingdom and make your website load faster because the user’s browser doesn’t have to make a roundtrip to download the file from Google’s external server.


How To Host gtag.js Locally?

If you are on WordPress, hosting the Google analytics javascript file is simple. You can achieve this by using the MonsterInsights plugin. It is also one of the best analytics plugins for WordPress.

MonsterInsights has a performance addon. It includes the option to host your gtag.js script locally on your server. It will also automatically fetch the latest gtag.js file from Google every 24hrs to make sure it’s up to date.

MonsterInsights performance addon

Besides hosting the file locally, the plugin also provides a ton of features like reports based on audience, behavior, content, eCommerce, various tracking methods to get the most of your analytics.

If you don’t want these additional features & just want to host the gtag.js locally, you can try installing this plugin – CAOS | Host Google Analytics Locally. Either way, you can speed up your site to some extent.


Also Read