← All resources Guide

WP Rocket and server-side tracking: what to check

WP Rocket makes a WordPress site faster by caching pages and rewriting how scripts load. Most of that is good for tracking too: a faster page loses fewer visitors before the tag fires. One setting is not: Delay JavaScript execution holds scripts back until the visitor clicks, scrolls or types. A visitor who reads a page and leaves is then never measured.

With version 0.10.3 or later of the Measurebase WordPress plugin, WP Rocket leaves all of your tracking alone without you typing anything. This guide covers what the plugin does by itself, when to clear WP Rocket's cache, how to check the result, and what to do on an older version or with a snippet pasted by hand.

Plugin 0.10.3 or later? Nothing to type in WP Rocket.

The plugin keeps WP Rocket away from all of its scripts by itself. Check the version under Plugins. Only on an older version, or with a snippet pasted by hand, do you add three lines yourself (step 1).

What WP Rocket does to tracking scripts

Four WP Rocket features touch scripts:

The first three are harmless for tracking as long as the tracking script itself is left alone. The fourth changes what you measure: page views of visitors who never interact go missing, and product views arrive late or not at all.

What the Measurebase plugin excludes for you

The plugin adds its own entries to WP Rocket's exclusion lists for minify, combine, defer and delay. Nothing needs to be typed in WP Rocket for these, and the entries do not show up in WP Rocket's own settings fields.

Other plugins' scripts stay delayed. The plugin marks each script it writes into the page with a short comment, /*mb-nodelay*/, and excludes that marker, not everything that mentions dataLayer.

The plugin can only add them while it is connected to Measurebase, because the markers come from the connection. If the Connection tab says the site is not connected, connect it first.

1Update the plugin to 0.10.3 or later

Under Plugins, update Measurebase if it shows a version before 0.10.3. That is all: there is nothing to add in WP Rocket. Go on to step 2.

Can't update yet? Add three lines by hand.

Before 0.10.3, WP Rocket delays the plugin's data layer: the start line next to the tracking script and the dataLayer.push lines for view_item, view_item_list, purchase and the other shop events. In WP Rocket go to Settings › WP Rocket › File Optimization. Under Delay JavaScript execution, add these lines to Excluded JavaScript Files, one per line:

dataLayer
measurebase-events
MeasurebaseCfg

dataLayer matches the start line and every push, measurebase-events is the plugin's script for clicks, cart changes and forms, and MeasurebaseCfg is that script's settings. Type them exactly like this: WP Rocket reads each line as a pattern, so leave out quotes and brackets. Save; WP Rocket clears its cache by itself.

The events script needs jQuery. If jQuery is delayed as well, the script waits for it and starts at the first interaction. Clicks and form submits are interactions themselves, so nothing gets lost.

2Clear the cache after every tracking change

The cache keeps serving the old snippet until it is cleared. Clear it in WP Rocket › Dashboard › Clear and preload cache after:

3Check that it works

Open a product page in a private window and view the page source. The tracking script, its start line and the dataLayer.push lines must be plain <script> tags. A tag that reads type="rocketlazyloadscript" is still delayed.

Then open preview in Tag Manager and load the page without clicking or scrolling. page_view and view_item should arrive straight away. Finally, run a tracking audit in the Measurebase dashboard: it loads your pages like a visitor and reports when the container does not load through your tagging host.

Logged-in customers stay out of the cache

For a logged-in customer the plugin adds their user ID, whether they are a new or returning customer, and a hashed email address to the page, so GA4 and Google Ads can recognise them. A cache that shares pages between logged-in users would hand those values to the next customer.

Since version 0.10.3 the plugin tells WP Rocket, LiteSpeed Cache, the other cache plugins and CDNs not to store exactly those pages. Pages for visitors who are not logged in stay cached as usual. There is nothing to set for this. On an older plugin version, do not use a cache that shares pages between logged-in users.

Cart, checkout and server-side purchases

WP Rocket never caches the cart, checkout and order confirmation pages of WooCommerce, so the purchase push and the details the plugin keeps for its server-side backup stay exactly as they are. That backup is sent from your web server to your tagging server after payment, without the browser, so no browser setting can delay it.

A tracking snippet pasted by hand

Without the plugin, nothing is excluded automatically. Add the same lines as in step 1, plus your tagging host and the file name of your tracking script, to three places in File Optimization: Excluded JavaScript Files under Minify, under Load JavaScript deferred and under Delay JavaScript execution. You find both values in the snippet itself, for example mb.example.com and AbCd123.js.

Frequently asked questions

Does excluding these scripts make the site slower?

Hardly. The tracking script loads asynchronously, so it never blocks the page, and the data layer lines are a few hundred bytes of text. Everything else WP Rocket delays stays delayed.

Does Remove unused CSS affect tracking?

No. It only works on stylesheets, and tracking does not depend on CSS.

Does the WP Rocket CDN setting change the tracking script?

No. The CDN setting rewrites the addresses of your theme, plugin and media files. The tracking script loads from your tagging host or your Same-Origin path, which the CDN leaves alone.

I use LiteSpeed Cache or Autoptimize instead. Does the same apply?

Yes. The plugin adds the same exclusions to LiteSpeed Cache and Autoptimize, the data layer included from version 0.10.3. On an older version, exclude dataLayer, measurebase-events and MeasurebaseCfg there the same way.

Why did my page views drop after switching on WP Rocket?

Almost always Delay JavaScript execution on a plugin version before 0.10.3, or with a snippet pasted by hand: visitors who leave without clicking or scrolling are no longer counted. Update the plugin or add the exclusions from step 1, clear the cache and compare the next full day.

Continue reading

Ready to improve your tracking setup?

Start free, no credit card required. Live in about 15 minutes.

Start free