# Query API

The one endpoint behind every chart, for your own reports.

Every chart in the dashboard comes from one endpoint. Call it to build your own reports or to pull numbers into another tool.

`POST https://api.ultanimus.com/v1/sites/{id}/query`

`{id}` is the site ID shown in the site's settings, such as `ult_fxpitz4w7h`, or the site's domain. Every API key can read, so any key of the organization works.

## Request

- `metrics` (string[]): What to count, one to eight of `visitors`, `visits`, `pageviews`, `views_per_visit`, `bounce_rate`, `visit_duration` in seconds, and `events`.
- `dimensions` (string[]): One dimension to split the numbers by, such as `["page"]`, from the Dimensions list below. Leave it out for totals. On Foresight, a second one turns the split into a pivot, as Pivots below shows.
- `filters` (object[]): Up to 10 filters, and a row must match all of them. Each one is `{"dimension": "country", "op": "is", "values": ["US", "CA"]}`, where `op` is `is` or `is_not` and `values` holds 1 to 20 values.
- `segment` (string): The key of a saved [segment](/docs/dashboard/segments), such as `mobile`, on Insight and Foresight. Its filters join the ones in `filters`, with up to 10 of each. An unknown key answers `404` with `ULT-1370`, and Glance gets `ULT-1203`.
- `date_range` (object): `{"preset": "30d"}` with `realtime`, `today`, `7d`, `30d`, `90d` or `12mo`, or `{"from": "2026-10-01", "to": "2026-10-07"}`. Dates are in the site's time zone and include both ends. `realtime` covers the last five minutes and gives totals only.
- `compare` (string): `previous` for the period just before, or `year` for the same dates a year earlier.
- `interval` (string): `hour`, `day`, `week` or `month` turns the answer into a time series. A query is a series or a split by dimension, not both.
- `order_by` (object[]): For a split, one of the requested metrics, such as `[{"field": "visitors", "direction": "desc"}]`. By default rows follow the first metric, highest first.
- `limit` (number): The most rows a split returns, from 1 to 500. The default is 10.

```bash
curl -X POST https://api.ultanimus.com/v1/sites/YOUR_SITE_ID/query \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"metrics":["visitors","pageviews"],"dimensions":["page"],"date_range":{"preset":"30d"},"compare":"previous","limit":3}'
```

## Response

The answer is columnar: one array per column, in the order `columns` lists them, so each array maps straight onto a chart series.

```json
{
  "status_code": 200,
  "data": {
    "date_range": { "from": "2026-09-18T00:00:00-04:00", "to": "2026-10-17T08:07:00-04:00", "timezone": "America/New_York" },
    "compare_range": { "from": "2026-08-19T00:00:00-04:00", "to": "2026-09-17T08:07:00-04:00", "timezone": "America/New_York" },
    "columns": ["page", "visitors", "pageviews"],
    "data": {
      "page": ["/", "/pricing", "/docs"],
      "visitors": [1840, 920, 610],
      "pageviews": [2310, 1104, 1490]
    },
    "previous": { "visitors": [1620, 980, 540], "pageviews": [2050, 1170, 1302] },
    "totals": { "visitors": 3120, "pageviews": 6020 },
    "previous_totals": { "visitors": 2900, "pageviews": 5600 },
    "more": 42
  },
  "message": "OK"
}
```

- `totals` count the whole range, not the sum of the rows, so a visitor who saw two pages counts once.
- `more` is the number of rows the limit left out.
- `previous` lines up with `data` row by row: the same pages in a split, the same position in a series.
- A time series has a `date` column holding the start of each bucket. Every bucket is there, with zeros where nothing happened.
- `sampled` appears when the range holds more than 5 million events. The numbers then come from that fraction of visitors, such as `0.1`, and counts are scaled back up. Rates and durations come from the same visitors and need no scaling.

## Dimensions

