How I Built a First-Party Analytics Platform With Next.js Edge Middleware

Every third-party analytics tool has the same shape: a JavaScript snippet in the page, a beacon request back to a data collection endpoint, a dashboard that reads from their database. It works. It also adds a 20-50 KB script to every page, one extra network round trip, a tempting target for ad blockers, and a consent banner because the tool is now a third party processing user data.None of that is necessary. Next.js Edge Middleware runs on every request, on Vercel's edge network, before the page is served. If you capture analytics there, you have:No client-side script (zero extra KB)No beacon request (zero latency)No third-party domain (no ad blocker, no banner, no privacy officer
…