Vercel Logs for comprehensive traffic analytics
Most analytics only see visitors whose browsers run JavaScript, which hides text browsers like Lynx, curl, and clients with JavaScript disabled. Vercel Logs fix that by forwarding the raw request logs from your deployment to an endpoint you control, so every request is recorded.
This tutorial streams logs for a static Astro site on Vercel and verifies that a request without a browser is captured. You end up with request-level visibility (path, status code, user agent, client IP) for all traffic.
Vercel calls the mechanism a drain; it lives under Team Settings → Drains. This guide calls the result Vercel Logs because that is what you get.
Prerequisites
Section titled “Prerequisites”- A Vercel project on a Pro or Enterprise plan (Drains are not on Hobby)
- An HTTPS endpoint that accepts
POSTand returns200 - Basic familiarity with the Vercel dashboard
Concepts
Section titled “Concepts”Two terms matter:
- Source: what you watch. For traffic this is Static Files: requests to the prerendered HTML, CSS, JS, and images.
- Destination: where logs go. A separate endpoint you own, never the site itself.
Logs are delivered over HTTPS in batches. Vercel bills per GB of drain volume; for a low-traffic site that is pennies per GB. Check Vercel’s current pricing for exact rates.
Step 1 - Prepare a destination endpoint
Section titled “Step 1 - Prepare a destination endpoint”For a first test, use a disposable request bin:
- Open webhook.site.
- Copy the unique URL it generates.
For production, replace this with your own collector: a small function that verifies the request signature and stores the payload (Step 6).
Placeholders
| Placeholder | Meaning |
|---|---|
<your-endpoint-url> | Your collector URL, e.g. https://logs.example.com/ingest |
<your_drain_secret> | The signature secret Vercel generates for the drain |
Step 2 - Create the drain
Section titled “Step 2 - Create the drain”- In the Vercel dashboard, open the team that owns the project.
- Go to Settings → Drains.
- Click Add Drain and select Logs as the data type.
Step 3 - Configure the drain
Section titled “Step 3 - Configure the drain”- Name: for example
myproject-access-logs. - Projects: select the project, or All projects.
- Sources: tick Static Files to capture page requests; optionally tick Builds for deploy logs.
- Environment: select production.
- Sampling rules: leave empty for 100% coverage. Once you add a rule, only matching requests are kept; add a catch-all rule if you sample.
Step 4 - Configure the destination
Section titled “Step 4 - Configure the destination”In the Custom Endpoint section:
- Endpoint URL:
<your-endpoint-url> - Format:
JSON(batched array) orNDJSON(one object per line) - Signature Verification Secret: keep the generated secret, then copy it from the drain’s Edit dialog
- Custom Headers: optional, for auth
Click Create Drain. Vercel tests the endpoint immediately and starts forwarding.
Step 5 - Verify without a browser
Section titled “Step 5 - Verify without a browser”curl -s -o /dev/null -w "%{http_code}\n" -A "curl-test" https://<your_domain>/In your request bin, look for a payload like:
[ { "source": "static", "host": "example.com", "path": "/", "environment": "production", "proxy": { "method": "GET", "statusCode": 200, "userAgent": ["curl-test"], "clientIp": "203.0.113.10", "region": "fra1", "vercelCache": "HIT" } }]"source": "static" confirms the request was recorded without any JavaScript involved.
Step 6 - Secure the endpoint (recommended)
Section titled “Step 6 - Secure the endpoint (recommended)”Anyone who learns your endpoint URL can POST fake data. Vercel signs every delivery with an x-vercel-signature header: an HMAC-SHA1 hex digest of the raw body, keyed by your drain secret. Verify it before trusting the payload.
import crypto from 'crypto';
export async function POST(request) { const secret = process.env.VERCEL_DRAIN_SECRET; // copied from the drain's Edit dialog const rawBody = await request.text(); // raw bytes, before JSON parsing const expected = crypto .createHmac('sha1', secret) .update(Buffer.from(rawBody, 'utf-8')) .digest('hex');
if (expected !== request.headers.get('x-vercel-signature')) { return Response.json({ error: "signature didn't match" }, { status: 403 }); }
// NDJSON: one JSON object per line for (const line of rawBody.split('\n')) { if (line.trim()) console.log(JSON.parse(line)); } return Response.json({ success: true });}Store the secret in an environment variable and never commit it.
What to expect
Section titled “What to expect”- All static assets are logged, not only page views. One page load can produce several entries (HTML, CSS, JS, images); filter on
pathortext/htmlwhen counting visitors. - Cache hits are included: entries carry
vercelCache: "HIT", so CDN-served pages are not dropped. - Client IP and user agent are personal data. For EU audiences, define a retention policy.
- Sampling cuts volume and cost but makes counts statistical rather than exact.
Conclusion
Section titled “Conclusion”You now stream every request from your Vercel project to an endpoint you control, with comprehensive coverage of all clients.
Next steps:
- Replace the request bin with a durable collector that verifies the signature and stores logs.
- Query the collected logs for per-path and per-user-agent trends.