CAOS (Complete Analytics Optimization Suite)

[CAOS] allows you to further optimize your sites’ usage of Google Analytics.

Cody Arsenault (KeyCDN)

The Complete Analytics Optimization Suite (CAOS, Formerly Known As “Host Analytics.js Local”) is a cool plugin for WordPress. It allows you to fine-tune your websites’ performance by enabling you to self-host Google’s Analytics Javascript file. Optimize analytics by simply entering your tracking ID and let the plugin do the rest! It places the necessary code in your theme’s header (or footer) and downloads the analytics.js or gtag.js file to your server. Then the file is updated automagically using WordPress’ integrated wp_cron() function.

How to Optimize Analytics in WordPress?

I get a lot of questions regarding the optimization of WordPress websites. Especially when people use Google’s own Pagespeed Insights they never seem to be able to get a perfect score. How do you leverage browser cache when Google’s very own Analytics.js has it’s expiry time set to 2 hours? How do you minimize DNS requests when Google advices you to copy their tracking code, linking to an externally hosted Javascript file?

If that isn’t bad enough already, Google’s advice is to avoid hosting the JavaScript file locally. And why? To ensure you get access to new features and product updates.

Why should I host analytics.js locally?

The Complete Analytics Optimization Suite for WordPress gives you the best of both worlds. After activation it automagically downloads the latest version of analytics.js from Google’s servers, places the necessary tracking code in your WordPress theme’s header and keeps the local Javascript file up-to-date using an adjusted version of Matthew Horne’s update analytics script and wp_cron(). This way you can minimize DNS requests, leverage browser cache, track your visitors and still follow Google’s recommendation to use the latest features and product updates.

Since version 1.30 the plugin supports more ways to optimize Analytics in WordPress. By loading your tracking code in the footer of your theme, you can eliminate render-blocking Javascript and CSS in above-the-fold content. The usage of adjusted bounce rate allows you to fine-tune your bounce rate for more realistic results.

Configure CAOS in WordPress

The basic configuration for CAOS is very easy. The basic settings are required for proper functioning of the plugin.

Basic Settings

Configuration of CAOS’ Basic Settings is required for propery functioning of the plugin.

Enter your Google Analytics Tracking ID. For development/testing purposes, you can decide whether you want to Track Logged In Administrators. This option should be disabled on production environments!

For GDPR Compliance, decide when you want to allow tracking

Choose your Snippet Type:

  • Google Analytics’ Default tracking code is loaded render blocking, providing the most accurate statistics and is suitable in most situations, but…
  • For peak performance choose the Asynchronous tracking code. This tracking code is loaded non-render blocking, providing the best user experience without sacrificing on Google Analytics’ feature set.
  • Are you a light-weight Google Analytics user i.e. you only care about Pageviews/Events? Enable Minimal Analytics (by Minimal Analytics) to use only the code you need (and nothing more).
    • This also eliminates the Unused JS notice in Google PageSpeed Insights for analytics.js/gtag.js, because the entire library isn’t loaded anymore! Cha-ching!

For some countries (e.g. Germany) it’s required to anonymize IP addresses of your visitors to comply with GDPR laws. Enable this option if your server is located in such a country, or you expect visitors from such countries.

Decide where you want to load the generated tracking code

  • Choose ‘Header’ for best performance. Because the tracking code is loaded before the rest of the page, you’re sure that all visitor data can be registered by Google Analytics,
  • Choose ‘Footer’ (not recommended). This used to be necessary, because in some cases Google Pagespeed would throw an ‘eliminate render-block Javascript in above-the-fold content’-notice. This would cause the snippet to be loaded after everything else,
  • Choose ‘Add manually’ to maximize compatibility. If your theme or another plugin is preventing CAOS from adding the tracking code automatically, choose this option and copy the generated tracking code from the field underneath.

If you haven’t already, remove any other previously installed Google Analytics plugins or manually inserted tracking code from your WordPress installation.

Advanced Settings

The Advanced Settings provide easy to tweak advanced features of Google Analytics.

To tailor CAOS to your needs you can use the Advanced Settings. None of these are required settings and are strictly meant for advanced (WordPress) users.

When Snippet Type is set to Minimal Analytics, this tab is hidden, because none of these settings will have any effect.

