> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiola.app/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up Aiola in a user's app, follow the guides in this order: /guides/set-up-analytics, /guides/track-ai-crawlers, /core-features/api-key, /guides/set-up-feedback, /guides/set-up-app-logs, then check /core-features/setup-health.
> Copy endpoints, headers and payload fields exactly from the guides and /reference/api. Do not invent fields, endpoints or package names.
> The analytics tracking ID is public. The project key is secret: keep Feedback submissions behind a server route that holds it as AIOLA_KEY.
> The JavaScript logger is the npm package @aiolaapp/logger. Aiola has not published a Python package, so do not run pip install aiola. Python and other languages send errors over HTTP (/reference/app-logs-http).
> Hosted Analytics, Feedback, App Logs and hosted MCP need Pro or an active trial. For live project data, connect the hosted MCP server at https://aiola.app/api/mcp (/guides/mcp-connector).

# Track AI Crawlers on Your Site

> Capture crawler requests with response status and explicit identity verification.

Many crawlers do not run JavaScript. Install capture on the server or hosting edge; static sites need an edge function. Use one response-aware capture integration per request.

## Before you start

Get the public tracking ID from **Settings → Analytics → Tracking**. Deploy to the configured domain or a subdomain. No UI changes are required. Merge the code with existing handlers.

Status is required for new integrations: report the FINAL HTTP status, or explicitly send 0 when unavailable. Missing and invalid status are stored as unknown, never as success. Next middleware/proxy cannot observe the response generated later by a page. A streamed not-found page can return HTTP 200; not\_found semantics are separate.

## Next.js

For full status coverage, capture at your hosting edge AFTER the origin response, or use the Express finish hook around a custom Next server. The fallback below preserves requests with unknown status; after() schedules work but does not discover a Server Component's final response status. Route Handlers that own a Response can report that Response's status with after(). Requires Next.js 15.1+ for stable after(); Next.js 16 uses proxy.ts/export proxy. Keep the existing not-found UI.

