The Cloudflare integration enables server-side tracking of AI crawler activity on your website using Cloudflare Workers. This allows you to monitor when AI bots like GPTBot, ClaudeBot, and PerplexityBot access your content.
Why Use Cloudflare Workers?
Traditional analytics tools rely on JavaScript that runs in the browser. AI crawlers don’t execute JavaScript, so they’re invisible to tools like Google Analytics.
Cloudflare Workers run at the edge (server-side), capturing all traffic including AI scrapers that traditional analytics miss. This gives you complete visibility into how AI platforms discover and index your content.
Benefits
- Capture AI crawler traffic that JavaScript-based analytics miss
- Zero latency impact - Workers run asynchronously without blocking requests
- Edge-level tracking - Logs are collected at Cloudflare’s edge before reaching your server
- Simple setup - Deploy in minutes with no code changes to your site
Prerequisites
Before you begin, you’ll need:
- A Cloudflare account (free tier works)
- Your domain configured with Cloudflare (using Cloudflare DNS)
- A ChatFeatured account with Agent Analytics enabled
Setup Instructions
Step 1: Get Your API Key
- Log in to ChatFeatured and navigate to your brand
- Go to Agent Analytics > Settings
- Click Create API Key and give it a name (e.g., “Cloudflare Worker”)
- Copy the generated API key - you’ll need it in Step 4
Step 2: Create the Worker in Cloudflare
- Log in to your Cloudflare Dashboard
- Click Workers & Pages in the sidebar
- Click Create Application
- Select Start with Hello World!
- Click Deploy
- At the top right, click Edit Code
- Clear the contents of the editor
- Copy and paste the worker code below
- Click Deploy
Step 3: Worker Code
Copy this code and paste it into the Cloudflare Worker editor:
/**
* Cloudflare Worker – stream HTML page views to ChatFeatured
*
* Excludes common static-asset extensions.
* It runs as a middleware and doesn't interfere with the actual request handling.
*/
const IGNORE_EXT =
/\.(?:png|jpe?g|gif|svg|webp|ico|mp4|webm|mp3|wav|ogg|css|js|mjs|json|map|txt|xml|pdf|docx?|xlsx?|pptx?|zip|rar|7z|tar|gz|woff2?|ttf|eot)$/i;
export default {
async fetch(request, env, ctx) {
// Get the original response
const response = await fetch(request);
// Clone the response for processing
const responseClone = response.clone();
// NOTE: Does NOT block / wait
ctx.waitUntil(handleRequest(request, responseClone, env));
return response;
},
};
async function handleRequest(request, response, env) {
const requestUrl = new URL(request.url);
// Skip obvious static assets early
if (IGNORE_EXT.test(requestUrl.pathname)) {
return;
}
// Only log HTML pages (and OPTIONAL: status < 500)
const contentType = response.headers.get("content-type") || "";
if (!contentType.startsWith("text/html") || response.status >= 500) {
return;
}
const logData = {
timestamp: new Date().toISOString(),
host: requestUrl.hostname,
method: request.method,
pathname: requestUrl.pathname,
query_params: requestUrl.search.startsWith("?")
? requestUrl.search.slice(1)
: "",
ip: request.headers.get("cf-connecting-ip") || "",
userAgent: request.headers.get("user-agent") || "",
referer: request.headers.get("referer") || "",
status: response.status,
};
await fetch(env.ANALYTICS_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": env.ANALYTICS_KEY,
},
body: JSON.stringify(logData),
}).catch((error) => console.error("Failed to send logs:", error));
}
After deploying, configure the required environment variables:
- In your Worker’s settings, click Variables and Secrets
- Add the following variables:
| Variable Name | Value |
|---|
ANALYTICS_ENDPOINT | https://ingest.chatfeatured.com/v1/logs |
ANALYTICS_KEY | Your API key from Step 1 |
- Click Deploy to save the changes
Step 5: Set Up Worker Routes
Connect the Worker to your domain:
- Navigate to your domain in Cloudflare
- Click Worker Routes in the sidebar
- Click Add Route
- Enter your route pattern:
*yourdomain.com/*
- Select your worker from the dropdown
- Click Save
Replace yourdomain.com with your actual domain. The * wildcards ensure all subdomains and paths are tracked.
Step 6: Verify Setup
Once deployed, AI crawler traffic will appear in your Agent Analytics dashboard within a few minutes. Visit your site in a browser to verify the Worker is running, then check your dashboard for incoming data.
How It Works
The Cloudflare Worker runs on every request to your site:
- Request arrives at Cloudflare’s edge
- Worker executes and captures request metadata (URL, user agent, IP, etc.)
- Original request continues to your origin server without delay
- Logs are sent asynchronously to ChatFeatured’s ingestion endpoint
- AI crawlers identified and displayed in your analytics dashboard
The Worker only logs HTML page requests. Static assets (images, CSS, JS, fonts) are automatically excluded to reduce noise.
What Gets Tracked
The Worker captures the following data for each request:
- Host - The domain being accessed
- Path - The URL path being requested
- User Agent - Used to identify AI crawlers
- IP Address - For geographic insights
- Referer - Where the request came from
- Status Code - The HTTP response status
- Timestamp - When the request occurred
ChatFeatured’s backend automatically identifies AI crawlers (GPTBot, ClaudeBot, PerplexityBot, Bingbot, etc.) and filters out regular user traffic.
Excluding Routes
To exclude specific routes from tracking (like admin pages):
- Go to Worker Routes for your domain
- Click Add Route
- Enter the pattern to exclude (e.g.,
*yourdomain.com/admin/*)
- Set Worker to None
- Click Save
Routes are evaluated in order, so add exclusion routes after your main tracking route.
Pricing
Cloudflare Workers pricing:
| Tier | Requests | Cost |
|---|
| Free | 100,000/day | $0 |
| Paid | 10 million/month | $5/month |
While the free tier of Cloudflare Workers is compatible, we highly recommend the paid plan ($5/month) for reliable analytics tracking. Review the Cloudflare Workers pricing page for more details.
Troubleshooting
No data appearing in dashboard
- Verify the Worker is deployed - Check Workers & Pages in Cloudflare
- Check environment variables - Ensure both
ANALYTICS_ENDPOINT and ANALYTICS_KEY are set correctly
- Verify route configuration - Ensure your domain’s Worker Routes include your site
- Test the API key - Try creating a new key if the current one isn’t working
Worker errors in Cloudflare logs
- Check the Worker’s Real-time Logs in Cloudflare
- Verify the
ANALYTICS_ENDPOINT URL is correct
- Ensure your API key is valid and active
Some pages not being tracked
The Worker only tracks HTML pages (content-type: text/html). API endpoints, JSON responses, and static files are intentionally excluded.
High request volume
If you’re approaching Cloudflare’s free tier limits:
- Consider upgrading to the paid Workers plan
- Add exclusion routes for high-traffic non-essential paths
- Contact ChatFeatured support for volume optimization tips
Security
API Key Best Practices
- Store your API key only in Cloudflare’s environment variables (encrypted at rest)
- Create a dedicated API key for Cloudflare (don’t reuse keys across integrations)
- Rotate keys periodically from the ChatFeatured dashboard
- Revoke keys immediately if you suspect they’ve been compromised
Data Privacy
- Only request metadata is logged (no page content or user data)
- IP addresses are used for geographic aggregation only
- All data is transmitted over HTTPS
- ChatFeatured is GDPR compliant
Next Steps
Once your Cloudflare integration is set up:
- Monitor your dashboard - Check Agent Analytics to see AI crawler activity
- Track citations - See which pages AI models cite in their responses
- Optimize content - Use insights to improve AI visibility for high-traffic pages
For more information on using Agent Analytics, see Setting up Agent Analytics.