> For the complete documentation index, see [llms.txt](https://docs.millimetric.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.millimetric.ai/api-reference/stats.md).

# GET /v1/stats

GET /v1/stats — aggregations over events.

Aggregate counts or unique-visitor counts over a time range, optionally grouped and/or time-bucketed.

## Auth

|                |        |
| -------------- | ------ |
| Required scope | `read` |
| Key kinds      | `rk_*` |

## Request

```http
GET /v1/stats?metric=count&from=…&to=…&event=signup&group_by=source,medium&interval=day
Authorization: Bearer rk_live_…
```

### Query parameters

| Name       | Required | Notes                                                                                                                  |
| ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
| `metric`   | no       | `count` (default) or `uniques` (unique `anonymous_id`s, HyperLogLog estimate).                                         |
| `from`     | **yes**  | ISO 8601 timestamp (inclusive).                                                                                        |
| `to`       | **yes**  | ISO 8601 timestamp (exclusive).                                                                                        |
| `event`    | no       | Filter to one event name.                                                                                              |
| `group_by` | no       | Comma-separated columns. Allowed: `event_name`, `source`, `medium`, `country`, `device_type`, `browser`, `os`, `path`. |
| `interval` | no       | `hour`, `day`, or `week`. Adds a `bucket` column to the output.                                                        |
| `limit`    | no       | 1–1000, default 100.                                                                                                   |

## Response

```json
{
  "metric": "count",
  "rows": [
    { "source": "facebook", "medium": "paid",   "value": 6 },
    { "source": "facebook", "medium": "social", "value": 3 },
    { "source": "google",   "medium": "paid",   "value": 3 }
  ]
}
```

When `interval` is set, each row also has a `bucket` column:

```json
{ "bucket": "2026-05-16 00:00:00", "source": "facebook", "value": 4 }
```

## Examples

### Daily signups by source

```bash
curl -G "https://api.millimetric.ai/v1/stats" \
  -H "Authorization: Bearer $RK_KEY" \
  --data-urlencode "metric=count" \
  --data-urlencode "from=2026-05-01T00:00:00Z" \
  --data-urlencode "to=2026-05-17T00:00:00Z" \
  --data-urlencode "event=signup" \
  --data-urlencode "group_by=source,medium" \
  --data-urlencode "interval=day"
```

### Unique visitors per country, last 7 days

```bash
curl -G "https://api.millimetric.ai/v1/stats" \
  -H "Authorization: Bearer $RK_KEY" \
  --data-urlencode "metric=uniques" \
  --data-urlencode "from=$(date -u -v-7d +%Y-%m-%dT%H:%M:%SZ)" \
  --data-urlencode "to=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
  --data-urlencode "group_by=country"
```

### Total page views this month

```bash
curl -G "https://api.millimetric.ai/v1/stats" \
  -H "Authorization: Bearer $RK_KEY" \
  --data-urlencode "from=2026-05-01T00:00:00Z" \
  --data-urlencode "to=2026-06-01T00:00:00Z" \
  --data-urlencode "event=\$pageview"
```

(Note the `\$` to escape the `$` in shell. In code, just send `"$pageview"`.)

## Errors

* `400 invalid_group_by` — column not in the allow-list. Response includes the allowed columns.
* `400 invalid_params` — `from`/`to` missing or `metric` not one of `count`/`uniques`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.millimetric.ai/api-reference/stats.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