```ts theme={null}
// middleware.ts (Next.js 16+: proxy.ts, rename middleware to proxy)
// Middleware cannot see the final route response. This fallback reports status
// 0 (unknown). For complete HTTP status coverage use the Express finish hook
// around your Next server or a hosting-edge response hook. Set
// AIOLA_FINAL_STATUS_CAPTURE=1 only after that hook covers EVERY request.
import { NextResponse } from "next/server"
import type { NextFetchEvent, NextRequest } from "next/server"
// aiola-bot-tracking v3
const BOT_RE = /(?:(?:^|[\s;(])(?:ChatGPT-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGPT-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-AdsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GPTBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ClaudeBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:anthropic-ai)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Perplexity-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PerplexityBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Training)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Index)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Grok-DeepSearch)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GrokBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Web-Crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Grok)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-GeminiNotebook|Google-NotebookLM)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Read-Aloud)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Agent|GoogleAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-InspectionTool)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-CloudVertexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GoogleOther)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Googlebot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Applebot(?!-Extended))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Copilot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingBot|bingbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:msnbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:NovaAct)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amazonbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TikTokSpider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Bytespider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Doubaobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalFetcher|meta-externalfetcher)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-webindexer)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-externalads)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:facebookexternalhit)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:CCBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:cohere-ai|cohere-training-data-crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckAssistBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaSearchBot(?:-Images)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaUser)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YouBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:KimiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwen-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QwenBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TongyiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AliyunBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Baiduspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ERNIEBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YiyanBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGLM-Spider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DeepSeekBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot\-Dolma)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FirecrawlAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Timpibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ImagesiftBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinerBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QualifiedBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexAdditional(Bot)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kagibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckDuckBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SeznamBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PetalBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwantbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdsBot-Google[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Storebot\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Safety)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:APIs\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FeedFetcher\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Site\-Verification)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdIdxBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MicrosoftPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingVideoPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:yisouspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:iTMS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Yandex[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Sogou[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exabot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exalead)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Twitterbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinkedInBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:WhatsApp(?=\/))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TelegramBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Discordbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Mediapartners[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SemrushBot[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Semrush[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AhrefsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MJ12bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DotBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Chrome\-Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PageSpeed)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GTmetrix)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Pingdom)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:UptimeRobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HeadlessChrome)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PhantomJS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Cloudflare\-AI\-Search\-External)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgilibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgili)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Webzio\-Extended)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AmazonBuyForMe)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FacebookBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Liner-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Manus-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HarkBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Shap-User)(?![A-Za-z0-9_-]))|(?:^|[\s;(])((?!CUBOT(?:[/\s;)]|$))[A-Za-z0-9_-]*(?:bot|crawler|spider|slurp)[A-Za-z0-9_-]*|Google-Extended)(?=[/\s;)]|$)/i
const ASSET_RE = /\.(png|jpe?g|gif|webp|avif|svg|ico|css|js|mjs|map|woff2?|ttf|otf|eot|webmanifest|mp4|webm)$/i
const isChatGPTAgent = function isChatGPTAgent(value = "") {
    try {
        const url = new URL(value.trim().replace(/^"|"$/g, ""));
        return url.protocol === "https:" && url.hostname === "chatgpt.com" && !url.username && !url.password && (!url.port || url.port === "443");
    }
    catch {
        return false;
    }
}
const purpose = (h: Headers) => [h.get("sec-purpose") || h.get("purpose"), h.get("rsc") === "1" ? "rsc" : ""].filter(Boolean).join(";")
// Never put the optional server key in browser code. Only forward an IP from
// your hosting provider's trusted connection metadata, not arbitrary headers.
const sendBot = async (body: Record<string, unknown>, key: string | undefined) => {
  const response = await fetch("https://aiola.app/api/bot-crawl-ingest", {
    method: "POST", headers: { "Content-Type": "application/json", ...(key ? { "X-Aiola-Server-Key": key } : {}) },
    body: JSON.stringify({ tracking_id: "YOUR_TRACKING_ID", ...body }),
  })
  if (!response.ok) throw new Error("Aiola crawler capture failed: " + response.status)
}

export function middleware(req: NextRequest, ev: NextFetchEvent) {
  const h = new Headers(req.headers), request_id = crypto.randomUUID()
  h.set("x-aiola-request-id", request_id)
  h.set("x-aiola-path", req.nextUrl.pathname)
  h.set("x-aiola-method", req.method)
  const ua = h.get("user-agent") || "", signature_agent = h.get("signature-agent") || ""
  if (process.env.AIOLA_FINAL_STATUS_CAPTURE !== "1" && (BOT_RE.test(ua) || isChatGPTAgent(signature_agent)) && !ASSET_RE.test(req.nextUrl.pathname)) {
    ev.waitUntil(sendBot({ request_id, url_path: req.nextUrl.pathname, url_host: req.nextUrl.hostname,
      ua, signature_agent, status: 0, http_method: req.method, request_purpose: purpose(h),
      is_test: h.get("x-aiola-test") === "1",
    }, process.env.AIOLA_BOT_SERVER_KEY).catch(error => console.error(error)))
  }
  return NextResponse.next({ request: { headers: h } })
}
export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] }

// lib/aiola-response.ts — separate file, for Route Handlers owning a Response.
// This supplements the middleware fallback using the SAME request ID. It does
// not cover Server Components; use a hosting response hook for those.
import { after } from "next/server"
import type { NextRequest } from "next/server"
// aiola-bot-tracking v3
const BOT_RE = /(?:(?:^|[\s;(])(?:ChatGPT-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGPT-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-AdsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GPTBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ClaudeBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:anthropic-ai)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Perplexity-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PerplexityBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Training)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Index)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Grok-DeepSearch)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GrokBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Web-Crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Grok)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-GeminiNotebook|Google-NotebookLM)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Read-Aloud)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Agent|GoogleAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-InspectionTool)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-CloudVertexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GoogleOther)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Googlebot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Applebot(?!-Extended))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Copilot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingBot|bingbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:msnbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:NovaAct)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amazonbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TikTokSpider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Bytespider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Doubaobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalFetcher|meta-externalfetcher)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-webindexer)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-externalads)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:facebookexternalhit)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:CCBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:cohere-ai|cohere-training-data-crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckAssistBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaSearchBot(?:-Images)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaUser)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YouBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:KimiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwen-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QwenBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TongyiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AliyunBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Baiduspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ERNIEBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YiyanBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGLM-Spider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DeepSeekBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot\-Dolma)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FirecrawlAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Timpibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ImagesiftBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinerBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QualifiedBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexAdditional(Bot)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kagibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckDuckBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SeznamBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PetalBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwantbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdsBot-Google[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Storebot\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Safety)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:APIs\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FeedFetcher\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Site\-Verification)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdIdxBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MicrosoftPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingVideoPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:yisouspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:iTMS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Yandex[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Sogou[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exabot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exalead)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Twitterbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinkedInBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:WhatsApp(?=\/))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TelegramBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Discordbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Mediapartners[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SemrushBot[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Semrush[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AhrefsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MJ12bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DotBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Chrome\-Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PageSpeed)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GTmetrix)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Pingdom)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:UptimeRobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HeadlessChrome)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PhantomJS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Cloudflare\-AI\-Search\-External)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgilibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgili)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Webzio\-Extended)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AmazonBuyForMe)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FacebookBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Liner-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Manus-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HarkBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Shap-User)(?![A-Za-z0-9_-]))|(?:^|[\s;(])((?!CUBOT(?:[/\s;)]|$))[A-Za-z0-9_-]*(?:bot|crawler|spider|slurp)[A-Za-z0-9_-]*|Google-Extended)(?=[/\s;)]|$)/i
const ASSET_RE = /\.(png|jpe?g|gif|webp|avif|svg|ico|css|js|mjs|map|woff2?|ttf|otf|eot|webmanifest|mp4|webm)$/i
const isChatGPTAgent = function isChatGPTAgent(value = "") {
    try {
        const url = new URL(value.trim().replace(/^"|"$/g, ""));
        return url.protocol === "https:" && url.hostname === "chatgpt.com" && !url.username && !url.password && (!url.port || url.port === "443");
    }
    catch {
        return false;
    }
}
const purpose = (h: Headers) => [h.get("sec-purpose") || h.get("purpose"), h.get("rsc") === "1" ? "rsc" : ""].filter(Boolean).join(";")
// Never put the optional server key in browser code. Only forward an IP from
// your hosting provider's trusted connection metadata, not arbitrary headers.
const sendBot = async (body: Record<string, unknown>, key: string | undefined) => {
  const response = await fetch("https://aiola.app/api/bot-crawl-ingest", {
    method: "POST", headers: { "Content-Type": "application/json", ...(key ? { "X-Aiola-Server-Key": key } : {}) },
    body: JSON.stringify({ tracking_id: "YOUR_TRACKING_ID", ...body }),
  })
  if (!response.ok) throw new Error("Aiola crawler capture failed: " + response.status)
}

export function withAiolaBotCapture(handler: (req: NextRequest) => Response | Promise<Response>) {
  return async function captured(req: NextRequest) {
    const response = await handler(req)
    const h = req.headers, url = new URL(req.url), ua = h.get("user-agent") || ""
    const signature_agent = h.get("signature-agent") || ""
    if ((BOT_RE.test(ua) || isChatGPTAgent(signature_agent)) && !ASSET_RE.test(url.pathname)) {
      const request_id = h.get("x-aiola-request-id") || crypto.randomUUID()
      after(() => sendBot({ request_id, url_path: url.pathname, url_host: url.hostname,
        ua, signature_agent, status: response.status, http_method: req.method,
        request_purpose: purpose(h), is_test: h.get("x-aiola-test") === "1",
      }, process.env.AIOLA_BOT_SERVER_KEY).catch(error => console.error(error)))
    }
    return response
  }
}
// In an existing Route Handler: export const GET = withAiolaBotCapture(yourHandler)
// after() schedules work; it does not discover a Server Component's status.

// app/not-found.tsx — merge this logic into the EXISTING component, preserve UI.
// Read headers BEFORE after(). Reuse the middleware request ID. A streamed
// not-found page can return HTTP 200: report semantics separately as below.
// const h = await headers()
// after(() => sendBot({ request_id: h.get("x-aiola-request-id"),
//   url_path: h.get("x-aiola-path"), url_host: (h.get("host") || "").split(":")[0],
//   ua: h.get("user-agent"), signature_agent: h.get("signature-agent"),
//   status: 0, not_found: true, http_method: h.get("x-aiola-method") || "GET",
//   request_purpose: purpose(h), is_test: h.get("x-aiola-test") === "1",
// }, process.env.AIOLA_BOT_SERVER_KEY))
// Apply the bot/asset guard. Use only when middleware capture is active; a
// complete response hook is authoritative. Query-time ID dedupe is required.

```

