# HTTP API

Base URL: `https://bloxtrack-api.stockideashq.workers.dev`

Two kinds of key, both made on a project's settings page at https://bloxtrack-app.vercel.app and sent as
`Authorization: Bearer <key>`:

- **Ingest keys** (`btk_in_...`): send events. Game servers use these (the Luau SDK does it for you).
- **Read keys** (`btk_rd_...`): read the project's stats, for scripts, notebooks and other dashboards.

Each key belongs to one project. Keep both on servers: never in a game client.

## Send events

`POST /v1/events` with an ingest key and a JSON body:

```json
{
  "env": "live",
  "version": 412,
  "server_id": "the server's JobId",
  "events": [
    {
      "id": "a unique id per event (a GUID)",
      "name": "purchase",
      "key": "VIP",
      "value": 199,
      "user_id": 123456789,
      "session_id": "one id per player join",
      "ts": 1795450000000,
      "props": { "kind": "gamepass" }
    }
  ],
  "steps": { "tutorial_step": ["Spawned", "Picked a class", "First kill"] }
}
```

| Field | |
|---|---|
| `env` | `live`, `test` or `studio`. Required. The dashboard shows each separately. |
| `version` | The place version (`game.PlaceVersion`). Optional; lets you filter players by the version they started on. |
| `server_id` | Optional. |
| `events` | Up to 500. |
| `events[].id` | Required, up to 64 characters. Resending the same id stores it once, so retrying a failed batch is safe. |
| `events[].name` | Required. snake_case: starts with a letter, then a-z, 0-9, `_`, up to 40 characters. |
| `events[].key` | Optional string, up to 100 characters. What the event was about. |
| `events[].value` | Optional number. Added up in totals. |
| `events[].user_id` | Required whole number: the Roblox UserId. |
| `events[].session_id` | Required, up to 64 characters. One per join. |
| `events[].ts` | When it happened, in milliseconds since 1970 (UTC). Outside the last 7 days (or missing), the time it arrived is used. |
| `events[].props` | Optional object, up to 2 KB as JSON. |
| `steps` | Optional: step lists, by event name, in order (see `DefineSteps` in the SDK). |

Special events:

- `session_start`: the first one per player makes their profile. Props it reads: `new_player` (boolean; without it the
  first session seen counts as new), `device` (`phone`, `tablet`, `desktop`, `console`), `country`, `locale`,
  `join_source` (`direct`, `friend_invite`, `follow`, `other_game`).
- `session_end`: `value` = seconds played (for average session length).
- Any event whose props carry a whole number `index`, with a key, is a step: the key is the step, `index` its place.

Answer:

```json
{ "ok": true, "received": 3, "stored": 2, "rejected": 1, "errors": ["events[2]: name must be snake_case: ..."] }
```

`stored` excludes events already stored (resent). A `401` means a wrong or revoked key; a `400` a malformed body.

## Read stats

`GET /v1/<endpoint>` with a read key. Answers are JSON and cached for 60 seconds.

Common parameters: `env` (`live` by default), `from` and `to` (UTC dates, `YYYY-MM-DD`, `to` included; the default is
the last 7 days). Player filters, where noted: `device`, `country`, `source` (join source), `version` (the version a
player started on, or `unknown`) or `version_min`.

| Endpoint | |
|---|---|
| `GET /v1/summary` | Every event name with `events`, `players` and `total` (sum of values). `name=purchase`: that event split by key. `by=day`: per UTC day (players = distinct that day). Player filters. |
| `GET /v1/players/count` | Players who played in the range and how many were new. |
| `GET /v1/funnel` | `step=` 1 to 40 times, each `name` or `name:key`, in order. Options: `within` (hours from the first step, default 24), `new=1` (only new players who first came in the range), `ordered=0` (steps in any order after the first), player filters. Gives each step's players, share of the first and previous step, and median seconds from the previous step. |
| `GET /v1/funnel/players` | The funnel's parameters plus `at=N` (a step, from 0): players who reached step N and who stopped there, newest first, up to 500 each. |
| `GET /v1/retention` | One row per cohort (the day they first came): its size and the share who played again on day 1, 3, 7, 14 and 30 (`days=` to choose). New players only unless `all=1`. Player filters. |
| `GET /v1/player` | `user_id=`: one player's profile, first time doing each thing, totals, and latest 1,000 events. |
| `GET /v1/versions` | The versions players started on, newest first, with player counts. |
| `GET /v1/steps` | Without `name`: the step event names. `name=tutorial_step`: its steps in order (`version=` / `version_min=` to pick versions). |
| `GET /v1/recent` | The latest events received, every env, up to `limit=100`. Not cached: use it to check a game is sending. |

Examples:

```sh
K=btk_rd_...
U=https://bloxtrack-api.stockideashq.workers.dev
curl -s "$U/v1/summary?env=live&from=2026-11-01" -H "Authorization: Bearer $K"
curl -sG "$U/v1/funnel" -H "Authorization: Bearer $K" --data-urlencode new=1 \
  --data-urlencode step=session_start \
  --data-urlencode "step=tutorial_step:Picked a class" \
  --data-urlencode "step=purchase"
curl -s "$U/v1/retention?device=phone" -H "Authorization: Bearer $K"
```

## Sending without the SDK

Anything that can make an HTTPS request can send events: build the body above, make a GUID per event and per
session, and retry failed batches with the same ids. From Roblox, the SDK (`BloxTrack.lua`) already does all of this.
