Hosting Google Analytics locally can help speed up your site by reducing extra DNS lookups and resolve the “leverage browser caching” issue from their script. It also allows you to load the analytics script from your own CDN which can help 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 (currently in beta), 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.
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 and anonymize IP addresses need to be set in MonserInsights.