How can I track a single-page application?
There are two main design patterns for websites: a multi-page application and a single-page application (also called SPA). The first one works traditionally — every time a visitor moves from a page to a page, the browser asks the server to retrieve the new page. The second one loads at the beginning of the visit, and the browser doesn’t call the server when a visitor moves through a website.
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.
So if we want to track a single-page application, we need to use a mechanism that will notice when a visitor changes a page and will send that information to Piwik PRO. Such piece of information is called a virtual page view.
A virtual page is not a real page, but it appears in reports as an actual page — it has a page URL and a page title. It can be set to track interaction with an element on your website. For example, a virtual page view may be counted when a visitor clicks a link.
To set up tracking with a virtual page view, follow these steps:
- Create the Piwik PRO virtual page view tag.
- Create a trigger for the tag. For example, a click trigger.
- After the tag and trigger are set up, data will appear in the page report (Menu > Analytics (new) > Reports > Pages).
Tip: In Analytics (classic), you can find a virtual page in the page report (Menu > Analytics > Actions > Pages) or in the page title report (Menu > Analytics > Actions > Page titles).
Note: From version 12.0.0 single-page application tracking will be set with a dedicated tag in Tag Manager.