Skip to content
Logo

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 siteDo this
Static HTML on Pages or WorkersPaste the script tag
A framework (Astro, SvelteKit, Nuxt, Next.js, React Router)Use that framework's SDK, below
Any site behind Cloudflare, without editing its HTMLInject the script with HTMLRewriter
Server events from a Worker or Pages FunctionCloudflare Workers

You need a project's client ID first: the dashboard shows it when you create a project (see the 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:

<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 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:

For events from server code in these apps, such as form actions, API routes and webhooks, use the server SDK in a Worker.

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:

// 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);
  },
};
// 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.

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.