Skip to content

SPA Mode

Single Page Applications handle navigation client-side without full page reloads. The library has built-in SPA support to re-detect page types on route changes.

View as Markdown llms.txt

Set spa: true in your configuration:

new Initializer({
// ...required fields
spa: true,
pageMap: {
/* your page map */
},
});

When enabled, the Page class:

  1. Listens for URL changes via popstate events
  2. Intercepts pushState and replaceState calls
  3. Re-runs page detection on every navigation
  4. Sends a new tracking event for each detected page

You don’t need to manually call tracking events on route change — the library handles it automatically.

ScenarioUse spa: true
React / Vue / Angular with client-side routingYes
Next.js with full page reloads (<a> tags)No
Next.js App Router with Link componentYes
Traditional multi-page siteNo
Hybrid (some pages reload, some don’t)Yes

You can skip SPA mode and call events manually in your router:

router.afterEach(to => {
if (to.name === 'product') {
events.ProductView({ productId: to.params.id });
} else {
events.PageView({ category: to.meta.category });
}
});

When your SPA unmounts (e.g., micro-frontend), call destroy() to remove listeners:

initializer.destroy();