| Dimension | Splits by |
|---|---|
| `page` | Page path, counting the pageviews of that page |
| `entry`, `exit` | The first and the last page of a visit |
| `hostname` | The host the page was on |
| `source`, `referrer`, `channel` | Where the visit came from |
| `utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term` | The campaign tags the visit arrived with |
| `event`, `goal` | Custom event name |
| `prop` | The names of the properties events carry |
| `prop:<name>` | The values of one property, such as `prop:plan`. A name takes 1 to 64 bytes |
| `country`, `region`, `city` | Location. A split by city adds a `country` column |
| `device`, `browser`, `browser_version`, `os`, `os_version`, `language` | The visitor's device and settings |
| `screen` | Screen width group: `0` for phones, then `768`, `1024`, `1440` and `1920` |

A filter on `event`, `goal` or a property keeps the whole visits that include a matching event, so you can see which pages people saw on the visits where they signed up. Bounce rate and visit duration describe whole visits, so they cannot be split by `page`, `hostname`, `event`, `goal` or a property.

### Events and their properties

- Filters on an event name and on its properties describe one event. `event is signup` with `prop:plan is pro` keeps the visits that sent a pro signup, not visits with a signup and some other event on plan pro.
- With an `is` filter on `event`, `goal` or a property, the `events` metric counts only the matching events. `events` with `event is signup` is the number of signups, while `visitors` still counts the people who sent one.
- A split by `event` under a property filter lists only the events that carry that value.
- A split by `prop` or `prop:<name>` reads the properties of the events your `event` filter names, so a property of another event on the same visit stays out.
- `prop` only splits. To filter, name the property, as in `prop:plan`.

This asks for the plans people picked when they signed up:

```bash
curl -X POST https://api.ultanimus.com/v1/sites/YOUR_SITE_ID/query \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"metrics":["events","visitors"],"dimensions":["prop:plan"],"filters":[{"dimension":"event","op":"is","values":["signup"]}],"date_range":{"preset":"30d"}}'
```

## Pivots

On the Foresight plan, a second dimension splits each row into columns, such as `["source", "device"]`. The second dimension must hold for the whole visit, so every metric can count it: channel, source, referrer, the UTM tags, entry page, country, region, city, language, device, browser, OS, their versions or screen. Other plans get `ULT-1203`.

The rows answer exactly as a split by the first dimension. A `split` object adds the columns and the cells:

```json
"split": {
  "columns": ["device", "visitors"],
  "data": { "device": ["desktop", "mobile"], "visitors": [2210, 980] },
  "more": 1,
  "cells": { "visitors": [[1420, 410], [610, 300]] }
}
```

- The columns are the 10 values with the most of the first count you asked for (visitors, visits, pageviews or events), whichever way the rows are sorted. With no count, they follow `order_by`. `more` is how many values that left out.
- `cells[metric][row][column]` is the value of that row in that column, in the order of `data`. A pair nobody had is `0`.
- With `compare`, the split has `previous` for its columns and `previous_cells` for its cells.

## Journeys

On Insight and Foresight, `journey` asks for the paths of visits instead of counts, as the [Journeys](/docs/dashboard/journeys) page shows them. Send it with `date_range` and `filters` only. Glance gets `ULT-1203`.

```json
{ "journey": { "start": "/pricing" }, "date_range": { "preset": "30d" } }
```

- An empty object, `{}`, follows visits from their entry pages. `start` follows them from the first time they opened a page, and `end` works back from one. Send one of the two at most. A path starts with `/` and matches one page exactly.
- `data.journey.steps` holds 5 steps at most, each with up to 5 pages and an `other` node for the rest. A node has `page`, `visits` and `exits`, the visits with no page after it, or with `end` none before it. `other` nodes also carry `pages`, the number of pages they fold.
- `data.journey.links` lists `{ "step": 0, "from": 1, "to": 0, "visits": 210 }`: visits from page `from` of step `step` to page `to` of the step after it.
- `totals.visits` counts the visits in the first step. Above a million events in the range, `sampled` gives the fraction of visitors read.

## Retention

On Insight and Foresight, `retention` asks how many signed-in people come back after their first visit, as the [Retention](/docs/dashboard/retention) page shows it. Send it with `date_range`, `filters`, `segment` and `interval` only. Glance gets `ULT-1203`.

```json
{ "retention": { "event": "purchase" }, "interval": "week", "date_range": { "preset": "90d" } }
```

