Hosting Google Analytics locally can help speed up your site by reducing extra DNS lookups and resolving the “leverage browser caching” issue from their script.
Ironically Google’s own script throws a warning about caching, but this is because they have their HTTP caching header expiration set really short. When you host it yourself, your own CDN or server’s HTTP caching headers will automatically be applied. In other words, you have full control over the caching of the script.
Hosting Google Analytics locally and serving the script from your own CDN or server also lets you take advantage of a single HTTP/2 connection.
Note: This is not officially supported by Google, but we have been doing this for years without any issues.
Enable Local Analytics
To enable Local Analytics, click into the Perfmatters plugin in your dashboard and then on the “Google Analytics” tab. To work correctly, you will need to at least input your tracking ID. Then select “Enable Local Analytics” and save the changes. Make sure to also clear your site’s cache.
Our plugin uses a CRON job that runs once daily to grab the latest copy of the latest Google Analytics script from their servers.
Important: Don’t use this feature with other Google Analytics plugins, otherwise you might load the script twice which could skew your data.
Input your Google Analytics tracking ID. If you don’t know your tracking ID you can find it here.
Tracking code position
Load your analytics script in the header (default) or footer of your site.
Google Analytics advises you load the script in the header of your site. But this is simply to prevent any issues if someone aborts loading the page (in rare cases it might not fire). If you have a fast loading site, loading GA in footer is completely fine and won’t impact your page view counts. In fact, we load GA in the footer on all of our sites.
Disable Display Features
Disable remarketing and advertising which generates a 2nd HTTP request.
Hide your IP to comply with privacy restrictions in some countries.
Track logged-in admins
Include logged-in WordPress admins in your Google Analytics reports.
Important: If you leave this off, you won’t see the analytics script when you’re logged in as an administrator on your site. But you can confirm your script is running by checking for it when you’re logged out or in incognito mode.
Adjusted bounce rate
Set a timeout limit in seconds to better evaluate the quality of your traffic. (1-100) We personally use 30 seconds. Read more about why you might want to use adjusted bounce rate.
MonsterInsights is a popular plugin used by over 2 million users to add Google Analytics to WordPress. You can now use MonsterInsights along with Perfmatters. It enables you to host the Google Analytics script (
analytics.js) locally while still being able to take advantage of the awesome MonserInsights features like GA event tracking.
It’s important to note that when the MonsterInsights option is enabled, all additional Google Analytics settings are then handled by their plugin, not Perfmatters. For example, excluding admin users from being tracked, anonymize IP addresses, your tracking ID, all need to be set in MonserInsights.
You still need to toggle on the “Enable Local Analytics” option to use this integration. When MonsterInsights is enabled, Google Analytics in Perfmatters is automatically disabled, so you don’t need to worry about the script loading twice.
When you are hosting your analytics locally, Google’s Tag Assistant Chrome extension won’t pick up analytics running on your site. This is completely normal, as they are only looking for it on their servers.
An easy way to confirm that Google Analytics is working is to open up a browser in Incognito Mode and visit your site. Look at the “Realtime” view in Google Analytics, and you should see yourself show up.