How to track a single-page application (SPA)

Avaliable from 16.19.0

Analytics

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:

  1. Go to Menu > Administration.
  2. Navigate to Sites & apps.
  3. On the left, select the site or app you want to work with.
  4. Navigate to Data collection.
  5. Scroll down until you see SPA.
  6. Turn on Track page views in a single-page application.
    Single-page application (SPA) tracking in Piwik PRO

    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.

  7. All done! You’ll see recorded page views in reports.
    Single-page application (SPA) tracking in Piwik PRO

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.

Was this article helpful?

Technical support

If you still have some questions, visit our community.
There’s always someone ready to help!

Back to help center