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

# Cloudflare integration (Worker)

> Forward AI crawler and referral hits from your Cloudflare zone with a small pass-through Worker.

The Cloudflare integration is a small Worker in your own Cloudflare account. It passes every request straight through to your site and sends RankRaft AI a copy afterwards, so it never slows down or blocks a visitor. Because it runs at the edge, it also sees requests served from Cloudflare's cache, which a server-side plugin can't.

**Sees:** AI crawlers and AI referrals, including cached pages.

## Before you start

* Your domain is proxied through Cloudflare (orange cloud).
* You have a RankRaft AI site key. See [Your site key](/agent-analytics/integrations/overview#your-site-key).

## Set up

<Steps>
  <Step title="Get your site key">
    In RankRaft AI, open **Integrations**, choose **Cloudflare** and click **Create site key**. Copy it.
  </Step>

  <Step title="Create a Worker">
    In your Cloudflare dashboard, go to **Workers & Pages → Create → Start with Hello World!**. Name it `rankraft-ai` and click **Deploy**.
  </Step>

  <Step title="Paste our code">
    Click **Edit code**, delete everything in the editor, paste the code shown on the RankRaft AI **Integrations** page (`worker.js`), then click **Deploy**.
  </Step>

  <Step title="Add your site key">
    In the Worker, open **Settings → Variables and Secrets → Add**. Choose type **Secret**, name it `RANKRAFT_SITE_KEY`, paste your key as the value, and click **Deploy**.
  </Step>

  <Step title="Send your site's traffic through it">
    Open **Settings → Domains & Routes → Add → Route**. Pick your zone and enter the route `example.com/*`.

    Set **Failure mode** to **Fail open**, so your site keeps working even if the Worker hits a limit.

    If visitors also use `www.example.com`, add a second route `www.example.com/*`.
  </Step>

  <Step title="Check it's working">
    Open your site in a new tab, then press **Check again** at the top of the RankRaft AI **Integrations** page. It turns green within a minute of the first visit.
  </Step>
</Steps>

<Note>
  Cloudflare's free plan includes 100,000 Worker requests a day. A busier site needs Workers Paid (\$5/month on Cloudflare).
</Note>

## Configuration

| Variable | Required | Description |
| - | - | - |
| `RANKRAFT_SITE_KEY` | Yes | Your site key. Always store it as a **Secret**. |
| `RANKRAFT_EXCLUDED_PATHS` | No | Comma-separated path prefixes that are never forwarded, for example `/wp-admin,/checkout,/cart,/admin,/api`. |
| `RANKRAFT_ENDPOINT` | No | Defaults to `https://ingest.rankraft.ai`. Leave it unset. |

## Deploying with Wrangler

If you manage Workers as code, deploy the same script with a `wrangler.jsonc` like this:

```jsonc wrangler.jsonc theme={"system"}
{
  "name": "rankraft-agent-analytics",
  "main": "src/index.js",
  "compatibility_date": "2025-01-01",
  "routes": [
    { "pattern": "example.com/*", "zone_name": "example.com" }
  ],
  "vars": {
    "RANKRAFT_EXCLUDED_PATHS": "/wp-admin,/checkout,/cart,/admin,/api"
  }
}
```

Then set the key as a secret:

```bash theme={"system"}
npx wrangler secret put RANKRAFT_SITE_KEY
```

## What it sends

For each request, after the response has been returned to the visitor: timestamp, host, method, path, query string, visitor IP (`CF-Connecting-IP`), user agent, referrer, response status, response size, country and ASN. WebSocket upgrades and excluded paths are skipped. The Worker never modifies the request or the response.

## Troubleshooting

* **Still "Waiting for your first data".** Check the route matches the hostname you visited (`www` vs apex), and that the secret is named exactly `RANKRAFT_SITE_KEY`.
* **Data stopped after rotating the key.** Paste the new key into the Worker's secret and deploy.
* **Cloudflare's "Block AI Scrapers and Crawlers" setting.** If it's on (under **Security → Bots**), Cloudflare blocks AI crawlers before they reach your Worker or your site. Turn it off if you want AI engines to read your site.


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