AI crawler analytics

Vercel Middleware

A small file in your project reports every AI visit. Works on any Vercel plan and any framework.

JoshUpdated 2 min read

How it works

Vercel runs a middleware file for every request your site serves. ByDefault's middleware reports the requests that come from AI tools asynchronously, so there is no performance impact.

It works on any Vercel plan and any framework, static and client-rendered sites included.

Set up the middleware

In ByDefault, open Analytics, click Connect your site, then pick Vercel and Middleware. Keep it open: it has your token and tells you when the middleware works.

  1. Install the package in the project that serves your site.

    With another package manager, run pnpm add, yarn add or bun add @bydefault/vercel.

  2. Create the middleware file at the project root. On Next.js, put it inside src/ if your project uses one. The file's name depends on your framework:

    On Next.js 16 or newer:

    proxy.ts

    On Next.js 15 or older, use the same code in middleware.ts and name the function middleware. On any other framework, leave out config:

    middleware.ts
  3. Add your token to .env.local, and under Settings → Environment Variables on your Vercel project, so the deployed site has it too. The setup shows the line with your token in it.

    .env.local
  4. Push to GitHub, or run vercel deploy --prod.

Check the connection

While the setup is open, ByDefault visits your site the way an AI assistant would, every few seconds. When the deployed middleware first reports, the last step reads Your middleware reached us. Once it reports our visit, the step turns green.

Troubleshooting

My project already has a middleware file

Keep the one file. Add the import and the tracker to it, then call tracker.track(request) at the start of your function. Paths your matcher skips aren't tracked.

Nothing arrives after deploying

Check that BYDEFAULT_TOKEN is set for Production on Vercel and that you deployed after adding it. On Next.js 15 or older, a file named proxy.ts never runs, so name it middleware.ts.

Did this answer your question?

Turn AI search into your most profitable sales channel.