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

# Cloudflare Worker

> Log every AI bot visit at the edge, and serve AI-ready pages.

> [!NOTE]
>
> Agent traffic is on the Growth plan.

For sites proxied by Cloudflare, the Sightline Worker runs in front of your site. It sees every request, cached or not, so it catches bot visits that a WordPress plugin behind a cache would miss. It works with any website, not only WordPress.

* **People and other bots** pass straight through to your site.
* **AI bot visits** are logged to Sightline in the background.
* **AI-ready pages**: with it turned on, AI assistants' bots get your approved [AI-ready page](https://docs.asksightline.com/action/ai-context.md#ai-ready-pages) for that URL. Search engine crawlers never do.

> [!WARNING]
>
> Your site must be proxied by Cloudflare: the orange cloud must be on for its DNS records.

## Set up

**1. Add your site in Sightline**

Open **Settings → Integrations → Agent traffic** and click **Add site**. Copy the site key. It's only shown once.

**2. Copy the Worker code**

On the same screen, click **Copy Worker code**.

**3. Deploy the Worker**

> [tab] Cloudflare dashboard
>
> 1. Go to **Workers & Pages → Create → Hello World**, then **Edit code**. Paste the code and click **Deploy**.
> 2. In the Worker's **Settings → Variables**, add `AV_APP_URL`, `AV_SITE_ID` and `AV_AXP` as plain text, and `AV_SITE_KEY` as a secret.
> 3. In your zone, open **Workers Routes → Add route**, enter `example.com/*` (your domain) and choose this Worker.

> [tab] Wrangler CLI
>
> 1. Save the code as `agent-worker.js` next to a `wrangler.jsonc` with your values.
> 2. Run `npx wrangler secret put AV_SITE_KEY` and paste the site key.
> 3. Run `npx wrangler deploy`.

**4. Test it**

```bash theme={null}
curl -A "AIVisibility-Testbot" https://example.com/
```

The visit appears on Sightline's **Agent traffic** page within a minute.

## Serving AI-ready pages

Set `AV_AXP` to `on` in the Worker's variables, and turn on **Serve approved pages** for the site in Sightline. Only pages you've approved in **Settings → AI-ready pages** are served.

## If a Worker is already on the route

Cloudflare runs only one Worker per route. If your site already has one (another analytics Worker, redirects and so on), chain them:

1. Give the Sightline Worker a **service binding** named `AV_NEXT` that points to your existing Worker (**Settings → Bindings → Add → Service binding**).
2. Deploy the Sightline Worker.
3. Point the route at the Sightline Worker.

Every request is then passed on to your existing Worker instead of straight to your site, so it keeps working unchanged. Both Workers must be on the same Cloudflare account. Add the binding before switching the route so the existing Worker never misses a request. To undo, point the route back at your existing Worker.

## Cost

Every request to your site passes through the Worker, on your Cloudflare account. Cloudflare's free Workers plan covers 100,000 requests a day. Beyond that, Workers Paid is \$5 per month for 10 million requests. Only AI bot visits make an extra request, to log them.


## Related topics

- [WordPress plugin](https://docs.asksightline.com/integrations/wordpress-plugin.md)
- [Plans](https://docs.asksightline.com/plans.md)
- [AI context and approved facts](https://docs.asksightline.com/action/ai-context.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.