who came. what broke.

Vercel already counts your visitors, on Vercel's dashboard. This step copies two streams of that data into your own database instead: page views, which pages people read and where they came from, and traces, how long each request took and which ones failed. You read both at /admin/observability on your own site, and the data is yours to keep.

StreamWeb Analytics drain
Tells youPages, visitors, countries, browsers
Arrives at/api/analytics/vercel
StreamTraces drain
Tells youSpeed, slow pages, errors
Arrives at/api/drains/traces
StreamGoogle Analytics (optional)
Tells youGoogle's own reports
Arrives atGoogle, not your database
  • Drains need Vercel Pro — the free Hobby plan cannot add them. On Pro, drained data costs $0.50 per GB. A small site sends very little
  • Only visitors who say yes are counted — analytics loads after someone accepts your cookie banner. People who reject it are never tracked
  • 30 days, then it is gone — a daily job deletes page views and traces older than 30 days, and trace details after 7, so your database stays small
BUILD.

✓ Success: your own visit shows up in /admin/observability.

this is a work in progress

  • Your site live on your domain — from Deploy and Your domain. The cleanup job uses the CRON_SECRET you made there
  • You are an admin — from Make yourself admin. /admin/observability is admin only
  • A Vercel Pro team — in Vercel, open Settings → Billing to upgrade

1️⃣ Web Analytics and One Secret

  1. In Vercel, open your project and click Analytics in the sidebar
  2. Click Enable. It starts with your next deploy
  3. Open Terminal and run openssl rand -hex 32. Copy the long line it prints: this is your drain secret

Both drains sign everything they send with this secret, and your site throws away anything unsigned. Put it in .env, add it to Vercel's Environment Variables for Production, then redeploy:

bash
# .env
DRAIN_SECRET="the line openssl printed"

2️⃣ Page Views and Traces

A drain is Vercel sending a copy of your data to an address you choose. Each drain carries one kind of data, so you make two. Drains live in your team's settings, not the project's.

  1. In Vercel, open Team Settings → Drains and click Add Drain
  2. Choose Web Analytics. Name it page views, and under projects pick only this site. With all projects, every site on your team lands in this database
  3. Leave the sampling rate at 100%. A lower rate sends less, and your dashboard counts drop with it
  4. Under the destination, choose Custom Endpoint. For the URL, type your domain followed by /api/analytics/vercel, like https://yourname.com/api/analytics/vercel
  5. Set Format to JSON
  6. In Signature Verification Secret, delete the one Vercel made and paste your DRAIN_SECRET
  7. Click Create Drain. Vercel tests the address right away

Now the second one. Same steps, three differences:

  • Data type: Traces — name it traces, and again pick only this site
  • URL ends in /api/drains/traces — like https://yourname.com/api/drains/traces
  • Format: JSON, not Protobuf — your site cannot read Protobuf, and quietly drops it. Leave the sampling rules empty: your site already keeps only 1 in 10 traces

“Same secret in three places: .env, Vercel, and both drains.”

— unparty-app

3️⃣ Your Visit, on Your Dashboard

  1. Open your live site in a private window and click Accept on the cookie banner
  2. Read a few pages. Drains send data in batches, so give it a few minutes
  3. Sign in as yourself and open /admin/observability
  4. Under Analytics, your pages are listed. Unique Visitors, Total Traces and Performance fill in as data arrives

📈 Google Analytics, If You Want It

Your site can also send visits to Google Analytics, which has its own reports and keeps data longer. It is off until you give your site your own ID. It asks for consent through the same cookie banner.

  1. At analytics.google.com, create an account and a property for your site
  2. Add a Web data stream with your domain
  3. Copy the Measurement ID. It starts with G-
  4. Put it in .env as NEXT_PUBLIC_GA_ID, add it to Vercel, and redeploy. It is built into your pages, so a restart is not enough
bash
# .env
NEXT_PUBLIC_GA_ID="G-XXXXXXXXXX"

⚠️ Good to Know

  • Your privacy policy mentions both — Vercel Analytics and Google Analytics. Not using Google Analytics? Remove those lines in src/data/privacypolicy.json
  • You can hide IP addresses — in Team Settings → Security & Privacy, under IP Address Visibility. It applies to every drain
  • Vercel emails you if a drain breaks — when most deliveries in an hour fail, and the drain is marked with a warning
  • Your computer is not counted — drains only send what happens on Vercel, so local testing never shows up

🧯 If Something Is Off

  • The drain test says 401 — the secret in the drain is not the same as DRAIN_SECRET in Vercel. Paste it again in both, then redeploy
  • 401 with Drain secret not configured — DRAIN_SECRET is missing from Vercel's Production environment
  • The test says 400 — the page views drain is set to NDJSON. Edit it and choose JSON
  • Total Traces stays at zero — the traces drain is set to Protobuf. Edit it and choose JSON
  • Nothing in Analytics — Web Analytics is not enabled in the project, or nobody has accepted the cookie banner yet. Check both, then visit again

🤖 Ask Your LLM

prompt
Here is what /admin/observability shows for the last 7 days:
[paste or describe it]. What should I write more of, and which
page should I make faster first?

My drain says "[paste the error]". The receiving code is in
src/app/api/analytics/vercel/route.ts and
src/app/api/drains/traces/route.ts. What should I check?

✅ You Are Done When

  • Web Analytics is enabled on your project
  • .env and Vercel have DRAIN_SECRET
  • Team Settings → Drains lists two drains, page views and traces, both JSON, both without a warning
  • Your own visit appears in /admin/observability
  • Optional: NEXT_PUBLIC_GA_ID is set, and Google Analytics shows you in its Realtime report

Now you can see what people actually read, not what you guessed they would. Let that pick your next article.

“Count what matters. Then make more of it.”

— unparty-app
#Analytics#Observability#Vercel Drains#Tracing#Google Analytics#Setup#Non-Technical Founders#Software You Own

🧗🏾‍♂️ in progress

THOUGHTS.

…