Notice: if you have no idea what any of the below options mean, just leave them to their default values as they could seriously alter your Google Analytics reports.
  • CAOS does not offer an Analytics Dashboard for WordPress or Enhanced Commerce tags/events. To implement these features, CAOS is fully compatible with Monster Insights, Analytify, WooCommerce GA Integration and ExactMetrics.
  • Choose to download analytics.js or gtag.js. Need help choosing?
  • If you use a CDN you can choose to serve analytics.js/gtag.js from your CDN by providing the base URL (without https:// or https://)
    • When using Stealth Mode the ‘collect’ calls will still be sent through your own domain, because CDN (usually) don’t run PHP.
  • Set a ‘Cookie Expiry Period‘ if you want to let the Google Analytics-cookie expire after a set number of days.
  • Change the Enqueue Order of the script if you notice that other JavaScript’s might be interfering with the execution of your Google Analytics tracking-code. I suggest leaving this to the default (10), to assure the script being triggered before everything else.
  • Disable all Display Features if you want to force disable any remarketing and advertising purposes set in your Google Analytics Dashboard.


Enhance the functionality of CAOS and analytics.js to aid in measuring user interaction using Extensions.

CAOS allows developers to easily extend its functionality using extensions. Out-of-the-box CAOS offers a few extensions which can easily be enabled under the Extensions tab:

  • When Stealth Mode is enabled, you can alter Google Analytics’ Plugin Handling to suit your needs. Plugins, e.g. ec.js or linkid.js can be served faster if your server supports CAOS’ experimental mode.
  • Enable Stealth Mode to bypass Ad Blockers and secure Google Analytics’ accuracy.
  • Not sure if you need Stealth Mode? Enable Track Ad Blockers to gain insights into your visitors’ Ad Blocker usage.
    • Enabling this option registers whether a visitor was using an Ad Blocker or not. It does not send information (pageviews, etc.) about visitors using Ad Blockers to Google Analytics. I.e. it’s not the same as Stealth Mode.
When Track Ad Blockers is enabled in CAOS, results can be found in Behavior > Events > Top Events > Event Category: Tracking > Event Action: Ad Blocker.
  • If you want to find out when users click a link to leave your site, you can enable Capture Outbound Links. This does not work when Stealth Mode is enabled.
  • You can set an Adjusted Bounce Rate if you want to filter out e.g. visitors that close their browser window within a set number of seconds. This can be useful if you offer short snippets of information on your blog that don’t trigger a user to continue reading other pages, such as StackOverflow.
  • Improve the accuracy of your In-Page Analytics by enabling Enhanced Link Attribution: automatically differentiate between multiple links to the same URL on a single page by using link element IDs.
  • Allow A/B testing by enabling Google Optimize Integration.


Analytics.js/gtag.js doesn’t exist or hasn’t been updated for more than two days.

CAOS throws this notice if analytics.js or gtag.js (depending on your settings) does not exist, or hasn’t been updated for a while.

First off, check if the file exists. If not, trigger a manual update from within CAOS’ settings screen.

If it does exist, then it means that the scheduled update wasn’t able to run. This usually happens on low traffic sites (< 100 visitors/daily), because WP cron wasn’t able to properly finish its schedule.

Is your site a low traffic site? There’s no shame in that :-), but it probably means that not just CAOS’ scheduled jobs, but many of WordPress cronjobs aren’t able to run properly.

To work around this, you need to setup a so called real cronjob.

Replace WP’s Cron with a Real Cronjob

For this you’ll need SSH access to your server. If you don’t have this, contact your hosting provider and ask them to replace WordPress’ pseudo cron with a real cronjob.

  • First you need to disable WordPress’ pseudo cron. To do this go to wp-config.php (located in the root of your WordPress install and add the following line right before the line that reads /* That's all, stop editing! Happy blogging. */:
    • define('DISABLE_WP_CRON', true);
  • Then, open up a terminal, login to your server and run crontab- e. This will open up your cron editor. Then add the following:
    • */5 * * * * wget -q -O - >/dev/null 2>&1

That’s it. From now on, WordPress’ cron will run every 5 minutes.

Further Reading


Click here to go to the WordPress Repository and download Complete Analytics Optimization Suite