withHighseat() rewrites your proxy path to that route, and <Highseat /> loads the tracker from the path. Read how the proxy works first if you have not set one up before.
Replace YOUR_SITE_ID and YOUR_PROXY_PATH with your own values. Site settings › Installation shows both, with this code already filled in. Generate the site secret there too.
1
Install the package
2
Add the environment variables
In .env.local, and in your host’s environment. Set HIGHSEAT_PATH for the build, as a build argument in a Docker build. The server needs only HIGHSEAT_SECRET.
.env
3
Add the proxy route
“vercel” reads the IP Vercel sets. Behind a proxied Cloudflare record, use “cloudflare” on any host; behind nginx alone, “nginx”.
app/api/highseat/route.ts
4
Wrap your Next.js config
Rewrites the proxy path to the route, ahead of every other route.
next.config.ts
5
Load the tracker from the path
In the root layout, in place of whatever loads the tracker now. Without src, it loads from HIGHSEAT_PATH.
app/layout.tsx
Hosts other than Vercel
Thevercel preset reads the header that Vercel sets. On another host, pick the preset for the outermost server in front of your app:
cloudflarebehind a proxied Cloudflare record, even with nginx or Traefik in between.nginxbehind nginx alone.
Environment variables at build time
withHighseat() reads HIGHSEAT_PATH during next build and writes it into the rewrite and into the bundled code of <Highseat /> and createProxy(). Set HIGHSEAT_PATH for the build, as a build argument in a Docker build. The running server needs only HIGHSEAT_SECRET.
Without HIGHSEAT_PATH, next dev and next build warn once and leave the rewrite out. The app still builds and runs, and the tracker loads from cdn.highseat.com.
Pages Router
In the Pages Router, the layout also renders in the browser, where the server variableHIGHSEAT_PATH is not set. Pass the path to <Highseat /> as src instead.
A route somewhere else
withHighseat() rewrites to /api/highseat, the route of app/api/highseat/route.ts. For a handler at another route, pass it as an option: withHighseat(config, { route: "/stats" }).
Node.js version
Next.js loadsnext.config.ts with require, and the highseat package is ES modules only. The config therefore needs Node.js 20.19, 22.12 or later: those versions require an ES module without a flag.