Skip to main content
1

Install

2

Set your site key

.env
Never prefix it with NEXT_PUBLIC_. That inlines the value into the browser bundle, publishing a key that authorises writes for your whole site.
3

Create the beacon

beacon.ts
siteUrl decides which hostname hits are attributed to, so a wrong value mis-files everything.
4

Wire it into your proxy

proxy.ts
Verify:

A note on Vary

Next rewrites Vary on every document response for its own RSC cache, which drops the Vary: Accept the middleware adds. Markdown responses keep it, so Next’s own cache is fine. A shared CDN in front of Next could still serve a cached HTML page to a client that asked for Markdown. Either add Accept to the CDN’s cache key, or rely on the .md URLs, which are distinct URLs and need no Vary at all.

Static pages and CDN caching

Anything served from Vercel’s CDN without invoking your proxy is invisible, the same way a page cache is on any platform. Requests that reach your middleware are counted in full.