## Cloudflare Pages

The cf-connecting-ip header is trustworthy only on requests received directly through Cloudflare, where the provider overwrites it. Use trusted platform metadata, never a visitor-supplied forwarded-IP header. A generic verifiedBot signal alone does not identify a vendor.

```js theme={null}
// functions/_middleware.js — Cloudflare Pages
// aiola-bot-tracking v3
const BOT_RE = /(?:(?:^|[\s;(])(?:ChatGPT-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGPT-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-AdsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GPTBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ClaudeBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:anthropic-ai)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Perplexity-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PerplexityBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Training)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Index)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Grok-DeepSearch)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GrokBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Web-Crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Grok)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-GeminiNotebook|Google-NotebookLM)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Read-Aloud)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Agent|GoogleAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-InspectionTool)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-CloudVertexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GoogleOther)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Googlebot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Applebot(?!-Extended))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Copilot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingBot|bingbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:msnbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:NovaAct)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amazonbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TikTokSpider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Bytespider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Doubaobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalFetcher|meta-externalfetcher)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-webindexer)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-externalads)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:facebookexternalhit)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:CCBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:cohere-ai|cohere-training-data-crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckAssistBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaSearchBot(?:-Images)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaUser)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YouBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:KimiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwen-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QwenBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TongyiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AliyunBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Baiduspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ERNIEBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YiyanBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGLM-Spider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DeepSeekBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot\-Dolma)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FirecrawlAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Timpibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ImagesiftBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinerBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QualifiedBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexAdditional(Bot)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kagibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckDuckBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SeznamBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PetalBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwantbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdsBot-Google[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Storebot\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Safety)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:APIs\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FeedFetcher\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Site\-Verification)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdIdxBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MicrosoftPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingVideoPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:yisouspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:iTMS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Yandex[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Sogou[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exabot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exalead)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Twitterbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinkedInBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:WhatsApp(?=\/))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TelegramBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Discordbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Mediapartners[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SemrushBot[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Semrush[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AhrefsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MJ12bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DotBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Chrome\-Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PageSpeed)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GTmetrix)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Pingdom)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:UptimeRobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HeadlessChrome)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PhantomJS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Cloudflare\-AI\-Search\-External)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgilibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgili)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Webzio\-Extended)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AmazonBuyForMe)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FacebookBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Liner-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Manus-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HarkBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Shap-User)(?![A-Za-z0-9_-]))|(?:^|[\s;(])((?!CUBOT(?:[/\s;)]|$))[A-Za-z0-9_-]*(?:bot|crawler|spider|slurp)[A-Za-z0-9_-]*|Google-Extended)(?=[/\s;)]|$)/i
const ASSET_RE = /\.(png|jpe?g|gif|webp|avif|svg|ico|css|js|mjs|map|woff2?|ttf|otf|eot|webmanifest|mp4|webm)$/i
const isChatGPTAgent = function isChatGPTAgent(value = "") {
    try {
        const url = new URL(value.trim().replace(/^"|"$/g, ""));
        return url.protocol === "https:" && url.hostname === "chatgpt.com" && !url.username && !url.password && (!url.port || url.port === "443");
    }
    catch {
        return false;
    }
}
const purpose = (h) => [h.get("sec-purpose") || h.get("purpose"), h.get("rsc") === "1" ? "rsc" : ""].filter(Boolean).join(";")
// Never put the optional server key in browser code. Only forward an IP from
// your hosting provider's trusted connection metadata, not arbitrary headers.
const sendBot = async (body, key) => {
  const response = await fetch("https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/bot-crawl-ingest", {
    method: "POST", headers: { "Content-Type": "application/json", ...(key ? { "X-Aiola-Server-Key": key } : {}) },
    body: JSON.stringify({ tracking_id: "YOUR_TRACKING_ID", ...body }),
  })
  if (!response.ok) throw new Error("Aiola crawler capture failed: " + response.status)
}

export async function onRequest(context) {
  const request_id = crypto.randomUUID()
  const req = context.request, url = new URL(req.url), h = req.headers
  const ua = h.get("user-agent") || "", signature_agent = h.get("signature-agent") || ""
  const shouldCapture = (BOT_RE.test(ua) || isChatGPTAgent(signature_agent)) && !ASSET_RE.test(url.pathname)
  // context.next() observes the origin response, including redirects and errors.
  // If the framework throws, let the outer error handler construct its final
  // response and capture there; never invent a 200.
  const response = await context.next()
  if (shouldCapture) context.waitUntil(sendBot({
    request_id, url_path: url.pathname, url_host: url.hostname, ua, signature_agent,
    status: response.status, http_method: req.method, request_purpose: purpose(h),
    requester_ip: h.get("cf-connecting-ip") || "", country: req.cf?.country || "",
    is_test: h.get("x-aiola-test") === "1",
    // verifiedBot alone does not identify a vendor; CIDR verification is used.
  }, context.env.AIOLA_BOT_SERVER_KEY).catch(error => console.error(error)))
  return response
}
```

