> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siteline.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare

> Integrate Siteline with Cloudflare Workers

Use [Cloudflare Workers](https://developers.cloudflare.com/workers/) to intercept requests at the edge and forward server logs containing AI bot & agent visit data to Siteline. The worker runs outside your application's request path, so there's no impact on site performance and no Cloudflare data is modified in any way.

<Note>
  On a hosted website builder like Webflow, Framer, or HubSpot? See [Website Builders](/integrations/website-builders) for the full DNS-and-Worker setup.
</Note>

## Prerequisites

* A [Siteline website key](/authorization)
* A Cloudflare account with your domain configured
* [Node.js](https://nodejs.org/) installed locally

## Setup

<Info>
  Both Cloudflare's DNS proxy and Workers run on Cloudflare's **free tier** (100K Worker requests/day), which covers most sites.

  If you have higher traffic and wish to stay on the free tier you can [scope your Worker routes](https://developers.cloudflare.com/workers/configuration/routing/routes/) to only the subdomains or paths that matter (e.g. your marketing site and blog, not your app dashboard). See [Cloudflare Workers pricing](https://developers.cloudflare.com/workers/platform/pricing/) for details.
</Info>

<Steps>
  <Step title="Clone and install">
    ```bash theme={null}
    git clone https://github.com/siteline-ai/siteline-cloudflare-worker.git
    cd siteline-cloudflare-worker
    npm install
    ```
  </Step>

  <Step title="Log in to Cloudflare via Wrangler (official CLI tool)">
    * Trigger the login page

    ```bash theme={null}
    npx wrangler login
    ```

    * Allow Wrangler (Cloudflare's official command-line tool) to access your account
  </Step>

  <Step title="Set your website key">
    * Create an encrypted secret for your Siteline website key

    ```bash theme={null}
    npx wrangler secret put SITELINE_WEBSITE_KEY
    ```

    * Paste your key when prompted and press Enter
    * Enter `Y` when prompted if you want to create a new Worker with name `siteline-cloudflare-worker`
  </Step>

  <Step title="Deploy">
    ```bash theme={null}
    npm run deploy
    ```
  </Step>

  <Step title="Configure routes">
    * In the [Cloudflare Dashboard](https://dash.cloudflare.com/), navigate to **Compute & AI** > **Workers & Pages**

    * Select **siteline-cloudflare-worker** > **Settings** > **Domain & Routes** > **Add** > **Route**

    * Select your project as the Zone and enter a route for the domains you'd like to track:

      * `example.com/*` — tracks all *pages* for your domain
      * `*example.com/*` — tracks all *pages & subdomains*

          <Info>
            We recommend tracking all *content* pages. If your blog is configured as a subdomain, use `*example.com/*` to capture both subdomains and root pages.
          </Info>

    * Set **Failure Mode** to **Fail Open**

    * Save
  </Step>
</Steps>

## How it works

The worker runs as middleware on your domain:

1. Receives an incoming request
2. Forwards the request immediately to your origin (zero added latency)
3. Sends tracking data to Siteline in the background via `ctx.waitUntil`
4. Returns the response to the visitor unmodified

Static assets (images, CSS, JS, fonts) are automatically excluded.

View the full source on [GitHub](https://github.com/siteline-ai/siteline-cloudflare-worker).

## Environment variables

<ResponseField name="SITELINE_WEBSITE_KEY" type="string" required>
  Your Siteline website key. Set via `npx wrangler secret put SITELINE_WEBSITE_KEY`.
</ResponseField>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Worker not tracking visits">
    Verify that routes are configured in the Cloudflare Dashboard under **Compute & AI** > **Workers & Pages**. Select **siteline-cloudflare-worker** > **Settings** > **Domain** > **Routes.** You should see either `exampledomain.com/*` or `*exampledomain.com/*` configured as routes.
  </Accordion>

  <Accordion title="How do I check if my key is set?">
    Run `npx wrangler secret list` to confirm `SITELINE_WEBSITE_KEY` is present.
  </Accordion>

  <Accordion title="How do I view real-time logs?">
    Run `npx wrangler tail` to stream logs from your deployed worker.
  </Accordion>

  <Accordion title="How do I update my website key?">
    Run `npx wrangler secret put SITELINE_WEBSITE_KEY` and paste your new key when prompted.
  </Accordion>
</AccordionGroup>

<Tip>
  **Need help?** [Book a setup call](https://cal.com/team/siteline/tech-set-up) and we'll walk you through it.
</Tip>
