Tracking Page Views in SPAs and the WordPress Interactivity API with WP Statistics

Modern WordPress sites often behave like Single-Page Applications (SPAs), where navigation happens without a full page reload. This includes JavaScript page-transition libraries (such as Barba.js, PJAX, Turbolinks, and Swup) as well as the WordPress Interactivity API, which dynamically updates content and URLs on the client side.

Because WP Statistics traditionally relies on full page loads, SPA navigation can prevent accurate page-view tracking unless explicitly handled.
This document explains how to enable SPA-aware page tracking in WP Statistics by:

Required: Enable SPA URL Resolution in WP Statistics

When navigation happens without a full page reload, WP Statistics must be told how to resolve the new URL that results from client-side routing (History API, Interactivity API updates, JS transitions, etc.).

To enable this behavior, you must add the following filter to your theme’s functions.php file or a custom plugin:

/**
 * Enable WP Statistics SPA URL resolution
 *
 * Required for tracking page views when navigation occurs
 * without a full page reload (SPA behavior).
 */
add_filter('wp_statistics_resolve_page_from_uri', function ($pageUri) {
	return \WP_Statistics\Service\Analytics\UrlResolver::resolve($pageUri);
});

Why this hook is required

Without this hook, page views triggered by SPA navigation may be missing, incorrect, or unresolved.

Let’s get started
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.