Middleware Setup
If you are using Next.js, use the Next.js integration instead — withCrawlReady from @crawlready/middleware/next already uses event.waitUntil() and is fully compatible with Vercel's Edge Runtime.
For non-Next.js projects deployed to Vercel Edge (e.g. a standalone middleware.ts with Vercel's edge functions), install the package:
npm install @crawlready/middleware
# or
pnpm add @crawlready/middleware
Create middleware.ts in your project root:
import { withCrawlReady } from '@crawlready/middleware/next';
import type { NextFetchEvent, NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
export const config = {
runtime: 'edge',
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};
const crawlreadyMiddleware = withCrawlReady({
siteKey: process.env.CRAWLREADY_SITE_KEY!,
});
export default function middleware(req: NextRequest, event: NextFetchEvent) {
return crawlreadyMiddleware(req, event);
}
Add your site key as a Vercel environment variable:
vercel env add CRAWLREADY_SITE_KEY
withCrawlReady uses event.waitUntil() to send the analytics beacon after the response is returned, which is the correct pattern for Vercel Edge — the function stays alive for the beacon without delaying the visitor.
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
| siteKey | string | required | Your site key from the CrawlReady dashboard (format: cr_live_*) |
| botFilter | 'ai-only' \| 'all' | 'ai-only' | Track only AI crawlers, or all 86+ known bots |
| endpoint | string | CrawlReady ingest URL | Override the ingest endpoint (useful for testing) |
| onBotDetected | function | — | Called before each ingest event; return false to suppress it |
Verify Your Integration
After deploying, use the Verify Integration button in your CrawlReady dashboard. It sends a synthetic GPTBot request to your site and confirms that a visit is recorded within 15 seconds.
If the check times out:
- Confirm
middleware.tsis in your project root. - Confirm the environment variable is added to the correct Vercel environment (Production/Preview/Development).
- Check your Vercel function logs for errors.
Going Further
- API Reference — trigger scans and retrieve scores programmatically
- Analytics Dashboard — understand your crawler traffic data
- Analytics Overview — what the metrics mean