Take your business to next level
Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.
If your WordPress site uses a JavaScript-based page-transition library (for example Barba.js) which updates content without full page reloads, then the normal tracking of WP Statistics may only run on the initial load. This guide shows how to ensure WP Statistics continues to track page-views correctly after JS page transitions.
When using Barba.js (or similar), the browser may not trigger a full document load on each “page” navigation. As a result:
• Confirm WP Statistics’ tracker.js is injected in a way that persists across transitions (or re-injected after each transition).
• If your theme/minifier/optimizer caches or defers JS, exclude tracker.js from being modified.
• (Optional) See our doc “How to Exclude WP Statistics tracker.js from Caching & Minification”.
In your Barba.js configuration, use the afterEnter (or equivalent) event to manually trigger WP Statistics tracking of the “new page”.
barba.init({
transitions: [{
name: 'default-transition',
afterEnter({ next }) {
if (typeof wpStatisticsTracker === 'object') {
wpStatisticsTracker.trackPageView(next.url);
}
}
}]
});
Replace wpStatisticsTracker.trackPageView with the actual function name your setup uses.
If WP Statistics provides a JS API or custom event (check your version) use that instead.
To avoid counting the same initial load twice (once by default, once via your custom trigger), you might disable the default auto-track on document.ready and rely only on your custom trigger.
Alternatively, check the URL change (via Barba.js) before firing the custom event.
After implementing the script, clear any server/plugin caching, disable/minify or exclude tracker.js, then test the transitions and inspect WP Statistics → Visitors or Hits report to confirm each transition is recorded.
Use browser DevTools (Network tab + Console) to verify the tracking request fires on each transition.
tracker.js loads and your handler runs during Barba.js afterEnter.tracker.js is excluded from being altered or deferred so that it executes correctly during transitions.• This guide assumes WP Statistics version 14.x (with client-side tracking) or above.
• Works with Barba.js version 2+ (or equivalent) using afterEnter.
• If you use any other JS page-transition library (e.g., PJAX, Turbolinks) adapt the lifecycle hook accordingly (e.g., onContentReplaced, pjax:end, etc).
By integrating WP Statistics’ tracking into your JS-based page transition lifecycle, you ensure accurate analytics even when full page reloads don’t happen. Follow the steps above so every “virtual page” view is counted correctly.
Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.