LYRENTH
HomePricingIntegrationsDocsIndex statsAboutContact
/docs / bot-tracking
For verified site owners

The site-owner worker

An optional edge worker for verified domain owners. It reports AI agent visits from your CDN edge to Lyrenth, so your dashboard sees the full picture of who is reading your site, not just agents that route through our API. Two templates: Cloudflare and Vercel.

Reads

Known AI agents

Matches incoming User-Agents against a maintained list of AI crawlers and assistants.

Reports

Edge, not origin

Fires a non-blocking beacon from the edge. Zero added latency for your visitors.

Never

No user PII

Only bot User-Agent, path, and timestamp. No human visitor data is collected.

01

Verify your domain

You must have a verified domain first. Verify at /sites/add, then grab the worker token from your site settings.

02

Cloudflare Worker

Deploy this Worker route in front of your zone. It mirrors AI-agent requests to Lyrenth and passes everything else straight through.

worker.js
export default {
  async fetch(req, env, ctx) {
    const ua = req.headers.get("user-agent") || "";
    if (/GPTBot|ClaudeBot|AIWebIndex|PerplexityBot/i.test(ua)) {
      ctx.waitUntil(fetch("https://api.lyrenth.com/v1/visits", {
        method: "POST",
        headers: { "Authorization": `Bearer ${env.LYRENTH_WORKER_TOKEN}` },
        body: JSON.stringify({ ua, path: new URL(req.url).pathname, ts: Date.now() }),
      }));
    }
    return fetch(req); // pass through, never block
  },
};
03

Vercel Middleware

Drop this into middleware.ts at your project root. Same beacon, same non-blocking behavior.

middleware.ts
import { NextResponse } from "next/server";
export function middleware(req) {
  const ua = req.headers.get("user-agent") || "";
  if (/GPTBot|ClaudeBot|AIWebIndex|PerplexityBot/i.test(ua)) {
    fetch("https://api.lyrenth.com/v1/visits", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.LYRENTH_WORKER_TOKEN}` },
      body: JSON.stringify({ ua, path: req.nextUrl.pathname, ts: Date.now() }),
    }); // fire-and-forget
  }
  return NextResponse.next();
}
04

Watch the data land

Within a minute, AI-visit data appears under the Bot traffic panel of your site in the dashboard, broken down by agent, path, and time. Pair it with the index-side reads Lyrenth already tracks for the complete view.