DEV Community

galb
galb

Posted on

Read your Vercel Web Analytics from the terminal

The Vercel dashboard shows Web Analytics for one project at a time. I wanted the numbers in a terminal and in scripts. So I made vercel-analytics-api, a small client for Vercel's public API (MIT, unofficial, no dependencies).

Terminal

The command uses your Vercel CLI login and current team:

npx vercel-analytics-api visitors --since 30d
Enter fullscreen mode Exit fullscreen mode
PROJECT           VISITORS  PAGE VIEWS
example.com          1,200       3,400
docs.example.com       480         910
Enter fullscreen mode Exit fullscreen mode
npx vercel-analytics-api top pages -p example.com -n 5
npx vercel-analytics-api series -p example.com --json
Enter fullscreen mode Exit fullscreen mode

Node

import { createClient } from "vercel-analytics-api";

const va = createClient({ token: process.env.VERCEL_TOKEN!, teamId: "team_abc" });
const since = Date.now() - 7 * 86_400_000;
const { visitors } = await va.totals({ projectId: "prj_123", since });
Enter fullscreen mode Exit fullscreen mode

The client also reads referrers, countries, custom events and Core Web Vitals (speedInsights()). The repository has recipes for a weekly Slack report in GitHub Actions and a CSV export.

Know this

  • Visitors are unique per window. A week's visitors are fewer than the sum of its days.
  • The API has no bounce rate.
  • UTM breakdowns need Web Analytics Plus. Without it, Vercel returns 402.

I made it while I built Lookout, a dashboard for all your Vercel projects. The package does not need Lookout.

Top comments (0)