Google Tracking Add-On
When you use Google Analytics on your site, those files which are hosted from Google's own servers, will be flagged by various performance testing tools with a "Leverage browser caching" warning for their short expiration:
Since you cannot apply browser caching on files you do not host, the solution is to host these files locally, i.e. from your own domain, or from your CDN, so that better browser caching rules can be applied. The Google Tracking Add-on in WP Rocket provides this solution.
Heads up! If your Google Analytics script is installed using Google Tag Manager, this add-on will not work. This Add-on currently only works with the tracking code taken from a Google Analytics account.
We currently target these specific files:
Go to the Add-ons tab in WP Rocket and simply toggle the Google Tracking Add-on to on:
Now when you run a speed test, you will no longer see the "leverage browser cache" warning on those particular files.
If you have activated the CDN option in WP Rocket, the local Google tracking files will automatically be served from your CDN.
Heads up! If you're using Google Analytics as the verification method for your Google Search Console account, GSC will not detect the local script. So you should use a different verification method.
Behind the scenes
When you turn the option on, it will immediately simulate a visit to the remote Google Analytics file (https://www.google-analytics.com/analytics.js). This will generate the local version of the file before a visitor goes to your website.
For Global Site Tag, the local file will be generated when WP Rocket creates a new cache file for a page.
The local files will be stored in the
- https://www.google-analytics.com/analytics.js will be saved as
- https://www.googletagmanager.com/gtag/js will be saved as
busting/1/(on multisite the folder number will correspond to the number of the site)
The Tag Manager file will be automatically excluded from Combine JS for compatibility.
There is a cron job that will update the Analytics local cache every week, to ensure it’s up to date if the file has not been cleared before. The version of the local file will update when a change in the contents of the original file is detected.
Plugins that work well with the Google Tracking Add-On
Please note that WP Rocket's Google Tracking Add-on doesn't replace or manage the Google Analytics integration in your website. You'll still need to use a plugin for the integration, some customers may use custom or theme's integration too.
This add-on's final goal is to store the tracking files locally (in your server) and add the right browser cache rules to them.