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 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 from Step 3
- Click Deploy
Step 3: Worker Code
Copy this code and paste it into the Cloudflare Worker editor:Step 4: Configure Environment Variables
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
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
Advanced Configuration
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
Multi-Domain Setup
If you manage multiple domains, you can:- Create separate Workers for each domain
- Or use a single Worker with conditional routing based on hostname
- Point each domain’s Worker Routes to the appropriate Worker
Performance Optimization
To reduce log volume and costs:- Add sampling - Only log a percentage of requests in the Worker code:
- Filter user agents - Skip logging for known bots:
- Exclude paths - Skip logging for specific path patterns:
Custom User Identification
To track which users interact with your content, modify the Worker to capture user identifiers from cookies or headers:Pricing & Cost Estimation
Cloudflare Workers pricing:| Tier | Requests | Cost |
|---|---|---|
| Free | 100,000/day | $0 |
| Paid | 10 million/month | $5/month |
| Monthly Requests | Estimated Cost |
|---|---|
| 1M | $0 (free tier) |
| 10M | $5/month |
| 100M | $50/month |
| 1B | $500/month |
Troubleshooting
No data appearing in dashboard
No data appearing in dashboard
- Verify the Worker is deployed - Check Workers & Pages in Cloudflare
- Check environment variables - Ensure both
ANALYTICS_ENDPOINTandANALYTICS_KEYare 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
- Check Cloudflare logs - Visit your Worker’s Real-time Logs tab for errors
Worker errors in Cloudflare logs
Worker errors in Cloudflare logs
- Check the Worker’s Real-time Logs in Cloudflare
- Verify the
ANALYTICS_ENDPOINTURL is correct:https://ingest.chatfeatured.com/v1/logs - Ensure your API key is valid and active
- Check for syntax errors in the Worker code
Some pages not being tracked
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.If you need to track other content types, modify the Worker code to remove the content-type check.High request volume or approaching free tier limits
High request volume or approaching free tier limits
If you’re approaching Cloudflare’s free tier limits:
- Consider upgrading to the paid Workers plan ($5/month)
- Add exclusion routes for high-traffic non-essential paths
- Implement sampling in the Worker code to reduce log volume
- Contact ChatFeatured support for volume optimization tips
API key not working (401 Unauthorized)
API key not working (401 Unauthorized)
Security Best Practices
API Key Management
- Store 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
See Also
- Agent Analytics with Webflow — Setup for Webflow-hosted sites (requires O2O)
- Vercel Integration — Alternative for Vercel projects
- Agent Analytics — Understanding your data