Install CiteRoute Telemetry
Choose the integration method that matches your architecture. Edge Middleware captures 100% of headless AI crawlers before page render, while the Client Script tag offers instant zero-code setup for static sites and CMSs.
import { NextResponse } from 'next/server';
import type { NextRequest, NextFetchEvent } from 'next/server';
const CITEROUTE_ENDPOINT = 'https://www.citeroute.com/api/v1/track';
const YOUR_DOMAIN = 'yourdomain.com'; // Replace with your domain
const AI_BOTS = [
'gptbot', 'claudebot', 'perplexitybot', 'bytespider', 'oai-searchbot',
'applebot-extended', 'google-extended', 'diffbot', 'cohere-ai', 'anthropic-ai'
];
export function middleware(request: NextRequest, event: NextFetchEvent) {
const ua = (request.headers.get('user-agent') || '').toLowerCase();
const referer = request.headers.get('referer') || '';
const isAiCrawler = AI_BOTS.some(bot => ua.includes(bot));
const isAiReferral = /chatgpt|perplexity|claude|gemini|copilot/i.test(referer);
// If non-human or AI referral, capture telemetry in background
if (isAiCrawler || isAiReferral) {
event.waitUntil(
fetch(CITEROUTE_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-forwarded-user-agent': request.headers.get('user-agent') || '',
'x-forwarded-referer': referer,
},
body: JSON.stringify({
domain: YOUR_DOMAIN,
path: request.nextUrl.pathname,
}),
}).catch(() => {})
);
}
// Attach diagnostic header so CiteRoute Verifier detects your middleware
const response = NextResponse.next();
response.headers.set('x-citeroute-tracked', '1');
return response;
}
export const config = {
matcher: ['/((?!api/|_next/static|_next/image|favicon.ico|robots.txt).*)'],
};Next.js Edge Middleware intercepts 100% of headless AI crawlers (GPTBot, ClaudeBot, etc.) before page render. Uses event.waitUntil() for zero added latency and sets an x-citeroute-tracked header for instant verification.
Verify your installation
Enter your domain and we'll probe whether Edge Middleware or the Tracking Tag is active.
Verify the installation
Open your site + DevTools
Network tab → filter "track". You should see a POST to citeroute.com/api/v1/track fire on page load.
Check the response
You will see:
{ "success": true, "recorded": false, "classification": "HUMAN" }All good
Human visits are not stored by design. AI crawlers appear in your analytics within 24–48 h. Run a GEO Audit to kick-start crawling.
FAQ
What is yourdomain.com?
Replace it with your actual domain - e.g. stripe.com or myblog.io. Do not include https:// or a trailing slash. This is how CiteRoute attributes AI traffic to your site.
Does it slow down my site?
No. The async attribute means it never blocks rendering. The beacon fires via navigator.sendBeacon on the load event - fire-and-forget, no response wait.
Is it GDPR / CCPA compliant?
Yes. No cookies. No IP addresses stored. No personal data collected. The only data sent is the URL path and an anonymous sessionStorage ID. Human visits are never written to the database.
I see recorded: false - is that normal?
Yes. Human visits are intentionally not stored. CiteRoute only persists AI crawler and agent traffic. recorded: false means the script is working correctly.
Do I need an API key?
No. The tag works without any account. API keys are only needed if you want to query the CiteRoute REST API directly.