Accessing Metrics with Vercel CLI
Use vercel metrics to query Web Analytics data from your terminal. You can reproduce common dashboard views, then go further with custom filters, multiple groupings, custom event analysis, UTM dimensions, and team-wide queries.
Web Analytics metrics are available through vercel metrics without Observability Plus.
The schema is the source of truth for the metrics, dimensions, and aggregations available to your account. Start by inspecting the available Web Analytics metrics:
vercel metrics schema
vercel metrics schema vercel.analyticsUse these examples to query the same kinds of traffic views available in the Web Analytics dashboard. The examples use --environment production to limit the results to your production environment. To filter the results by a dimension, add --query with a filter expression, such as country:US.
Query daily page views for the last seven days:
vercel metrics vercel.analytics.page_view.count --since 7d --granularity 1d --project project-name --environment productionSee the top countries by page views:
vercel metrics vercel.analytics.page_view.count --group-by country --since 7d --limit 10 --project project-name --environment productionQuery unique visitors from a specific country over the last day:
vercel metrics vercel.analytics.page_view.count --aggregation unique/visitorId --query 'country:US' --since 1d --granularity 1h --project project-name --environment productionList the most common custom event names:
vercel metrics vercel.analytics.event.count --group-by eventName --since 7d --limit 20 --project project-name --environment productionThe --data option runs a query with multiple metrics and formulas, letting you compute ratios such as bounce rate that a single-metric flag query cannot express. The following query counts visitors with exactly one page view with the singleton aggregation on vercel.analytics.page_view.count over visitorId, counts total visitors with the unique aggregation over visitorId, and divides the two to compute a bounce rate from page-view data:
vercel metrics --since 7d --project project-name --data '{
"filter": "environment:production",
"metrics": {
"bounced": {"metric": "vercel.analytics.page_view.count", "aggregation": "singleton", "dimensions": ["visitorId"]},
"visitors": {"metric": "vercel.analytics.page_view.count", "aggregation": "unique", "dimensions": ["visitorId"]}
},
"formulas": {"bounceRate": "bounced / visitors * 100"},
"outputs": ["bounceRate"]
}'This value is a bounce rate computed from page-view data and may differ from the Bounce Rate shown in the Web Analytics dashboard.
The following query shapes are not available in the Web Analytics dashboard. Use them when you need more precise filtering, multi-dimensional comparisons, custom event analysis, or team-wide reporting.
Repeat --query to add filters. The results match every filter. Use a field-scoped OR expression to include multiple path prefixes, != to exclude a value, and repeated --group-by options to compare the remaining traffic by path and device type:
vercel metrics vercel.analytics.page_view.count --query 'requestPath:(/docs* OR /guides*)' --query 'country != US' --group-by requestPath --group-by deviceType --since 7d --project project-name --environment productionFilter by a custom event name, then group results by country and device type:
vercel metrics vercel.analytics.event.count --query 'eventName:signup' --group-by country --group-by deviceType --since 7d --project project-name --environment productionGroup page views by UTM source and campaign to compare campaign traffic:
vercel metrics vercel.analytics.page_view.count --group-by utmSource --group-by utmCampaign --since 7d --project project-name --environment productionUse --all with projectId to compare production traffic across every project in the current team:
vercel metrics vercel.analytics.page_view.count --all --group-by projectId --group-by country --since 7d --limit 20 --environment productionFor all options, see the vercel metrics reference.
Was this helpful?