Counts

Count how many events match a query.

What a count returns

A count returns the number of events that match your query. Counts accept an optional filter and a required time range:

typescript
const purchases = await vanta.count({
  time: timeRange('2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z'),
})

The result is a plain number, so it reads naturally in a report or a dashboard card.

Filtered counts

Add filters to narrow the count to a specific event type, property, or context value:

typescript
const proSignups = await vanta.count({
  filters: filter('data.plan', 'equals', 'pro'),
  time: timeRange('2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z'),
})

Combine conditions with and() and or() for more precise questions:

typescript
const trialConversions = await vanta.count({
  filters: and(
    filter('type', 'equals', 'checkout.completed'),
    or(
      filter('data.plan', 'equals', 'pro'),
      filter('data.plan', 'equals', 'team'),
    ),
  ),
  time: timeRange('2024-06-01T00:00:00Z', '2024-06-30T23:59:59Z'),
})

Counting page views

Page views are tracked under the reserved event type $page. Count them the same way:

typescript
const pageViews = await vanta.count({
  filters: filter('type', 'equals', '$page'),
  time: timeRange('2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z'),
})

Counts with grouping

Use groupBy() when you need the count broken down per value instead of a single total. See Grouping.