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 of the browser history state – which is like a page view in a SPA. So all you need to do to track your SPA is check if the tracking option is turned on.
To check if your SPA tracking is turned on, follow the 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.
How tracking SPAs is different than other sites
A traditional website (multi-page application) works in this way: every time a visitor goes from a page to a page, the page reloads in the visitor’s browser. A SPA (single-page application) loads at the beginning of the visit, and then dynamically gets the 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 changes a page. A single-page application is more difficult to track because, in most cases, the tracking code loads one time and doesn’t load again when a visitor explores the website.
Piwik PRO uses a mechanism that notices when a visitor changes a page in SPA (the browser history state changes) and sends that information to reports. It all works automatically.