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 Content
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
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:
Google Analytics Tracking ID – Enter your tracking id here.
Allow Tracking – Always
Snippet Type – Default
Position of tracking – code: Header
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 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
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.
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 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.
Perfmatters 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
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 Monsterinsights plugin then turn this ON, otherwise turn this OFF.
5. Flying Analytics
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
Google Analytics Tracking ID – Enter your Tracking id here.
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 100% Score.
If you have any queries on WordPress, then feel free to comment below.
A guy blogging for the last 3 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.