Before you start
- Your site’s DNS must run through Cloudflare.
- Buy the Cloudflare Workers Paid plan first ($5 a month), under Compute > Workers Plans in Cloudflare. The Worker runs on every request on its route, assets included, and the free plan stops at 100,000 requests a day, after which a busy site can stop logging or fail with Cloudflare error 1027. See Cloudflare’s Workers pricing.
- Creating an API key needs an Owner or Admin by default.
Set it up
1
Create an API key
On the Cloudflare integration page, click New API Key, enter a name and click Create API Key. Copy the key from the dialog. Keys start with
aa_.Any Agent Analytics key works for every log source, so you can reuse one from Website > Agent Analytics > Settings. A new key can take up to a minute to start working.2
Create the Worker
- In the Cloudflare dashboard, click Workers & Pages in the sidebar.
- Click Create Application, select Start with Hello World! and click Deploy.
- Click Edit Code, clear the editor, paste the code below and click Deploy.
3
Add the endpoint and key
In the Worker’s settings, open Variables and Secrets and add two entries:
Add
ANALYTICS_KEY as a Secret. Click Deploy after adding them.4
Route your domain through the Worker
- Open your domain in Cloudflare and click Workers Routes in the sidebar.
- Click Add Route.
- Enter a pattern scoped to your site, such as
example.com/*. Use*example.com/*if you also want subdomains likewww.example.comandblog.example.com. - Select your Worker and click Save.
example.com/admin/*, with its Worker set to None.Check that it works
A browser visit won’t show anything, because ChatFeatured keeps only requests from recognized bots. Send a request with a crawler user agent instead:{"status":"accepted","accepted":1,"filtered":0}. If that works but the first test doesn’t, check the route, the Worker’s variables, and any Cloudflare security setting that might block the test request.
What gets recorded
ChatFeatured keeps requests from AI crawlers and search engine bots (see what gets counted) and discards everything else.What the Worker skips
The Worker only reportstext/html responses with a status below 500, and skips static files by extension. So crawler fetches of robots.txt, llms.txt and sitemap.xml don’t appear. To track them, remove txt|xml from IGNORE_EXT and loosen the !contentType.startsWith("text/html") check.
Troubleshooting
The test POST returns 401 Missing API key or Invalid API key
The test POST returns 401 Missing API key or Invalid API key
Missing API key means the X-API-Key header didn’t arrive. Invalid API key means the key is mistyped, deactivated, deleted, or less than a minute old.The test POST returns accepted 0 and filtered 1
The test POST returns accepted 0 and filtered 1
The key works, but the
userAgent in the body didn’t match a known bot. Use a crawler string such as GPTBot/1.0.Crawler visits stopped partway through the day
Crawler visits stopped partway through the day
You’re probably on the Workers free plan and went past 100,000 requests. Upgrade to Workers Paid under Compute > Workers Plans.
Related
- Agent Analytics: reading the data
- Agent Analytics with Webflow: running this Worker in front of a Webflow site
- Custom log integration: the endpoint and payload this Worker uses