{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uncorrelate.com/schemas/event-batch.schema.json",
  "title": "Event batch",
  "description": "Body of POST https://ingest.uncorrelate.com/v1/batch. Every SDK (Unity, Flutter, HTTP) sends exactly this. Auth: header `Authorization: Bearer <key>`. Publishable keys (`uc_pub_<env>_…`) ship inside game builds and can only write events; secret keys (`uc_sec_<env>_…`) are for game servers and may also set player properties for any player. The key names the game and environment, so neither appears in the body.",
  "type": "object",
  "required": ["events"],
  "additionalProperties": false,
  "properties": {
    "sent_at": {
      "type": "string",
      "format": "date-time",
      "description": "Device clock when the batch left. The server uses it with received_at to correct device clock skew on every event's `time`."
    },
    "sdk": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": { "enum": ["unity", "flutter", "http", "import"] },
        "version": { "type": "string" }
      }
    },
    "events": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "items": { "$ref": "#/$defs/event" }
    }
  },
  "$defs": {
    "event": {
      "type": "object",
      "required": ["event", "insert_id", "time"],
      "anyOf": [{ "required": ["player_id"] }, { "required": ["device_id"] }],
      "additionalProperties": false,
      "properties": {
        "event": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,63}$",
          "description": "Any name the game wants. Names starting with `$` are reserved for SDK-generated events ($identify, $purchase, $session_start...). Unknown names are accepted and show up in the catalog as `new`."
        },
        "insert_id": {
          "type": "string",
          "minLength": 8,
          "maxLength": 64,
          "description": "Client-generated UUID. Dedup key: the same insert_id within 7 days is dropped. SDKs retry with the same id."
        },
        "time": { "type": "string", "format": "date-time", "description": "When it happened on the device. Events older than 30 days or more than 1 h in the future are rejected per event." },
        "player_id": { "type": "string", "maxLength": 128, "description": "The game's own account id, once known. Set via identify()." },
        "device_id": { "type": "string", "maxLength": 128, "description": "Install-scoped id the SDK generates and persists. Bridges pre-login events to player_id." },
        "session_id": { "type": "string", "maxLength": 64 },
        "properties": {
          "type": "object",
          "description": "Free-form. Scalars, arrays of scalars, or one level of nesting (flattened as a.b). Max 255 keys, 8 KB serialized. Types are inferred and tracked per key in the catalog; a type change is flagged, not rejected.",
          "maxProperties": 255
        },
        "player_properties": {
          "type": "object",
          "description": "Upserted onto the player profile ($set semantics). Use `$set_once` inside for first-touch values.",
          "maxProperties": 255
        },
        "context": { "$ref": "#/$defs/context" },
        "revenue": { "$ref": "purchase.schema.json" }
      }
    },
    "context": {
      "type": "object",
      "description": "Filled automatically by SDKs. All optional.",
      "additionalProperties": false,
      "properties": {
        "platform": { "enum": ["ios", "android", "web", "steam", "console", "other"] },
        "app_version": { "type": "string" },
        "build": { "type": "string" },
        "os_version": { "type": "string" },
        "device_model": { "type": "string" },
        "locale": { "type": "string" },
        "country": { "type": "string", "description": "ISO 3166-1 alpha-2. If absent, derived from IP at ingest; the IP itself is never stored." },
        "timezone": { "type": "string" },
        "install_source": { "type": "string" },
        "campaign": { "type": "string" },
        "idfv": { "type": "string" },
        "gaid": { "type": "string", "description": "Only when the player consented. SDKs never send IDFA." }
      }
    }
  },
  "examples": [
    {
      "sent_at": "2026-12-05T14:03:11Z",
      "sdk": { "name": "unity", "version": "0.1.0" },
      "events": [
        {
          "event": "level_complete",
          "insert_id": "9b2f6a0e-5d1c-4b7e-9a40-0c2d61b2f0a1",
          "time": "2026-12-05T14:02:58Z",
          "player_id": "p_8812",
          "device_id": "d_0f3a",
          "session_id": "s_77",
          "properties": { "level": 42, "world": "ember", "attempt": 3, "stars": 2, "boosters": ["hammer"] },
          "context": { "platform": "ios", "app_version": "4.12.1" }
        }
      ]
    }
  ]
}
