How to track a single-page application (SPA)

Analytics

Avaliable from 16.19.0

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:

  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 from tracking on other types of sites

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.

Was this article helpful?

Technical support

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

Back to help center