---
title: "Cloudflare Web Analytics · Nuxt Scripts"
description: "Load Cloudflare Web Analytics during hydration with its built-in SPA measurement enabled."
canonical_url: "https://scripts.nuxt.com/scripts/cloudflare-web-analytics"
meta:
  "og:description": "Load Cloudflare Web Analytics during hydration with its built-in SPA measurement enabled."
  "og:image": "https://scripts.nuxt.com/_og/s/o_2df371027eb8d845.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Cloudflare Web Analytics · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_2df371027eb8d845.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Scripts**

# **Cloudflare Web Analytics**

[Copy for LLMs](https://scripts.nuxt.com/scripts/cloudflare-web-analytics.md)

[**Cloudflare Web Analytics**](https://developers.cloudflare.com/web-analytics/about/) reports traffic and Web Vitals. Its beacon [**does not use cookies or local storage**](https://developers.cloudflare.com/web-analytics/data-metrics/core-web-vitals/#information-collected), and the company says the product does not collect or use visitors' personal data.

**Cloudflare Web Analytics**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/cloudflare-web-analytics.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Cloudflare Web Analytics globally. Alternatively you can use the **useScriptCloudflareWebAnalytics** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      cloudflareWebAnalytics: {
        token: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4',
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

This config automatically enables **first-party mode ** (bundle + proxy). See below to customise.

## useScriptCloudflareWebAnalytics()

The `**useScriptCloudflareWebAnalytics**` composable lets you have fine-grain control over when and how Cloudflare Web Analytics is loaded on your site.

```
const { proxy } = useScriptCloudflareWebAnalytics()

// automatic page view tracking
```

Please follow the [**Registry Scripts **](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage.

## First-Party Mode: Privacy Focused Proxy

No extra config needed. The script is bundled from your domain (faster loads, no extra DNS lookup) and runtime requests are reverse-proxied through your server with automatic anonymisation (user IPs stay hidden from Cloudflare Web Analytics, works with ad blockers). [**Learn more. **](https://scripts.nuxt.com/docs/guides/first-party)

**Mode**

Bundle Proxy Partytown

**Privacy**

User IP addresses are anonymised. Other request data passes through.

```
export default defineNuxtConfig({
  scripts: {
    // ✅ First-party mode: bundled + proxied
    registry: {
      cloudflareWebAnalytics: {
        token: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4',
        trigger: 'onNuxtReady',
      },
    },
  },
})
```

## Example

Using Cloudflare Web Analytics in a component with the proxy to send events .

ConversionButton.vue

```
<script setup lang="ts">
const { proxy } = useScriptCloudflareWebAnalytics()

// noop in development, ssr
// just works in production, client
function handleAction() {
  // automatic page view tracking
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
```

Default:

- **Trigger: Client** The script loads during Nuxt hydration to keep Web Vitals metrics accurate.

The beacon script is bundled. Events go directly from the browser to `**https://cloudflareinsights.com/cdn-cgi/rum**`. Proxying is unsupported because [**Cloudflare RUM cannot collect Worker subrequests**](https://developers.cloudflare.com/web-analytics/faq/#can-i-use-real-user-monitoring-rum-with-cloudflare-workers). An HTTP 204 response from a Worker proxy does not prove that Cloudflare recorded the event.

This registry fixes the trigger to `**client**`. A `**scriptOptions.trigger**` value passed by the caller is overwritten, so this integration cannot currently be deferred with a consent or element trigger.

The current runtime always enables SPA tracking, even though [**Cloudflare documents **`**spa: false**`](https://developers.cloudflare.com/web-analytics/get-started/web-analytics-spa/#disable-spa-analytics) as the switch for disabling it. Passing `**spa: false**` to this registry currently has no effect.

## Loading in app.vue

Register the beacon in `**app.vue**`:

app.vue

```vue
<script setup lang="ts">
useScriptCloudflareWebAnalytics({
  token: '12ee46bf598b45c2868bbc07a3073f58',
})
</script>
```

The analytics script creates a `**window.__cfBeacon**` object. Access it after the script loads:

```ts
const { onLoaded } = useScriptCloudflareWebAnalytics({
  token: '12ee46bf598b45c2868bbc07a3073f58',
})
onLoaded(({ __cfBeacon }) => {
  console.log(__cfBeacon)
})
```

`**token**``string`** required **

The Cloudflare Web Analytics token.

`**spa**``boolean` = true

Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API's pushState function and listening to the onpopstate. Hash-based router is not supported.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/cloudflare-web-analytics.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/cloudflare-web-analytics.md)

[**Clarity** Load Microsoft Clarity and manage its session-recording consent state.](https://scripts.nuxt.com/scripts/clarity) [**Crisp** Add a lazy-loaded Crisp chat launcher to your Nuxt app.](https://scripts.nuxt.com/scripts/crisp)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/cloudflare-web-analytics#webpage","@type":"WebPage","description":"Load Cloudflare Web Analytics during hydration with its built-in SPA measurement enabled.","name":"Cloudflare Web Analytics","url":"https://scripts.nuxt.com/scripts/cloudflare-web-analytics","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/cloudflare-web-analytics#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/cloudflare-web-analytics"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/cloudflare-web-analytics#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Cloudflare Web Analytics","item":"https://scripts.nuxt.com/scripts/cloudflare-web-analytics","position":3}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