- An empty object, `{}`, counts any visit as coming back. `event` counts only the periods where a person sent that event, and `goal` takes a goal's key. Send one of the two at most.
- `interval` is `day`, `week` or `month`, and the range must hold between 2 and 31 of them. Leave it out for the shortest one that fits. The answer's `interval` says which one it used.
- `data.retention.cohorts` holds one cohort per period, oldest first. A cohort has `start`, `people`, and `returned`, where `returned[k]` counts the people who came back `k` periods later, so `returned[0]` equals `people`.
- `data.retention.average[k]` is the share who came back `k` periods later, over the cohorts whose period `k` has ended.
- `data.retention.partial` is `true` while the range's last period is still running.
- Only people with a [user ID](/docs/tracking/identify) count, and `totals.people` adds up every cohort. Above 5 million events in the range, `sampled` gives the fraction of people read.

## Sessions

On Insight and Foresight, `sessions` lists visits one by one, newest first, as the [Sessions](/docs/dashboard/sessions) page shows them. Send it with `date_range`, `filters`, `segment` and `limit` only. Glance gets `ULT-1203`.

```json
{ "sessions": {}, "date_range": { "preset": "7d" }, "limit": 50 }
```

- `data.sessions.sessions` lists up to `limit` visits that began in the range, 50 by default and 100 at most. A visit has `id`, `start` and `end` as UTC times, `duration` in seconds, `pageviews`, `events`, `entry`, `exit`, `source`, `channel`, `referrer`, `campaign`, `country`, `region`, `city`, `device`, `browser` and `os`.
- When more visits are left, `data.sessions.next` holds a cursor. Send it back as `{ "sessions": { "before": "<next>" } }` with the same range and filters for the next page. The last page has no `next`.
- Filters keep or drop whole visits, so a page filter lists the visits that opened the page with every page they opened.

`session` answers one visit's events. Send the `id` and `start` of a visit from the list, and nothing else.

```json
{ "session": { "id": "8410337165307419223", "start": "2026-11-02T09:24:35.902Z" } }
```

- `data.session` has the same fields as a visit in the list, plus `timeline`, the visit's events in order, each with `at`, `name`, `hostname`, `path` and `props`.
- A visit with more than 1,000 events returns its first 1,000 and sets `more` to `true`.
- A visit with no events at that start answers `404` with `ULT-1112`.

## People

On Insight and Foresight, `people` lists the people your site signs in, the most recently seen first, as the [People](/docs/dashboard/people) page shows them. Send it with `date_range`, `filters`, `segment` and `limit` only. Glance gets `ULT-1203`.

```json
{ "people": {}, "date_range": { "preset": "30d" }, "limit": 50 }
```

- `data.people.people` lists up to `limit` people active in the range, 50 by default and 100 at most. A person has `id` (16 hex digits), `first_seen` and `last_seen` as UTC times within the range, `visits`, `pageviews`, `events`, and the `country`, `device` and `browser` of their latest browser event.
- When more people are left, `data.people.next` holds a cursor. Send it back as `{ "people": { "before": "<next>" } }` with the same range and filters for the next page.

`person` answers one person. Send the `id` from the list, or `user` with the user ID your site passes to the tracker, and `date_range`. The user ID is hashed the way the tracker does and never stored.

```json
{ "person": { "user": "u_8f2k1x" }, "date_range": { "preset": "30d" } }
```

- `data.person` has the fields of a person in the list, plus `sessions`, their latest 50 visits shaped like the visits in `sessions`, `more_sessions`, and `event_names`, `pages`, `countries`, `devices` and `browsers`, each a list of `value`, `count`, `visits`, `first` and `last`. `goals` lists the site's goals they reached with `key`, `name`, `count` and `visits`.
- A person with no event in the range answers zeros and empty lists.

## How a query runs

- Answers are cached for a minute, or for an hour once the range ended more than an hour ago.
- A query stops after 10 seconds and answers `504` with `ULT-9001`. Ask for a shorter range or fewer filters.
- Each key can run 240 queries a minute. Past that the answer is `429` with `ULT-1902` and a `Retry-After` header in seconds.
- For every event as its own row instead of counts, use the [raw export](/docs/api/export).
