---
title: Cloudflare Web Analytics
description: Cookieless analytics from Cloudflare with a prebuilt helper that serializes the beacon config into the `data-cf-beacon` attribute.
lastModified: 2026-05-10
icon: cloudflare-web-analytics
---
Cloudflare Web Analytics is a cookieless analytics product configured through a single `data-cf-beacon` attribute on its loader. The `cloudflareWebAnalytics()` helper serializes your token and single-page application (SPA) preference into that attribute and hands the result to c15t's script loader.

## Integrate with c15t

**React**

```tsx
import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/react';
import { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';

const scripts = [
  cloudflareWebAnalytics({
    token: 'your-cloudflare-token',
  }),
];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: 'https://your-instance.c15t.dev',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**Next.js**

```tsx
'use client';

import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/nextjs';
import { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';

const scripts = [
  cloudflareWebAnalytics({
    token: 'your-cloudflare-token',
  }),
];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: '/api/c15t',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**JavaScript**

```ts
import { getOrCreateConsentRuntime } from 'c15t';
import { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';

getOrCreateConsentRuntime({
  mode: 'hosted',
  backendURL: 'https://your-instance.c15t.dev',
  scripts: [
    cloudflareWebAnalytics({
      token: 'your-cloudflare-token',
    }),
  ],
});
```

## How c15t loads it

* **Category:** `measurement` (Analytics)
* **Loads when:** measurement consent is granted
* **On revocation:** unloaded — c15t removes the script element from the DOM. Cloudflare Web Analytics is cookieless, so no client-side state needs clearing.

SPA route tracking is enabled by default. Disable it for traditional multi-page apps:

```ts
cloudflareWebAnalytics({
  token: 'your-cloudflare-token',
  spa: false,
})
```

The helper JSON-encodes `{ token, spa }` into the `data-cf-beacon` attribute that Cloudflare's loader reads at startup, matching Cloudflare's recommended embed.

## Tracking events in your app

Cloudflare Web Analytics has no app-facing event API — the beacon tracks pageviews automatically once the script is loaded. There are no event calls in your application code to guard, so c15t's consent gating fully controls when and whether tracking happens.

## Types

### CloudflareWebAnalyticsOptions

| Property    | Value                                                                    |
| :---------- | :----------------------------------------------------------------------- |
| Type Name   | \`CloudflareWebAnalyticsOptions\`                                        |
| Source Path | \`./packages/scripts/src/vendors/analytics/cloudflare-web-analytics.ts\` |

\*AutoTypeTable: Could not extract \`CloudflareWebAnalyticsOptions\` from \`./packages/scripts/src/vendors/analytics/cloudflare-web-analytics.ts\`. Verify the path/name and that the file is included by your tsconfig.\*

### Script

| Property    | Value                                               |
| :---------- | :-------------------------------------------------- |
| Type Name   | \`Script\`                                          |
| Source Path | \`./packages/core/src/libs/script-loader/types.ts\` |

\*AutoTypeTable: Could not extract \`Script\` from \`./packages/core/src/libs/script-loader/types.ts\`. Verify the path/name and that the file is included by your tsconfig.\*
