Page caches and JavaScript optimisers can break analytics by delaying, merging or caching scripts. Opti-Behavior handles the common ones automatically.
| Plugin | Handled automatically |
|---|---|
| WP Rocket | JS combine, delay and defer exclusions, A/B cache-vary cookie |
| LiteSpeed Cache | JS combine and defer exclusions, A/B vary cookie |
| W3 Total Cache | JS minification of the tracker |
| Autoptimize / Breeze | JS aggregation |
| Perfmatters | Delay, defer and minify JS |
| WP Super Cache, Hummingbird, SG Optimizer and others | Standard no-optimise attributes |
What Opti-Behavior does #
- Trackers are already minified and loaded with
defer, so optimisers have nothing to gain by touching them. - Tracker URLs change with each release, so caches and CDNs refresh them after an update.
- When a cached page carries an old security token, the tracker refreshes it and sends the data again.
- A/B tests register the
opti_ab_vcookie so each variant is cached separately. - If a tracker seems silently blocked, the Setup check and an admin notice tell you, naming the likely plugin.
Manual exclusion (other optimisers) #
- Open your optimiser’s “exclude from delay / combine” setting.
- Add
opti-behavior,optiBehavior,OptiBehavior,opti_behaviorand_obq(exact case). - Purge the cache and reload a page.
Why A/B tests need a cache-vary cookie #
When a visitor is assigned a variant, a page cached for one variant must never be served to a visitor of another. The companion cookie opti_ab_v is registered automatically with WP Rocket and LiteSpeed so each variant has its own cached copy.
Troubleshooting #
- No new sessions after enabling a cache – the page may be served as static HTML without the tracker: purge and add the exclusion.
- Same A/B variant for everyone – your cache or CDN ignores
opti_ab_v. - Stale dashboard numbers – object cache or edge cache; purge and wait for the next cycle.
Manual exclusion strings #
opti-behavior matches the tracker files. optiBehavior, OptiBehavior (Pro), opti_behavior and _obq match their inline configuration. Type them with this exact case: some optimisers are case-sensitive.
More questions #
Do I need to exclude anything by default? #
No, for the optimisers listed above.
Cloudflare APO or another edge cache? #
Supported. Purge after updates; for A/B tests, the edge cache must vary on the opti_ab_v cookie.
Expected result #
After purging, pages load the trackers and new visits appear; A/B variants differ between visitors.
FAQ #
After updating, tracking stopped. #
Purge the page cache and CDN once.
Does a CDN break tracking? #
No, as long as it forwards cookies for A/B test pages.