# Install with a Vercel log drain

For sites on Vercel where you'd rather not add a file to the project: a log drain sends Vercel's request logs to Punchline, and each page request becomes the same event the [middleware](https://punchlineanalytics.com/docs/install-vercel) or the [Next.js package](https://punchlineanalytics.com/docs/install-nextjs) would have sent. No code, no deploy.

- **Nothing runs in your project.** Vercel posts its logs to Punchline after the fact; your functions and pages are untouched.
- **It sees what Google Analytics can't:** crawlers, AI fetchers and coding agents that never run JavaScript.
- **Vercel Pro or Enterprise.** Drains aren't available on Hobby. Vercel bills drains by volume.

Use **one** server-side install per site: a drain and the middleware together would count every page twice. The [browser snippet](https://punchlineanalytics.com/docs/install-snippet) can be added to either.

## Set it up

You'll need your `PUNCHLINE_DSN` value (Site settings → Install in your dashboard). It looks like `https://<site-id>:<secret>@app.punchlineanalytics.com/api/collect`; you'll use the two parts.

1. In Vercel, open your **team settings → Drains → Add drain** (or the project's **Settings → Drains**).
2. **Type:** Logs. **Format:** JSON or NDJSON, either works. **Environment:** Production. **Sources:** keep the request sources (Function/Lambda, Edge, Static, Redirect). Build and Firewall lines are ignored if included.
3. **Endpoint:** `https://app.punchlineanalytics.com/api/drains/vercel?site=<site-id>`, with the site id from your DSN.
4. **Custom headers:** add one line, `Authorization: Bearer <secret>`, with the secret from your DSN. This is how the drain authenticates; the endpoint refuses anything else.
5. Save. Vercel tests the endpoint with a sample delivery; the response is `{"ok":true,"received":…,"counted":0}` for a test batch.
6. **Check it's working.** Visit a few pages. They appear in your Punchline dashboard within a minute or two of Vercel delivering the batch; **Doctor → Site check** shows the last page view.

## What's counted

Page requests in Production: `GET` and `HEAD` for pages and the text files agents fetch (`robots.txt`, `llms.txt`, `sitemap.xml`, `*.md`). Not counted: assets (images, scripts, styles, fonts), `/api/` routes, Next.js internals, client-side navigations (`_rsc` requests), preview deployments, blocked (firewall) requests, and background revalidations.

Each page request carries what the log has: the path, `utm_*` values and the query string with credential and personal-data values redacted, the referrer's host, the status and response size, and the visitor's address and user agent, which the collector uses in memory for people and keeps with the visit for agents. The request's own time is kept, not the delivery time.

## What a drain can't do

Logs don't carry request headers beyond the user agent and referrer, so compared with an edge install:

- **No Web Bot Auth.** Signed agents (ChatGPT's agent and others) are still recognized by name and address, but at *declared* confidence rather than *verified*.
- **No browser-header check.** Rule R15 (a browser's name without the headers browsers always send) is skipped.
- **No markdown, no share links.** The install can't change the response, so [serving agents markdown](https://punchlineanalytics.com/docs/edge-markdown) and handoff links minted at the edge need the middleware or the package.
- **Later.** Vercel delivers batches after the fact, so Realtime lags by a minute or two.
- **A batch is stored once.** If one request in a batch fails to store, it's logged and counted as failed in the response; Vercel isn't asked to resend, because a resend would store the rest of the batch twice.

If any of those matter, the [middleware](https://punchlineanalytics.com/docs/install-vercel) is one file.

## Troubleshooting

- **The drain shows errors.** Open a failed delivery: a `401` means the `Authorization` header is missing or the secret is wrong; a `400` means the `site` parameter isn't a site id. Rotating the edge secret in Site settings invalidates the header until you update it.
- **Nothing arrives, deliveries succeed.** The response's `counted` says how many page requests the batch held. Zero on real traffic usually means the drain's environment is Preview, or only Build logs are selected.
