Cloudflare Web Analytics automatically tracks user interactions on Single Page Applications (SPAs) via one of the following three methods, depending on which is supported:
- Using the Soft Navigations API ↗
- Listening on
navigateevents via the Navigation API ↗ - By patching the History API ↗'s
pushStatefunction and listening to theonpopstateevent
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.
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>