SPA

The analytics script supports all rendering patterns for web applications, and you don’t need to take any additional steps to adapt it for SPAs.

For single page applications, add the analytics script to your HTML file or your application’s layout once.

Since, during client-side navigation in an SPA, the browser does not receive a new HTML document and does not trigger visibilitychange event, the analytics script sends page views when history.pushState() is called and on the popstate event, which is fired when the active history entry changes.

During client-side navigation, the analytics script waits for the next frame to render using window.requestAnimationFrame(). This is necessary to ensure that when navigating to another page in the SPA, the document has time to update its content before collecting the props for the page view from the DOM and sending the page view.