## Express

Configure trust proxy to specific trusted hops. Use an always-running Node 20+ process or a hosting-supported background task. res.statusCode inside finish is final. Do not use a status captured before routing.

```js theme={null}
// Register before routes and static handlers. Node 20+.
// aiola-bot-tracking v3
const BOT_RE = /(?:(?:^|[\s;(])(?:ChatGPT-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGPT-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:OAI-AdsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GPTBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Claude-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ClaudeBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:anthropic-ai)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Perplexity-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PerplexityBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Training)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MistralAI-Index)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Grok-DeepSearch)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GrokBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Web-Crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Grok)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:xAI-Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-GeminiNotebook|Google-NotebookLM)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Read-Aloud)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-Agent|GoogleAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-InspectionTool)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google-CloudVertexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GoogleOther)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Googlebot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Applebot(?!-Extended))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Copilot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingBot|bingbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:msnbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:NovaAct)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amzn-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Amazonbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TikTokSpider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Bytespider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Doubaobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalFetcher|meta-externalfetcher)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-webindexer)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:meta-externalads)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:facebookexternalhit)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Meta-ExternalAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:CCBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:cohere-ai|cohere-training-data-crawler)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckAssistBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaSearchBot(?:-Images)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ExaUser)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YouBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-SearchBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:KimiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwen-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QwenBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TongyiBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AliyunBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Baiduspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ERNIEBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YiyanBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ChatGLM-Spider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DeepSeekBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot\-Dolma)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AI2Bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Diffbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FirecrawlAgent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Timpibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:ImagesiftBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinerBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:QualifiedBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexAdditional(Bot)?)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:YandexBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kagibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DuckDuckBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SeznamBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PetalBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Qwantbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdsBot-Google[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Storebot\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Safety)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:APIs\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FeedFetcher\-Google)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Google\-Site\-Verification)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AdIdxBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MicrosoftPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:BingVideoPreview)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:yisouspider)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:iTMS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Yandex[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Sogou[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exabot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Exalead)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Twitterbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:LinkedInBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:WhatsApp(?=\/))(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:TelegramBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Discordbot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Mediapartners[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:SemrushBot[-A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Semrush[A-Za-z]*)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AhrefsBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:MJ12bot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:DotBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Chrome\-Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Lighthouse)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PageSpeed)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:GTmetrix)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Pingdom)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:UptimeRobot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HeadlessChrome)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:PhantomJS)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Cloudflare\-AI\-Search\-External)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgilibot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Omgili)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Webzio\-Extended)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:AmazonBuyForMe)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:FacebookBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Kimi-Agent)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Liner-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Manus-User)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:HarkBot)(?![A-Za-z0-9_-]))|(?:(?:^|[\s;(])(?:Shap-User)(?![A-Za-z0-9_-]))|(?:^|[\s;(])((?!CUBOT(?:[/\s;)]|$))[A-Za-z0-9_-]*(?:bot|crawler|spider|slurp)[A-Za-z0-9_-]*|Google-Extended)(?=[/\s;)]|$)/i
const ASSET_RE = /\.(png|jpe?g|gif|webp|avif|svg|ico|css|js|mjs|map|woff2?|ttf|otf|eot|webmanifest|mp4|webm)$/i
const isChatGPTAgent = function isChatGPTAgent(value = "") {
    try {
        const url = new URL(value.trim().replace(/^"|"$/g, ""));
        return url.protocol === "https:" && url.hostname === "chatgpt.com" && !url.username && !url.password && (!url.port || url.port === "443");
    }
    catch {
        return false;
    }
}
const purpose = (h) => [h.get("sec-purpose") || h.get("purpose"), h.get("rsc") === "1" ? "rsc" : ""].filter(Boolean).join(";")
// Never put the optional server key in browser code. Only forward an IP from
// your hosting provider's trusted connection metadata, not arbitrary headers.
const sendBot = async (body, key) => {
  const response = await fetch("https://aiola.app/api/bot-crawl-ingest", {
    method: "POST", headers: { "Content-Type": "application/json", ...(key ? { "X-Aiola-Server-Key": key } : {}) },
    body: JSON.stringify({ tracking_id: "YOUR_TRACKING_ID", ...body }),
  })
  if (!response.ok) throw new Error("Aiola crawler capture failed: " + response.status)
}

app.use((req, res, next) => {
  const request_id = crypto.randomUUID(), ua = req.get("user-agent") || ""
  const signature_agent = req.get("signature-agent") || "", path = req.path || "/"
  if ((BOT_RE.test(ua) || isChatGPTAgent(signature_agent)) && !ASSET_RE.test(path)) {
    // Configure Express trust proxy to ONLY the actual trusted proxy hops.
    const requester_ip = req.ip || req.socket.remoteAddress || ""
    res.once("finish", () => {
      void sendBot({ request_id, url_path: path, url_host: req.hostname, ua, signature_agent,
        status: res.statusCode, http_method: req.method,
        request_purpose: req.get("sec-purpose") || req.get("purpose") || (req.get("rsc") === "1" ? "rsc" : ""),
        requester_ip, is_test: req.get("x-aiola-test") === "1",
      }, process.env.AIOLA_BOT_SERVER_KEY).catch(error => console.error(error))
    })
  }
  next()
})
```

