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.
Enabling SPA Mode
Section titled “Enabling SPA Mode”Set spa: true in your configuration:
new Initializer({ // ...required fields spa: true, pageMap: { /* your page map */ },});How It Works
Section titled “How It Works”When enabled, the Page class:
- Listens for URL changes via
popstateevents - Intercepts
pushStateandreplaceStatecalls - Re-runs page detection on every navigation
- 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.
When to Use
Section titled “When to Use”| Scenario | Use spa: true |
|---|---|
| React / Vue / Angular with client-side routing | Yes |
Next.js with full page reloads (<a> tags) | No |
Next.js App Router with Link component | Yes |
| Traditional multi-page site | No |
| Hybrid (some pages reload, some don’t) | Yes |
Manual Alternative
Section titled “Manual Alternative”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 }); }});Cleanup
Section titled “Cleanup”When your SPA unmounts (e.g., micro-frontend), call destroy() to remove listeners:
initializer.destroy();