Skip to main content
Use Cloudflare 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.

Prerequisites

Cloudflare Workers are available on Cloudflare’s the free plan up to 100K requests/day which is sufficient for most sites. See Cloudflare Workers pricing for details.

Setup

1

Clone and install

git clone https://github.com/siteline-ai/siteline-cloudflare-worker.git
cd siteline-cloudflare-worker
npm install
2

Log in to Cloudflare via Wrangler (official CLI tool)

  • Trigger the login page
npx wrangler login
  • Allow Wrangler (Cloudflare’s official command-line tool) to access your account
3

Set your website key

  • Create an encrypted secret for your Siteline website key
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’
4

Deploy

npm run deploy
5

Configure routes

  • In the Cloudflare Dashboard, navigate to Compute & AI > Workers & Pages
  • Select the siteline-cloudflare-worker > Settings > Domain & Routes > Add > Route to add a new route.
  • Select your project as the Zone and enter in a route as shown below for the domains you’d like to track:
    • example.com/* — tracks all pages for your domain
    • *example.com/* — tracks all pages & subdomains
    We recommend setting up tracking for all content pages. For example, if your blog configured as a subdomain then make sure to use *example.com/* to capture both subdomains and pages.
C) Set Failure Mode to Fail OpenD) Save

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.

Environment variables

SITELINE_WEBSITE_KEY
string
required
Your Siteline website key. Set via npx wrangler secret put SITELINE_WEBSITE_KEY.

Troubleshooting

Verify that routes are configured in the Cloudflare Dashboard under Compute & AI > Workers & Pages. Select the siteline-cloudflare-worker > Settings > DomainRoutes. You should see either exampledomain.com/* or *exampledomain.com/* configured as routes.
Run npx wrangler secret list to confirm SITELINE_WEBSITE_KEY is present.
Run npx wrangler tail to stream logs from your deployed worker.
Run npx wrangler secret put SITELINE_WEBSITE_KEY and paste your new key when prompted.
Need help? Book a setup call and we’ll walk you through it.