## Identity and delivery

UA and Signature-Agent names are **claimed**, not proof of a vendor request or a validated HTTP signature. Optional X-Aiola-Server-Key authenticates server capture. Keep the key server-side and forward requester\_ip from the original trusted connection. Only then may vendor CIDR matches or a provider-attested exact bot identity become verified. A mismatch with a current published list is failed; unavailable lists stay claimed. Meta has no public machine-readable crawler CIDR list supported here, so its requests stay claimed unless the authenticated server supplies the exact provider-verified identity. Broad cloud/ASN ranges are not bot identity proof.

Keys are stored as hashes in a service-only Supabase table. Issuance/rotation through an existing settings action is proposed; no key issuance control is added in this change. Existing integrations work without a key and stay claimed.

Create request\_id once per incoming request. Reuse it for retries, middleware/response updates and semantic not-found updates. Storage is append-only: query-time dedupe must be installed before counts can be called deduplicated. Browser event\_id can be forwarded as the shared ID; otherwise choose server capture and set bot\_capture\_mode:server on collector bot pageviews. Without a common ID, independent browser and server telemetry cannot be reliably merged.

PDFs and JSON are content, as are robots.txt, llms.txt and sitemap XML. Record HEAD, prefetch and RSC with http\_method/request\_purpose; they are requests rather than full page reads. Scanner/probe paths retain the claimed bot name but have kind scanner, category other and is\_ai=0. Unknown bot tokens are retained as Unknown bot (token).

