# Capture AI crawlers on Vercel.

> Connect a Vercel site to Virent AI Crawler Analytics with a Log Drain (Pro and Enterprise) or Next.js middleware (any plan).

Canonical: https://virent.app/docs/integrations/vercel
Last updated: 2026-10-19

A Log Drain sends every request, including CDN-cached pages, without running your code. Middleware works on any plan but only sees requests that reach your app.

## Choose a method

| Method | Plans | Coverage |
| --- | --- | --- |
| [Log Drains](#log-drains) (recommended on Pro+) | Pro and Enterprise | Best coverage: includes CDN-cached pages without running application code |
| [Middleware](#middleware) | Any plan | Runs per matched request in Next.js 16+ `proxy.ts`; does not replace CDN request logs |

You need your site ID and server secret from **Settings → Connection** (see [Hosting integrations](/docs/integrations/overview#before-you-start)). In the dashboard, **Connect analytics → Hosting integrations → Vercel** shows these steps with your values filled in.

## Log Drains

### Set up with your coding agent

Paste this prompt into Claude Code, Codex or another coding agent. Replace the site ID and example.com with your own.

```text
Configure a Vercel Log Drain so example.com sends request logs to Virent AI crawler analytics.

Site ID: <your-site-id>
Use the full Virent server secret from the Connect dialog. Do not use the masked preview "vha_sk_••••" as the real value.

Steps:
1. In the Vercel dashboard, add a Logs drain for the project serving example.com.
2. Name it Virent Crawler Logs. Select that specific project.
3. Sources: Functions, Edge Functions, Static Files, Rewrites, Redirects. Environment: Production.
4. Destination: Custom Endpoint https://virent.app/api/ingest/vercel
5. Add an Authorization header with value: Bearer <paste-your-server-secret>
6. Keep delivery at 100% with no sampling rules, create the drain, then send a crawler request to example.com.

Do not commit the server secret.
```

### Choose data to drain

Open your team's drain settings in the [Vercel dashboard](https://vercel.com/dashboard). Click **Add Drain**, select **Logs**, then click **Next**.

### Configure the drain

| Setting | Value |
| --- | --- |
| Drain name | `Virent Crawler Logs` |
| Projects | **Specific Projects**: pick the project serving your site |
| Sources | Functions, Edge Functions, Static Files, Rewrites, Redirects |
| Environments | Production |

You do not need sampling rules. Continue with the defaults after selecting the project, sources and production environment.

### Configure the destination

Select **Custom Endpoint**, paste this URL, add a custom `Authorization` header with the value below (your server secret after `Bearer`), then click **Test**.

```text
https://virent.app/api/ingest/vercel
```

```text
Bearer <paste-your-server-secret>
```

### Create the drain

Keep delivery at 100% with no sampling rules, then click **Create Drain** at the end of the wizard. That is everything on Vercel's side. Send a [test crawler request](/docs/analytics/ai-crawlers#verify) to your site to confirm.

## Middleware

For Next.js 16+ on any Vercel plan. The [Next.js guide](/docs/installation/nextjs) covers the same proxy together with Human Analytics.

### Set up with your coding agent

Paste this prompt into Claude Code, Codex or another coding agent. Replace the site ID and example.com with your own.

```text
Install Virent AI crawler analytics on example.com with Vercel middleware (Next.js proxy.ts).

Site ID: <your-site-id>
Use the full Virent server secret from the Connect dialog. Do not use the masked preview "vha_sk_••••" as the real value.

Steps:
1. Run npm install @virent.app/sdk@^0.3.0 in the project serving the site.
2. Add proxy.ts at the project root, or src/proxy.ts if the app uses a src directory. Use createVirentBotProxy with endpoint: process.env.VIRENT_INGEST_ENDPOINT and report in event.waitUntil so the response is never blocked. Do not rely on the SDK default endpoint; use the exact Virent environment below.
3. Set these environment variables locally and in Vercel:
VIRENT_SITE_ID=<your-site-id>
VIRENT_INGEST_SECRET=<paste-your-server-secret>
VIRENT_INGEST_ENDPOINT=https://virent.app/v1/ingest/bot
4. Deploy the site to Vercel, then send a crawler request to example.com. Confirm the ingest request is accepted and appears in this Virent environment; an HTTP 200 from the website alone does not verify analytics delivery.

This is server-side crawler tracking, not browser analytics. Do not hard-code the secret.
```

### Install the package

Run this in the project serving your site:

```sh
npm install @virent.app/sdk
```

### Add the proxy

Create `proxy.ts` at the project root, or inside `src` if the project uses a `src` directory. The helper reports in `event.waitUntil`, after the response path is released.

```typescript
// proxy.ts
import { createVirentBotProxy } from "@virent.app/sdk/next"

export const proxy = createVirentBotProxy({
	  siteId: "<your-site-id>",
	  writeKey: process.env.VIRENT_INGEST_SECRET!,
	  endpoint: process.env.VIRENT_INGEST_ENDPOINT || "https://virent.app/v1/ingest/bot",
	  trustedProxy: "vercel",
	})

export const config = {
  matcher: [
    "/((?!api|_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.(?:png|jpg|jpeg|gif|svg|ico|webp|css|js|map)$).*)",
  ],
}
```

### Set environment variables

Add these values locally and in **Settings → Environment Variables** on Vercel, so the deployed site can report securely.

```env
VIRENT_SITE_ID=<your-site-id>
VIRENT_INGEST_SECRET=<paste-your-server-secret>
VIRENT_INGEST_ENDPOINT=https://virent.app/v1/ingest/bot
```

### Deploy

Push to GitHub or deploy from the Vercel CLI, then send a [test crawler request](/docs/analytics/ai-crawlers#verify).

```sh
vercel deploy --prod
```
