How to Host gtag.js Locally in WordPress Using MonsterInsights?

If you have stumped on this post, you are probably already struggling with your site speed. So, first thing first, stop stressing as you aren’t alone here. And, secondly, let’s see how to host gtag.js on your WordPress site and boost speed.

Yes, hosting gtag.js locally is all you need to stop potential customers from leaving your site. You see, the main two factors that drive online customers are Speed and Experience. In fact, almost 80% of online shoppers desire a personalized experience, and 53% want websites to load within 3 seconds.

So, to provide a good speed and user experience to your online customers, hosting gtag.js locally is easy. Without any ado, let’s see how to host gtag.js locally on your site.

What is gtag.js?

Gtag.js is simply a set of JavaScript functions, variables, and programs that you can load on your site to track visitors’ data. Once you link your website to Google Analytics, analytics.js or gtag.js will automatically load on your site.

Gtag.js helps to track and collect the data from your site like the number of visitors, their behavior patterns on your site, etc. Using this data, you can create a personalized environment to boost your user experience.

Unfortunately, gtag.js has a downside — it can slow down your website speed. JavaScript or any other extra code can negatively impact your site speed. But at the same time, you can’t find a better solution than JavaScript to collect your websites’ visitors’ data.

So, what to do now? Since you want both speed and analytics to boost users’ experience.

The solution is simple. Just host gtag.js locally! Yep, hosting gtag.js locally won’t let Google Analytics scripting slow your website speed. So, let’s see how this process works.

Find out how to install gtag.js on WordPress with our simple guide.

Why It’s Important to Host gtag.js Locally for Site Speed?

Whenever a user searches for your website URL, the request is passed to the DNS server. The DNS is a database of all domain names that turn them into IP addresses. You can call it an online phone book.

That means every time someone searches for your web domain, a DNS lookup process begins.  A web browser takes time to complete this process and load web pages. As per YSlow, average DNS lookups take 20-120 milliseconds to complete.

This process alone is sufficient to slow your site. But when you use page performance testing tools, like Google Analytics, this runs down your site speed to the ground.

For instance, if your web server’s expiration periods are set too low or have no caching constraints. In both cases, your speed insight tool will frequently report it that will impact your site speed.

Many other things can slow your site, but these two are the prominent ones. So, that means you should stop using Google Analytics to analyze your users’ behavior on your site?

No! You simply can’t grow without Google Analytics. So, you just need to host gtag.js locally to avoid extra DNS lookup and gain full control over your file’s caching. Sounds complicated?

With the new MonsterInsights update, you can now easily host gtag.js locally on your server to improve your WordPress site speed. All you need is MonsterInsights Performance addon, and your gtag.js will be hosted locally.

How to Host gtag.js?

Using Google Analytics free edition, you can easily track up to 10 million visitors per month per site. However, if you have a large user base, you need to get Google Analytics Premium for $150,000 per year.

I know Google Analytics Premium is costly. But the good thing is that if you use it with the MonsterInsights plugin, you don’t need advanced Google Analytics features to grow online.

Plus, MonsterInsights premium packages are a lot more affordable than Google Analytics, including — Plus ($199), Pro ($399), and Agency ($799) per year.

So, let’s now check out how to boost your website speed by hosting gtag.js locally using MonsterInsights.

Install & Activate MonsterInsights

Go to your WordPress dashboard > All Plugins > Add New. Search for the MonsterInsights plugin and install it. You can start with a MonsterInsights 14 days free trial. We have a detailed guide on how to setup monsterinsights, check out for more information.

Activate Performance Addon

Before moving ahead, make sure to connect your Google Analytics accounts to MonsterInsights. Check how to install google analysis on your wordpress website. Then, activate the MonsterInsights Performance addon to modify sample rate and site pace sample rate to keep Google Analytics processing limit below.

Sample Rate here defines the proportion of users for monitoring.

Site Speed Sample Rate sets the frequency at which site speed monitoring beacons are transmitted.

To install the Performance addon, go to Insights > Addons > click the MonsterInsights Performance addition. The addon will automatically activate after installation.

Navigate to Insights > Settings > Advanced > Performance to change sample rate and site speed sample rate. There you go! Without any extra MonsterInsights adjustments, the addon is ready to operate.

Remember one thing; your site must pass the new Core Web Vitals exam for better results. It might seem that Google influences its own Core Web Vitals, but that’s not the case. Google Analytics scripting can slow down your site speed if it’s not optimized properly.

Faster Script Loading

As a result of this upgrade, the plugin’s script will now load quickly. Although the script loaded quite fast previously, with the change, MonsterInsights can now seamlessly boost Core Web Vital scores.

You can host your gtag.js script directly on your site to the Performance addon. Google Analytics features a two-hour cache period, which you can decrease by hosting locally.

All in One SEO Integration

MonsterInsights is now fully integrated with the All in One SEO plugin. This, in return, gives an extra push to script loading performance.

This new development lets you integrate AIOSEO target keywords and TruSEO scores into your Google Analytics data. This will provide you deeper insight into your users’ data, such as:

  • Which targeted keywords have brought the most users?
  • Is your content well-optimized?
  • Is there any specific post that generates high traffic?

Speed Up Your Site Speed Now

So, people, there are hundreds of reasons behind your sluggish page load speed. But if you are using Google Analytics or any other tool on your site, JavaScript is your main culprit.

Therefore, it’s always a great idea to host gtag.js locally to boost your site seamlessly. Plus, with the new MonsterInsights Performance addon, it’s not that hard to host gtag.js locally. In fact, it has become easier to speed up the SEO score of your site with AIOSEO integration.

I hope this post has helped you gain a real perspective to host gtag.js locally for better speed. So, for more blogs related to WordPress plugins, stay connected. And, don’t forget to like and share @reviewsnguides on your social media.

Leave a Reply

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