Settings & Integrations4 min read

Connect Cloudflare

How to connect your website served by Cloudflare (CDN) to RankMonster's Agent Traffic tool to view all accesses and metrics from LLM bots to your domain using Cloudflare Workers.

Overview#

The Agent Traffic tool in RankMonster lets you monitor how much access your site is getting from LLM bots—including ChatGPT, Perplexity, Gemini, Grok, and others.

If your website is proxied by Cloudflare, you can use Cloudflare Workers to send traffic logs to RankMonster. The Worker runs at the edge and forwards request details without slowing down your site.

[!NOTE] Cloudflare CDN and Cloudflare Workers are offered separately by Cloudflare, and are not included in your RankMonster plan. Cloudflare offers generous free plans for smaller websites. For higher-traffic websites, please note that there may be additional costs associated with deploying Agent Traffic via Workers. See our additional guidance below.

Adding Your Website#

  1. Open the RankMonster app.

  2. Go to Settings > Integrations.

  3. Under the Edge CDN AI Tracker section, click Connect CDN Tracker.

  4. Run the initial Diagnostic Wizard to verify your domain and firewall settings.

  5. Once verified, select Cloudflare to view your specific integration credentials (Drain destination URL and API key header).

[!IMPORTANT] Each site has its own endpoint and key. Don't reuse them across different sites or integrations.

Integrating Cloudflare Workers#

Step 1: Ensure your website is proxied by Cloudflare#

Workers will run only if your website is proxied by Cloudflare. You can check if the website is proxied by the DNS menu on the domain level. Verify that the proxy status is set to Proxied (orange cloud) for your A or CNAME records.

⚠️ If the website is not proxied (grey cloud), the next steps won't work.

Step 2: Create a Worker#

  1. Log in to your Cloudflare dashboard.
  2. Navigate to Workers & Pages → Create Application.
  1. Select Start with Hello World!
  1. Give it a name (e.g., rankmonster-tracker) and then click on Deploy.
  1. Once deployed, click on Edit code and follow the next step.

Step 3: Add Worker Code#

The Worker intercepts requests, collects traffic data (user agent, path, status code, etc.), and sends it to RankMonster asynchronously without blocking the user response.

Replace the default Worker code with the following optimized snippet:

javascript
const extractClientUserAgent = (req) => {
const originalUa = req.headers.get("X-Original-UA");
const stdUa = req.headers.get("User-Agent");
return (originalUa || stdUa || "unknown").toLowerCase();
};
const sendTrafficLog = async (payload, env) => {
try {
const res = await fetch(env.RANKMONSTER_WEBHOOK_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Api-Key": env.RANKMONSTER_API_KEY,
},
body: JSON.stringify(payload),
});
if (!res.ok) {
console.warn("RankMonster logger returned status:", res.status);
}
} catch (err) {
console.error("RankMonster webhook error:", err);
}
};
export default {
async fetch(request, env, ctx) {
const targetUrl = new URL(request.url);
const startMs = Date.now();
const ua = extractClientUserAgent(request);
const processLog = (serverResponse) => {
ctx.waitUntil(
sendTrafficLog(
{
timestamp: new Date().toISOString(),
site_id: env.RANKMONSTER_SITE_ID,
domain: targetUrl.hostname,
user_agent: ua,
url: targetUrl.toString(),
path: targetUrl.pathname,
method: request.method,
status_code: serverResponse.status,
response_time_ms: Date.now() - startMs,
ip_address: request.headers.get("CF-Connecting-IP") || "unknown",
},
env
)
);
};
try {
const clonedReq = new Request(request.url, request);
const serverResponse = await fetch(clonedReq);
processLog(serverResponse);
return serverResponse;
} catch (err) {
const fallbackResponse = new Response("Edge Error", { status: 500 });
processLog(fallbackResponse);
return fallbackResponse;
}
},
};

Click Deploy to save your new Worker code.

Step 4: Set Environment Variables#

In your Worker settings, go to Settings → Variables. Click Add variable three times to add the following three environment variables exactly as shown.

  1. Variable 1:
    • Variable name: RANKMONSTER_SITE_ID
    • Value: (paste your site ID from the RankMonster app)
    • Type: Plain text
  2. Variable 2:
    • Variable name: RANKMONSTER_WEBHOOK_URL
    • Value: (paste your webhook URL from the RankMonster app)
    • Type: Plain text
  3. Variable 3:
    • Variable name: RANKMONSTER_API_KEY
    • Value: (paste your API key from the RankMonster app)
    • Type: Secret

Click Save and deploy after adding all three variables.

Step 5: Configure Custom Domain#

To place your Worker in front of your site's domain and begin recording bot traffic for the site, you'll need to configure Custom Domains on the Worker in Cloudflare.

  1. Go to your Cloudflare Dashboard → Domains → Overview → your website → Worker Routes → Add Route.
  2. Add your domain using wildcards and pick your new worker.
    • Example: yourdomain.com/*

Step 6: Verify Traffic#

Wait up to 5 minutes for your site to show as "Active" in RankMonster.

If your connection remains pending, click the Refresh button in the RankMonster status header. RankMonster will automatically fire a mock request to your domain to verify if logs are flowing. You can also run the Diagnostic Wizard from the Edge CDN panel menu to re-verify your configuration at any time.

👉 Once configured, your Cloudflare Worker will continuously forward logs to RankMonster, giving you real-time visibility into how LLM bots access your website.