← Back
Connect Your Cloudflare Website to Agent & LLM Analytics (Using a Worker)
Are You on an Enterprise Cloudflare Plan?
If so, you can alternatively use the Cloudflare Logpush integration to connect your website.
Overview
This integration uses a simple Cloudflare Worker that forwards analytics events to Dark Visitors. Please contact us if you need help.
Step 1: Create a Worker
- Open your domain in your Cloudflare dashboard
- In the sidebar, click Workers & Pages under Compute (Workers)
- Click the Create application button
- Select the Start with Hello World! option
- Name the worker (something like
dark-visitors
) and click Deploy - In the top right, click the
Edit code
button - Paste this code into the
worker.js
file:
export default {
async fetch(request, env, ctx) {
const response = await fetch(request)
ctx.waitUntil(trackVisit(request, env).catch(() => {}))
return response
},
}
async function trackVisit(request, env) {
await fetch("https://api.darkvisitors.com/visits", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
request_path: new URL(request.url).pathname + new URL(request.url).search,
request_method: request.method,
request_headers: {
"cf-connecting-ip": request.headers.get("cf-connecting-ip"),
"user-agent": request.headers.get("user-agent"),
"referer": request.headers.get("referer"),
"signature": request.headers.get("signature"),
"signature-input": request.headers.get("signature-input"),
"signature-agent": request.headers.get("signature-agent"),
},
}),
})
}
- Navigate back to the Dark Visitors Projects page and open your project
- Copy your access token from the Settings page
- Back in Cloudflare, swap in your access token where it says
YOUR_ACCESS_TOKEN
- Click Deploy
- Navigate back to your Cloudflare dashboard and select your domain
- In the sidebar, click Workers Routes
- Click Add route in the HTTP Routes section
- Under Route, enter your domain followed by
/*
(e.g.example.com/*
) and select the worker you just created - Click Save
Step 2: Test Your Integration
- Navigate to the Projects page
- Select your project
- Click Settings
- Click Send a Test Visit
- Click Realtime
If your website is correctly connected, you should see visits from the Dark Visitor agent in the realtime timeline within a few seconds.