Skip to main content
TayStack

Single-page apps

How the TayStack script records route changes in single-page apps, and what it does not track.

How route changes are tracked

You do not need to call anything. The script sends a pageview when it starts, and then watches the browser History API:

  • It wraps history.pushState and history.replaceState, and after either call it sends a pageview.
  • It listens for popstate (the back and forward buttons) and does the same.
  • The pageview is sent just after the change, so it records the new path.

Routers that navigate with the History API, which is the usual case, are covered without any framework-specific code. This has not been tested with every framework.

Rules

  • A pageview is sent only when the path or query string differs from the last one sent. Repeating the same URL sends nothing.
  • Changes that only alter the # fragment are not tracked, so hash-based routing records a single pageview.
  • The stored path has no query string. The only query parameters kept are utm_source, utm_medium, utm_campaign, utm_term, utm_content and ref.
  • After the first page, the referrer of each pageview is the previous page of your own site, without its query string.
  • Load the script once, in the page that stays loaded while visitors move around. A second copy does nothing.