{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/zeblink-io/json-schema/zeblink-io-query-analytics-input-schema.json",
  "title": "QueryAnalyticsInput",
  "description": "Analytics query, two halves. Object SCOPE — WHICH links to count clicks for — uses the same vocabulary as link search: `status`, `created`, `edited`, `createdVia`, `hasCollection`, `schedule`, `attribution`, `targetHost`, `query`, plus the identity scopes `linkId` / `collectionId` (one link OR one collection OR attributes, never combined) and `negate` (invert named scope dims). Click MEASUREMENT — `country`/`continents`/`region`/`city`, `browser`/`os`/`deviceType`, `referrerDomain`, `fromQr`, bot dims — filters the clicks. `groupBy` returns a breakdown (one row per value), `measure` counts clicks or uniqueClicks, `range` sets the window (`day` buckets and custom `from`/`to` resolve in `timeZone`, default UTC). All fields optional; an empty body is whole-space all-time totals.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/zeblink-io-v1-openapi.json#/components/schemas/QueryAnalyticsInput",
  "type": "object",
  "properties": {
    "groupBy": {
      "type": "string",
      "enum": [
        "country",
        "region",
        "city",
        "browser",
        "os",
        "deviceType",
        "referrerDomain",
        "fromQr",
        "shortDomain",
        "isBot",
        "botType",
        "botName",
        "day",
        "link"
      ],
      "description": "Break the result down by this dimension (one row per value); omit for a single total. `day` is a per-day time series."
    },
    "measure": {
      "type": "string",
      "enum": [
        "clicks",
        "uniqueClicks"
      ],
      "description": "What to count: total clicks (default) or unique visitors."
    },
    "range": {
      "type": "string",
      "enum": [
        "15m",
        "1h",
        "1d",
        "7d",
        "30d",
        "all",
        "custom"
      ],
      "description": "Time window: all (all-time, the default), 7d, 30d, 1d (last 24h), 1h, 15m, or custom (then set from/to). Use a rolling window like 7d for 'this week' / 30d for 'last 30 days'."
    },
    "from": {
      "type": "string",
      "description": "Custom window start as an ISO date or date-time. Only with range=custom."
    },
    "to": {
      "type": "string",
      "description": "Custom window end as an ISO date or date-time. Only with range=custom."
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1000,
      "description": "Max breakdown rows (group-by only; default 100)."
    },
    "query": {
      "type": "string",
      "maxLength": 200,
      "description": "Free text matched against each link's short path, title, and destination URL."
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "inactive"
      ],
      "description": "active = live right now; inactive = off (manually or by schedule). Schedule-aware."
    },
    "created": {
      "type": "string",
      "enum": [
        "1h",
        "24h",
        "7d",
        "30d"
      ],
      "description": "Creation-time window: within the last 1h, 24h, 7d, or 30d."
    },
    "edited": {
      "type": "string",
      "enum": [
        "1h",
        "24h",
        "7d",
        "30d"
      ],
      "description": "Last-edit window (1h|24h|7d|30d). Creation counts as the initial edit."
    },
    "createdVia": {
      "type": "string",
      "enum": [
        "web",
        "import",
        "chat",
        "api",
        "mcp"
      ],
      "description": "How the link was created: web, import, chat, api, or mcp."
    },
    "hasCollection": {
      "type": "boolean",
      "description": "true = in at least one collection; false = uncollected."
    },
    "schedule": {
      "type": "string",
      "enum": [
        "upcoming",
        "completed"
      ],
      "description": "upcoming = has an activation/deactivation still to fire; completed = schedule fully in the past. Unscheduled links match neither."
    },
    "attribution": {
      "type": "string",
      "enum": [
        "utm",
        "signals",
        "any"
      ],
      "description": "Which attribution the link CARRIES: utm = a utm_* param on its destination URL; signals = a QR code carries signals; any = carries either (spoken to a user as \"Either\")."
    },
    "targetHost": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 20,
      "description": "Where the link POINTS, its destination host (e.g. cnn.com), as hostnames. A leading `www.` is ignored on both sides, so cnn.com matches www.cnn.com — pass the bare host, never both spellings. User-facing word: \"destination\" (never say \"target host\" to a user)."
    },
    "collectionId": {
      "type": "string",
      "pattern": "^col_[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$",
      "description": "Scope to one specific collection (analytics-only). Mutually exclusive with the object-attribute filters and with linkId."
    },
    "linkId": {
      "type": "string",
      "pattern": "^lnk_[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$",
      "description": "Scope to one specific link by its id (analytics-only) — the click counterpart to opening that link's dashboard. Mutually exclusive with the object-attribute filters and with collectionId. Click dimensions (country, browser, …) still apply on top."
    },
    "negate": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "status",
          "created",
          "edited",
          "createdVia",
          "hasCollection",
          "schedule",
          "attribution",
          "targetHost"
        ]
      },
      "description": "Object-scope dimensions to invert, e.g. [\"status\"] for clicks from links that are NOT active. Free text is not negatable."
    },
    "country": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 60,
      "description": "ISO country codes of the click (e.g. US, GB)."
    },
    "continents": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "europe",
          "africa",
          "asia",
          "north-america",
          "south-america",
          "oceania",
          "antarctica"
        ]
      },
      "maxItems": 7,
      "description": "Named continent groupings; expand to their countries."
    },
    "region": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 50,
      "description": "Region / state of the click."
    },
    "city": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 50,
      "description": "City of the click."
    },
    "browser": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 30,
      "description": "Browser name (e.g. Chrome, Safari)."
    },
    "os": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 30,
      "description": "Operating system (e.g. iOS, Windows)."
    },
    "deviceType": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 10,
      "description": "Device type (e.g. mobile, desktop, tablet)."
    },
    "referrerDomain": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 50,
      "description": "Referring domain of the click."
    },
    "shortDomain": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 20,
      "description": "The link's own short-domain host(s) the click came through, as hostnames."
    },
    "fromQr": {
      "type": "boolean",
      "description": "true = QR scans only; false = ordinary (non-QR) clicks only."
    },
    "isBot": {
      "type": "boolean",
      "description": "true = automated traffic only; false = humans only."
    },
    "botType": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 15,
      "description": "Traffic class (ai_assistant, crawler, fetcher, …)."
    },
    "botName": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "maxItems": 30,
      "description": "Bot product name (e.g. \"GPTBot\")."
    },
    "timeZone": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "IANA time zone (e.g. `Europe/Copenhagen`) for `day` bucketing and custom `from`/`to` bounds. Default: UTC."
    }
  },
  "additionalProperties": false
}