Skip to content

Web Analytics for SPAs

Last updated View as MarkdownAgent setup

Cloudflare Web Analytics automatically tracks user interactions on Single Page Applications (SPAs) via one of the following three methods, depending on which is supported:

  1. Using the Soft Navigations API
  2. Listening on navigate events via the Navigation API
  3. By patching the History API's pushState function and listening to the onpopstate event

Disable SPA measurement

If you want to disable the automatic tracking for SPAs, you can do so by adding the spa option with a value of false in the data attribute of the script tag, as shown below:

<script
  type="module"
  src="https://static.cloudflareinsights.com/beacon.min.js"
  data-cf-beacon='{"token": "...", "spa": false}'
></script>

Note: this requires using the manual embedding approach.

Google Tag Manager (GTM)

If you are using Google Tag Manager (GTM), you can disable SPA tracking by passing the spa=false option via the query string in the script URL:

<script
  type="module"
  src="https://static.cloudflareinsights.com/beacon.min.js?token=...&spa=false"
></script>

Was this helpful?