Skip to content

Analytics API Reference

Query aggregated analytics data for your operator — KPIs, revenue trends, player lists, game performance, and payment provider statistics.

Base path: /functions/v1/analytics-api

Authentication: Authorization: Bearer oh_live_... or Supabase JWT

Rate limits

ActionLimit
Read queries200 / minute
Export queries5 / minute
View refresh1 / minute

Common parameters

Range filtering

Most endpoints accept a range query parameter:

ValueDescription
7dLast 7 days
14dLast 14 days
30dLast 30 days
90dLast 90 days
2026-01-01:2026-03-31Custom date range (ISO format)

Response size limit

All responses are capped at 1 MB. If the data exceeds this limit, it is truncated and the response includes "truncated": true.


KPIs {#kpis}

GET /analytics-api/analytics/kpis

Returns aggregate KPIs for your operator.

Query parameters

ParameterTypeDescription
rangestringDate range filter (see above)

Example

bash
curl "https://api.onehazel.com/analytics-api/analytics/kpis?range=30d" \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "kpis": {
      "total_players": 1250,
      "active_players_today": 342,
      "total_ggr": 45230.50,
      "total_deposits": 128500.00,
      "total_withdrawals": 83269.50,
      "avg_deposit": 102.80
    },
    "refreshed_at": "2026-04-06T06:00:00.000Z"
  }
}
  • active_players_today is based on players with activity in the last 7 days (not strictly today)
  • avg_deposit is total deposits divided by the number of depositing players
  • refreshed_at indicates when the materialized views were last refreshed (null if using raw table fallback)

Revenue {#revenue}

GET /analytics-api/analytics/revenue

Returns revenue time series data.

Query parameters

ParameterTypeDefaultDescription
periodstringdailyAggregation period: daily, weekly, or monthly
rangestringDate range filter

Default lookback: 30 days for daily, 12 weeks for weekly, 12 months for monthly.

Example

bash
curl "https://api.onehazel.com/analytics-api/analytics/revenue?period=daily&range=7d" \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "period": "daily",
    "rows": [
      {
        "date": "2026-03-31",
        "total_ggr": 1520.50,
        "total_deposits": 4200.00,
        "depositing_players": 42,
        "active_players": 185
      },
      {
        "date": "2026-04-01",
        "total_ggr": 1680.25,
        "total_deposits": 3850.00,
        "depositing_players": 38,
        "active_players": 192
      }
    ]
  },
  "truncated": false
}

Players {#players}

GET /analytics-api/analytics/players

Returns a paginated list of entities.

Required parameter

The entity_type query parameter is required. Requests without it return HTTP 400.

Query parameters

ParameterTypeDefaultDescription
entity_typestringRequired. Entity type to query (e.g. player)
searchstringFilter by external ID (partial match)
sortstringcreated_atSort column: created_at, updated_at, or external_id
directionstringdescSort direction: asc or desc
limitinteger50Results per page (max 100)
offsetinteger0Pagination offset

Example

bash
curl "https://api.onehazel.com/analytics-api/analytics/players?entity_type=player&limit=10&search=james" \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "players": [
      {
        "id": "ent_a1b2c3d4e5f67890",
        "external_id": "player_12345",
        "entity_type": "player",
        "data": { "country": "GB", "currency": "GBP", "status": "active" },
        "created_at": "2026-04-01T10:00:00.000Z",
        "updated_at": "2026-04-06T14:30:00.000Z"
      }
    ],
    "total": 1,
    "has_more": false
  }
}

PII in list responses

PII fields remain encrypted in list responses. Only the player detail endpoint decrypts PII.


Player detail {#player-detail}

GET /analytics-api/analytics/players/:id

Returns detailed information about a single entity, including decrypted PII, current states, and the 20 most recent events.

Example

bash
curl https://api.onehazel.com/analytics-api/analytics/players/player_12345 \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "id": "ent_a1b2c3d4e5f67890",
    "external_id": "player_12345",
    "entity_type": "player",
    "data": {
      "first_name": "James",
      "last_name": "Wilson",
      "email": "james@example.com",
      "country": "GB",
      "currency": "GBP",
      "status": "active"
    },
    "states": [
      { "state_key": "balance", "value": { "amount": 145.50, "currency": "GBP" }, "updated_at": "2026-04-06T14:30:00Z" },
      { "state_key": "kyc_status", "value": "verified", "updated_at": "2026-04-05T09:00:00Z" }
    ],
    "recentEvents": [
      {
        "id": "eev_b2c3d4e5f6789012",
        "event_type": "transaction",
        "data": { "type": "deposit", "amount": 50.00, "currency": "GBP" },
        "created_at": "2026-04-06T14:00:00Z"
      }
    ],
    "created_at": "2026-04-01T10:00:00Z",
    "updated_at": "2026-04-06T14:30:00Z"
  }
}

Games {#games}

GET /analytics-api/analytics/games

Returns game performance statistics.

Query parameters

ParameterTypeDefaultDescription
limitinteger50Results per page (max 100)
offsetinteger0Pagination offset
rangestringDate range filter (raw table path only)

Example

bash
curl "https://api.onehazel.com/analytics-api/analytics/games?limit=10" \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "games": [
      {
        "game_name": "European Roulette",
        "rounds": 15420,
        "ggr": 8250.75,
        "unique_players": 342,
        "avg_bet": 5.25
      },
      {
        "game_name": "Blackjack Classic",
        "rounds": 12180,
        "ggr": 6430.20,
        "unique_players": 287,
        "avg_bet": 10.50
      }
    ]
  },
  "truncated": false
}

Providers {#providers}

GET /analytics-api/analytics/providers

Returns payment provider statistics — transaction volume, total amount, and success rate.

Example

bash
curl https://api.onehazel.com/analytics-api/analytics/providers \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "data": {
    "providers": [
      {
        "provider": "stripe",
        "volume": 2450,
        "total_amount": 125000.00,
        "success_rate": 0.97
      },
      {
        "provider": "trustly",
        "volume": 890,
        "total_amount": 45000.00,
        "success_rate": 0.99
      }
    ]
  }
}

Refresh {#refresh}

POST /analytics-api/analytics/refresh

Manually refreshes materialized views. Rate limited to 1 request per minute.

Example

bash
curl -X POST https://api.onehazel.com/analytics-api/analytics/refresh \
  -H "Authorization: Bearer oh_live_YOUR_API_KEY"

Response

json
{
  "success": true,
  "message": "Views refreshed",
  "refreshed_at": "2026-04-06T14:35:00.000Z"
}

Error codes

HTTP StatusError CodeDescription
400MISSING_FILTERentity_type is required for /analytics/players
400INVALID_PARAMInvalid parameter value (e.g. unknown period)
401UNAUTHORIZEDMissing or invalid API key / JWT
429RATE_LIMITEDRate limit exceeded
500INTERNAL_ERRORServer error