Note: For versions below 16.19.0, use a manual method for tracking SPAs.
Piwik PRO tracks single-page applications (SPAs) automatically. It records a page view with each change in a visitor’s browser history — which is like a page view in an SPA. So, all you need to do to track your SPA is make sure the tracking option is on.
To find out if SPA tracking is on, follow these steps:
- Go to Menu > Administration.
- Navigate to Sites & apps.
- On the left, select the site or app you want to work with.
- Navigate to Data collection.
- Scroll down until you see SPA.
- Turn on Track page views in a single-page application.
Note: If you notice that a page view is recorded twice on a page load, turn on this setting: Tag Manager > Piwik PRO tag (tracking code) > Other options > Track page views manually.
Tip: For more advanced setups, we recommend using our tracking libraries.
- All done! You’ll see recorded page views in reports.
A traditional website (multi-page application) works in this way: every time a visitor goes from one page to another, the new page reloads in the visitor’s browser. An SPA (single-page application) loads at the beginning of the visit, then fetches the necessary data from the server as the visitor moves through the website, without the need for a page reload.
A multi-page application is easy to track because the tracking code loads each time a visitor visits a new page. A single-page application is more difficult to track because, in most cases, the tracking code loads just once, and doesn’t do so again as a visitor moves through the website.
Piwik PRO uses a mechanism that notices when a visitor moves to a new page in an SPA (the browser history changes) and sends that information to reports. It all happens automatically.