Ingestion waits for Tinybird's row acknowledgement. Delivery errors are logged and return 502; retry with the SAME ID. Hourly Supabase health counters record accepted, written, dropped and failed per site/source, independently of Tinybird. A written counter is a write acknowledgement, not a unique-request total.

## Check it works

```bash theme={null}
curl -A 'GPTBot/1.4' -H 'X-Aiola-Test: 1' https://example.com/
```

Forward the header as is\_test:true (all snippets do). This is a simulated claimed identity, not a verified vendor request. Test rows are excluded from totals by the reporting contract; inspect capture logs, the ingest response, raw rows with is\_test=1 and health counters instead. Test an existing page, redirect, blocked URL and missing page, and verify the final HTTP codes. Do not expect tests in totals cards. Deploy reporting filters before exercising tests.

## Reporting and history

Legacy capture\_version=0 rows with default status 200 count as fetched for AI coverage and distinct breadth, with **status not reported**. They never count as reported successes or prove an absence of errors. Explicit legacy non-200 error codes remain errors. New v1 success requires status\_known=1 and a 2xx status; unknown v1 responses remain fetched requests with status not reported and receive no success credit.

Crawler lists return 50 rows initially, reveal ten at a time on scroll, and fetch the long tail once using the same 10,000-row deep-query mechanism as human lists. There is no top-N presentation cutoff; this is a bounded fetch, not a promise of unlimited results. Ranking and shares use the full matching population. MCP full:true requests up to 10,000 rows and discloses listCap/capReached. Coverage joins all retained human host/path pairs directly, without a capped or comma-separated candidate list. Failed sections are unavailable, never zero, “no errors”, or “every page crawled”; partial results are not cached. All time starts at the earliest retained human event or non-test crawl within five years; long ranges use week/month buckets.

