How To Host Google Analytics Locally In WordPress (2022)| Fix Your Leverage Browser Caching Issue In Gtmetrix

You are currently viewing How To Host Google Analytics Locally In WordPress (2022)| Fix Your Leverage Browser Caching Issue In Gtmetrix

In this tutorial, you will learn how you can host your Google Analytics code locally in WordPress & Improve your Gtmetrix, Pingdom, Google page speed score.

You might see a leverage browser caching issue on your Gtmetrix report if you are using Google Analytics (Or Google Tag Manager code).

To fix this issue, we can host the Google Analytics tracking code locally. So, in this post, I will show you how to host your Google analytics code locally on your WordPress website.

So, let’s get started.

Table of Contents

How To Fix Google Analytics Leverage Browser Caching Warning In WordPress

I have shared 5 plugins that will help you to fix your Google Analytics leverage browser caching warning in WordPress.

1. CAOS | Host Google Analytics Locally

caos plugin to host google analytics locally

There are many plugins to host Google Analytics code locally. I use CAOS | Host Google Analytics Locally plugin which is a free plugin & has great reviews.

CAOS Plugin Setting:

Basic Settings:

caos host google analytics locally plugin setting

Google Analytics Tracking ID – Enter your tracking id here.

Allow Tracking – Always

Snippet Type – Default

Position of tracking – code: Header

Advanced Settings:

best caos plugin setting

Enable Compatibility Mode: If you are using any other Google Analytics plugin like WooCommerce Google Analytics integration, GADP for WP, GAD for WP, or GADP for WP by monster insights then you can link that plugin with CAOS. Choose NONE if you are not using any other GA plugin.

Which File to Download – Analytics.js 

Save Analytics.js to  – Here you can change the path where the analytics are cached inside the WordPress directory. This is up to you, you can change the path or leave it as it is.

Serve From a CDN – If you are using any CDN, then enter your CDN URL here.

Enable Preconnect – Enable. This will speed up the requests to the servers.

Capture Outbound Links – Enable this. Capturing outbound links will help you in retargeting ads.

Cookie Expiry Period (days) –   Here you can set the cookie expiry period. 

Change Enqueue order – Let it be default.

Disable All display features functionality – disable this option 

Anonymize IP – Enable this, as it is required by law in some countries (GDPR Compliance) which will prevent the collection of user’s data.

Track Logged In Administrators –  Disable this option.

Remove Setting at Uninstall –  Enable this option.

2. Swift Performance Lite

leverage browser caching for google analytics

Swift performance lite is a free cache plugin (also has a pro version) & has an option to host Google Analytics locally. All you have to do is go to the tools > swift performance lite setting > General > Google Analytics.

swift performance lite setting for google analytics

Bypass Google Analytics – On.

Tracking ID – Here you have to paste your Google Analytics tracking UA ID.

Anonymize IP – On.

3. WP Rocket

wp rocket for speed optimization

WP Rocket is a premium plugin for WordPress speed optimization. You don’t have to install 6 extra plugins as this plugin covers minification, database cleaning, hosting google fonts, image optimization, etc. So, If you are using WP Rocket then you can host analytics locally. All you have to do is to go to the Add-ons tab and Turn ON Google analytics.

wp rocket google analytics setting page

4. Perfmatters

perfmatters google analytics

 is a premium plugin by Kinsta which also helps in improving the WordPress website by disabling plugins & unnecessary WordPress features. This plugin also has a feature to host your Google Analytics code locally.

Install and activate this plugin. Then go to the settings > Perfmatters > Google Analytics.

perfmatters settings

Enable Local Analytics – On.

Tracking ID – Enter your tracking id here.

Tracking Code Position – Choose Header.

Disable Display Features – OFF.

Anonymize IP – On.

Tracking Logged In Admins – OFF.

Use Monsterinsights – If you are using the Monsterinsights plugin then turn this ON, otherwise turn this OFF.  

5. Flying Analytics

leverage browser caching google tag manager in wordpress

Flying Analytics is another lightweight plugin that also helps you to host your analytics code locally.

Install and activate this plugin.

Next, Go to the settings > flying analytics

flying analytics setting

Google Analytics Tracking ID – Enter your Tracking id here.

Javascript method – This plugin offers 4 types of js methods to choose from.

flying analytics plugin

Disable for logged-in Admins – Check this box.


You can choose any plugin mentioned above to host the Google Analytics code locally in WordPress. It is a great way to improve your GTmetrix, Page Speed Score, and Pindom score and fix your leverage browser caching warning.

Also, check out my blog on how to improve your WordPress website speed with a 100% Score.

If you have any queries on WordPress, then feel free to comment below.

Best Black Friday Web Hosting Deals

A2 Hosting

Starting At $2.99/month

cloudways hosting review 2020

Cloudways Hosting

Starting At $10/month

black friday web hosting deals

WPX Hosting

Starting At $20.83/month

Sandip Maheshwari

A guy blogging for the last 4 years, I am a guy who loves to write about SEO, social media and affiliate marketing. An avid cricket fan, die-hard fan of Silicon valley the series. I love to blog in my free time to share my knowledge with people around the world.

This Post Has 2 Comments

  1. Marcus

    Following your tutorial i have hosted my Google analytics code locally using CAOS plugin. Thanks for sharing. Is there any way to host Google Font locally?

    1. Sandip

      Glad you liked it. Yes, you can also host your Google Font locally. I have written a blog post on this, see my speed optimization sidebar.

Leave a Reply

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