{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/snitcher/json-schema/snitcher-session-schema.json",
  "title": "Session",
  "description": "A representation of a session",
  "x-generated": "2026-11-16",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/snitcher-openapi.yml#/components/schemas/Session",
  "properties": {
    "uuid": {
      "type": "string",
      "format": "uuid"
    },
    "organisation_uuid": {
      "type": "string",
      "format": "uuid"
    },
    "visitor_uuid": {
      "description": "The visitor (client) ID of the browser this session belongs to, the same value the tracker sends as `anonymous_id` and Spotter returns. Stable per browser until its storage is cleared, and shared across every session of that visitor, so it can be joined against an ID minted client-side.",
      "type": "string",
      "format": "uuid"
    },
    "started_at": {
      "type": "string",
      "format": "date-time"
    },
    "ended_at": {
      "type": "string",
      "format": "date-time"
    },
    "location": {
      "$ref": "#/$defs/Location"
    },
    "browser": {
      "description": "The browser used during the session",
      "type": [
        "string",
        "null"
      ]
    },
    "referrer": {
      "description": "The referring URL from which the session originated",
      "type": [
        "string",
        "null"
      ]
    },
    "device_type": {
      "description": "The type of device used (e.g., desktop, mobile, tablet)",
      "type": [
        "string",
        "null"
      ]
    },
    "views": {
      "description": "Deprecated: Use `events` instead. Only contains pageview events.",
      "type": "array",
      "items": {
        "properties": {
          "visited_at": {
            "type": "string",
            "format": "date-time"
          },
          "time_on_page": {
            "type": "integer"
          },
          "url": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "deprecated": true
    },
    "events": {
      "description": "All tracking events in the session (pageviews, form submissions, custom events, clicks, downloads)",
      "type": "array",
      "items": {
        "$ref": "#/$defs/SessionEvent"
      }
    }
  },
  "type": "object",
  "$defs": {
    "Location": {
      "title": "Location",
      "description": "Representation of an location in API responses",
      "properties": {
        "country": {
          "description": "Maps an Organisation object to an API response.",
          "type": "string"
        },
        "state": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "latitude": {
          "type": "number"
        },
        "longitude": {
          "type": "number"
        }
      },
      "type": "object"
    },
    "SessionEvent": {
      "title": "SessionEvent",
      "description": "A tracking event within a session. Additional fields depend on event_type.",
      "properties": {
        "event_type": {
          "description": "The type of event",
          "type": "string",
          "enum": [
            "pageview",
            "form_submit",
            "form_abandon",
            "track",
            "click",
            "download"
          ]
        },
        "url": {
          "description": "The URL where the event occurred",
          "type": "string"
        },
        "triggered_at": {
          "description": "When the event was triggered",
          "type": "string",
          "format": "date-time"
        },
        "time_on_page": {
          "description": "Time spent on page in seconds (pageview only)",
          "type": [
            "integer",
            "null"
          ]
        },
        "form_id": {
          "description": "The form element ID (form_submit and form_abandon)",
          "type": [
            "string",
            "null"
          ]
        },
        "form_name": {
          "description": "The form name (form_submit and form_abandon)",
          "type": [
            "string",
            "null"
          ]
        },
        "time_spent": {
          "description": "Seconds spent interacting with the form before leaving (form_abandon only)",
          "type": [
            "integer",
            "null"
          ]
        },
        "fields": {
          "description": "Form field values captured (form_submit and form_abandon)",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "properties": {
              "name": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            },
            "type": "object"
          }
        },
        "name": {
          "description": "Event name (track, click, download only)",
          "type": [
            "string",
            "null"
          ]
        },
        "properties": {
          "description": "Event properties (track, click, download only)",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "properties": {
              "name": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            },
            "type": "object"
          }
        }
      },
      "type": "object"
    }
  }
}