Skip to main content
On Vercel, the relay is a proxy.ts file. Next.js runs it as its proxy. With a different framework, Vercel runs it as Routing Middleware. The code on this page is for the US region with Every page selected. Copy your code from the setup screen. It has your region and your paths.

Before you start

  1. Install @waniwani/relay 0.6.0 or later:
  2. In Vercel, open Settings › Environment Variables. Add the key from the setup screen as WANIWANI_AGENT_TRAFFIC_KEY for Production.

Next.js

Create proxy.ts next to your app or pages folder:
proxy.ts
If the project already has a proxy.ts or a middleware.ts, add the if block at the top of its function.

Other frameworks

Create proxy.ts at the root of your project. Use the same function, without config. Then add the proxy key to vercel.json (or vercel.ts):
vercel.json

With agent pages or blocking

When the website serves agent pages or blocks an agent, the setup screen gives you this proxy.ts. It also calls serveAgentPage:
proxy.ts
You make this change one time. After it, you turn agent pages and blocking on and off in the dashboard, with no deploy.

Deploy and check

Deploy to production. In the setup screen, enter the address of one of your pages and click Check now.

Notes

  • recordAgentVisit does not stop the response. The event goes to Waniwani after the response, with the waitUntil of Vercel.
  • With Only some paths, the matcher has your paths. /blog/* becomes /blog/:path*. Also add the paths of your agent pages.
  • In the EU region, each call gets { region: "eu" }.