Vercel Middleware
A small file in your project reports every AI visit. Works on any Vercel plan and any framework.
JoshUpdated 2 min readHow 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.
-
Install the package in the project that serves your site.
With another package manager, run
pnpm add,yarn addorbun add @bydefault/vercel. -
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.tsOn Next.js 15 or older, use the same code in
middleware.tsand name the functionmiddleware. On any other framework, leave outconfig:middleware.ts -
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 -
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
tracker.track(request) at the start of your function. Paths your matcher skips aren't tracked.Nothing arrives after deploying
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?