## AI referrals

AI referrals attribute each measured session using its first pageview in the selected window, before page/dimension segmentation. Views count pageviews in attributed sessions; visitors are distinct visitor keys. Use the summary for the unique visitor total: do not sum assistant rows. Sessions beginning before the window cannot recover earlier entry attribution. Missing referrers or tags do not prove no AI visits or no citation.

Hosts are normalized (case, trailing dots and URL syntax) and match the exact host or DNS subdomains: chatgpt.com, chat.openai.com, perplexity.ai, claude.ai, gemini.google.com, bard.google.com, copilot.microsoft.com, copilot.cloud.microsoft, copilot.com, grok.com, grok.x.ai, meta.ai, chat.deepseek.com, chat.mistral.ai, you.com, poe.com, phind.com, doubao.com, notebooklm.google.com, notebook.google.com, chat.qwen.ai, tongyi.aliyun.com, chat.baidu.com, yiyan.baidu.com, wenxin.baidu.com, kimi.com, kimi.moonshot.cn, duck.ai, yuanbao.tencent.com, chatglm.cn, genspark.ai, felo.ai, monica.im and t3.chat. huggingface.co requires /chat or /chat/; kagi.com requires /assistant or /assistant/. Generic corporate hosts openai.com, x.ai, deepseek.com and mistral.ai do not qualify. Only exact normalized utm\_source tokens chatgpt.com and perplexity are accepted. Attribution tags are signals, not authenticated identity.

## Endpoint contract

POST [https://aiola.app/api/bot-crawl-ingest](https://aiola.app/api/bot-crawl-ingest) with JSON: tracking\_id, url\_path, url\_host, ua, status, request\_id, http\_method, request\_purpose, is\_test; optional signature\_agent, country, requester\_ip, not\_found and authenticated cf\_verified\_bot/cf\_verified\_bot\_name. Cloudflare sites in Aiola's zone use the direct Supabase URL in the snippet.

A 204 confirms a write for recognized bots; non-bot UAs are ignored. A 502 is a delivery failure. Unauthenticated beacons are accepted as claimed for backward compatibility. See [crawler identities](https://docs.aiola.app/reference/bot-crawlers.md) and [API](https://docs.aiola.app/reference/api.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.