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
-
Install
@waniwani/relay0.6.0 or later: -
In Vercel, open Settings › Environment Variables. Add the key from the setup screen as
WANIWANI_AGENT_TRAFFIC_KEYfor Production.
Next.js
Createproxy.ts next to your app or pages folder:
proxy.ts
proxy.ts or a middleware.ts, add the if block at the top of its function.
Other frameworks
Createproxy.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 thisproxy.ts. It also calls serveAgentPage:
proxy.ts
Deploy and check
Deploy to production. In the setup screen, enter the address of one of your pages and click Check now.Notes
recordAgentVisitdoes not stop the response. The event goes to Waniwani after the response, with thewaitUntilof 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" }.