Events & ExportExplore query (trend or funnel)

Explore query (trend or funnel)

Self-serve analytics over the event stream in one call. A typed spec — no raw SQL — is validated, compiled server-side to ClickHouse SQL over a wide, typed events table, and scoped to your location by the compiler. Sub-second at current scale: a 30-day trend broken down by a property reads tens of megabytes where the same question over raw JSON properties did not finish.

Trend (kind: trend): 1–5 series, each an event (or null for any event) × math (total, dau, unique_sessions, sum, avg, min, max, median, p90, p95, p99; numeric maths need math_property), bucketed by interval (hour|day|week|month) or returned as one number per series when interval is omitted. Optional breakdown by any property (top-N by the first series; the rest fold into "$$other") and compare: previous_period (the immediately preceding window of equal length, aligned by bucket index, and truncated at the same time of day so today-so-far is not compared against a whole day).

Funnel (kind: funnel): 2–10 ordered steps, a conversion window (default 7 days, capped at the range), optional breakdown taken from the first step. Sequential: other events may occur between steps. Per-step users, conversion_from_first, conversion_from_previous.

Properties: typed names resolve to columns — $current_url, $pathname, $referring_domain, utm_source, utm_medium, utm_campaign, $device_type, $browser, $os, $geo_country, $geo_city, $experiment_arm, plus event, distinct_id, session_id, user_id. Any other name is a custom event property (scalar, ≤200 chars; nested objects and meta_* blobs are not queryable). utm_* and $referring_domain are session-entry values with an event-level fallback. Discover keys with GET /properties and values with GET /query/values.

Semantics: buckets are UTC and zero-filled; presets resolve to [today-N, today] inclusive; unique counts are uniq() (approximate) on distinct_id, not resolved persons. Excluded events: $replay_summary, $replay_started, $heatmap, $web_vital_*, $set, $set_once, $identify (each has its own surface).

Limits (400 invalid_spec, every problem listed in error.details): unknown keys rejected, ≤5 series, 2–10 steps, ≤20 filters in total, range ≤366 days, hour only for ranges ≤31 days, in lists ≤100 values, breakdown limit ≤50. Rate limit 30 requests / 10 s per location. Cached 120 s when the range touches today, 6 h otherwise (meta.cached).

curl -X POST "https://mythic-analytics.gulp.workers.dev/client/v1/data/query?location_id=example_string&debug=example_string" \
  -H "Content-Type: application/json" \
  -H "X-Location-Id: example_string" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
  "kind": "trend",
  "date_range": {
    "preset": "30d"
  },
  "interval": "day",
  "series": [
    {
      "event": "$pageview",
      "math": "dau"
    }
  ],
  "breakdown": {
    "property": "utm_source",
    "limit": 5
  },
  "compare": "previous_period",
  "filters": [
    {
      "property": "$device_type",
      "op": "eq",
      "value": "mobile"
    }
  ]
}'
{
  "success": true,
  "data": {
    "kind": "trend",
    "buckets": [
      "2026-08-30",
      "2026-08-31",
      "2026-09-01"
    ],
    "breakdown_values": [
      "google",
      "",
      "$$other"
    ],
    "series": [
      {
        "label": "$pageview · dau",
        "math": "dau",
        "event": "$pageview",
        "breakdown_value": "google",
        "data": [
          412,
          388,
          97
        ],
        "total": 897,
        "previous": [
          390,
          401,
          120
        ]
      }
    ],
    "meta": {
      "from": "2026-08-30",
      "to": "2026-09-01",
      "interval": "day",
      "previous": {
        "from": "2026-08-27",
        "to": "2026-08-29"
      },
      "sql_ms": 212,
      "rows_read": 778534,
      "bytes_read": 36060000,
      "cached": false
    }
  }
}
POST
/query
POST
Base URLstring

Target server for requests. Edit to use your own host.

Bearer Token
Bearer Tokenstring
Required

Agency key (ak_) or location secret key (sk_) as a bearer token. Format: Bearer ak_... or Bearer sk_.... Scoped keys (mcp_) are accepted too and need the read scope of the family the route belongs to (people, events, sessions, replays, exceptions, heatmaps or bigquery_export). See Using an mcp_ key over HTTP.

Agency key (ak_) or location secret key (sk_) as a bearer token. Format: Bearer ak_... or Bearer sk_.... Scoped keys (mcp_) are accepted too and need the read scope of the family the route belongs to (people, events, sessions, replays, exceptions, heatmaps or bigquery_export). See Using an mcp_ key over HTTP.
query
location_idstring

Alternative to the X-Location-Id header for agency (ak_) keys. Ignored for secret (sk_) keys.

query
debugstring

1 adds the compiled SQL to meta.sql (agency keys only).

Content-Typestring
Required

The media type of the request body

Options: application/json
header
X-Location-Idstring

Location to scope the request to. Required for agency (ak_) keys on the event routes. Ignored for secret (sk_) keys, which resolve their own location, and not used by /export.

kindstring
Required
Options: trend, funnel
intervalstring

Trend only. Omit for one number per series.

Options: hour, day, week, month
seriesarray

Trend only.

comparestring

Trend only.

Options: previous_period
stepsarray

Funnel only. Ordered; other events may occur between steps.

windowobject

Funnel only. Default 7 days, capped at the range length.

grainstring

Funnel only. device counts the raw distinct_id; person resolves each id to its canonical person first, so a journey across devices — or a step that is a server/CRM event keyed by a contact id — links instead of breaking. Slower (it joins the identity map for the window); trends have no grain.

Options: device, person
filtersarray

Applied to every series / step.

Request Preview
Response

Response will appear here after sending the request

Authentication

header
Authorizationstring
Required

Bearer token. Agency key (ak_) or location secret key (sk_) as a bearer token. Format: Bearer ak_... or Bearer sk_.... Scoped keys (mcp_) are accepted too and need the read scope of the family the route belongs to (people, events, sessions, replays, exceptions, heatmaps or bigquery_export). See Using an mcp_ key over HTTP.

Query Parameters

location_idstring

Alternative to the X-Location-Id header for agency (ak_) keys. Ignored for secret (sk_) keys.

debugstring

1 adds the compiled SQL to meta.sql (agency keys only).

Headers

X-Location-Idstring

Location to scope the request to. Required for agency (ak_) keys on the event routes. Ignored for secret (sk_) keys, which resolve their own location, and not used by /export.

Body

application/json
kindstring
Required
Allowed values:trendfunnel
intervalstring

Trend only. Omit for one number per series.

Allowed values:hourdayweekmonth
seriesarray

Trend only.

breakdownobject
comparestring

Trend only.

Allowed values:previous_period
stepsarray

Funnel only. Ordered; other events may occur between steps.

windowobject

Funnel only. Default 7 days, capped at the range length.

grainstring

Funnel only. device counts the raw distinct_id; person resolves each id to its canonical person first, so a journey across devices — or a step that is a server/CRM event keyed by a contact id — links instead of breaking. Slower (it joins the identity map for the window); trends have no grain.

Allowed values:deviceperson
filtersarray

Applied to every series / step.

Responses

successboolean
dataobject

Trend: buckets[] (ISO, UTC), previous_buckets[] with compare, breakdown_values[] with breakdown, and series[] — one entry per spec series × breakdown value with label, math, event, breakdown_value?, data[] + total (or value without interval) and previous[] / previous_value with compare. Funnel: steps[] and breakdown[] \{ value, steps[] \}. Always meta \{ from, to, interval?, previous?, window_seconds?, sql_ms, rows_read, bytes_read, cached, sql? \}.