# Sites on Cloudflare

FlarePanel takes in events on Cloudflare's network, so a site that already runs on Cloudflare sends them to the nearest data center, like the rest of its traffic. Pick the setup that matches your site.

| Your site | Do this |
|---|---|
| Static HTML on Pages or Workers | Paste the [script tag](/integrations/cloudflare#static-sites) |
| A framework (Astro, SvelteKit, Nuxt, Next.js, React Router) | Use that framework's SDK, [below](/integrations/cloudflare#frameworks) |
| Any site behind Cloudflare, without editing its HTML | Inject the script with [HTMLRewriter](/integrations/cloudflare#without-editing-html) |
| Server events from a Worker or Pages Function | [Cloudflare Workers](/sdks/cloudflare-workers) |

You need a project's client ID first\: the [dashboard](https\://dashboard.flarepanel.dev/onboarding) shows it when you create a project (see the [Quickstart](/getting-started/quickstart)). Once the script is live, load your site\: the dashboard confirms the first event within a couple of seconds.

## Static sites

For plain HTML on Cloudflare Pages or Workers static assets, paste this before `</head>` on every page, or once in your layout template\:

```html
<script>
  window.op=window.op||function(){var n=[];return new Proxy(function(){arguments.length&&n.push([].slice.call(arguments))},{get:function(t,r){return"q"===r?n:"call"===r||"apply"===r||"bind"===r?t[r]:function(){n.push([r].concat([].slice.call(arguments)))}} ,has:function(t,r){return"q"===r}}) }();
  window.op('init', {
    clientId: 'YOUR_CLIENT_ID',
    trackScreenViews: true,
    trackOutgoingLinks: true,
  });
</script>
<script src="https://flarepanel.dev/op1.js" defer async></script>
```

Deploy as usual (`npx wrangler deploy`, or a push to the branch your Pages project builds). The script sets no cookies, so it needs no consent banner. See [Script tag](/sdks/script-tag) for custom events.

## Frameworks

Cloudflare's framework guides deploy these to Workers. The FlarePanel SDK for each runs in the browser, so it works the same on Cloudflare as anywhere else\:

* [Astro](/sdks/astro)
* [SvelteKit](/sdks/sveltekit)
* [Nuxt](/sdks/nuxt)
* [Next.js](/sdks/nextjs), including sites deployed with OpenNext
* [React Router and Remix](/sdks/react-router)

For events from server code in these apps, such as form actions, API routes and webhooks, use the [server SDK in a Worker](/sdks/cloudflare-workers).

## Without editing HTML

If your site is proxied through Cloudflare (orange cloud) but you cannot or would rather not change its HTML, for example a site from a CMS or an old app, a Worker on the route can add the script to every page on the way out with [HTMLRewriter](https\://developers.cloudflare.com/workers/runtime-apis/html-rewriter/)\:

```ts
// src/index.ts
const SNIPPET = `<script>
  window.op=window.op||function(){var n=[];return new Proxy(function(){arguments.length&&n.push([].slice.call(arguments))},{get:function(t,r){return"q"===r?n:"call"===r||"apply"===r||"bind"===r?t[r]:function(){n.push([r].concat([].slice.call(arguments)))}} ,has:function(t,r){return"q"===r}}) }();
  window.op('init', { clientId: 'YOUR_CLIENT_ID', trackScreenViews: true });
</script>
<script src="https://flarepanel.dev/op1.js" defer async></script>`;

export default {
  async fetch(request: Request): Promise<Response> {
    const response = await fetch(request);
    const type = response.headers.get('content-type') ?? '';
    if (!type.includes('text/html')) {
      return response;
    }
    return new HTMLRewriter()
      .on('head', {
        element(head) {
          head.append(SNIPPET, { html: true });
        },
      })
      .transform(response);
  },
};
```

```jsonc
// wrangler.jsonc
{
  "name": "add-flarepanel",
  "main": "src/index.ts",
  "compatibility_date": "2026-11-25",
  "routes": [{ "pattern": "example.com/*", "zone_name": "example.com" }]
}
```

Deploy it with `npx wrangler deploy`. Every request on the route then runs the Worker once, which counts toward your Workers requests. To keep it to pages only, narrow the route pattern, for example leave out `/assets/*`.

## Keep Cloudflare Web Analytics if you like

FlarePanel and Cloudflare Web Analytics do not conflict\: many sites keep Cloudflare's beacon for Core Web Vitals and use FlarePanel for events, campaigns and funnels. See [Coming from Cloudflare Web Analytics](/getting-started/cloudflare-web-analytics).

## AI crawlers

The script only sees browsers. To see which AI crawlers read your pages, connect your Cloudflare zone with a read-only token or wrap your Worker, as described in [AI crawlers and bots](/tracking/ai-crawlers).
