{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://justinsumner.dev/schema/interaction.json",
  "version": "1.0.0",
  "title": "Client Interaction Event Schema (v1.0.0)",
  "description": "Authoritative telemetry data contract and interaction event specification for justinsumner.dev client components and dataLayer pipeline.",
  "type": "object",
  "required": [
    "event",
    "event_id",
    "event_time",
    "interaction"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri-reference",
      "description": "URI reference to this validation schema."
    },
    "schema_version": {
      "type": "string",
      "const": "1.0.0",
      "description": "Semantic version (SemVer) of the data contract specification."
    },
    "event": {
      "type": "string",
      "description": "Standardized interaction event verb indicating the nature of the action.",
      "enum": [
        "page_view",
        "section_view",
        "navigation_click",
        "cta_click",
        "content_click",
        "external_link_click",
        "social_click",
        "tag_click",
        "contact_click",
        "ui_toggle",
        "interaction"
      ]
    },
    "event_id": {
      "type": "string",
      "pattern": "^js_[0-9]+_[a-z0-9]+$",
      "description": "Unique deterministic token generated at the interaction moment for client/server deduplication."
    },
    "event_time": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix timestamp in seconds when the interaction occurred."
    },
    "interaction": {
      "type": "object",
      "description": "Validated core UI component payload capturing the objective facts of the interaction.",
      "required": [
        "component",
        "label",
        "is_outbound"
      ],
      "properties": {
        "component": {
          "type": "string",
          "description": "Semantic identifier of the UI component originating the interaction (e.g., 'sidebar_nav', 'hero', 'card', 'post_nav', 'mobile_header')."
        },
        "label": {
          "type": "string",
          "description": "Machine-readable slug or identifier representing the action target."
        },
        "position": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "description": "Optional 1-indexed ordinal position within a list, menu, or card grid."
        },
        "section_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Identifier for the enclosing section container (e.g., 'sidebar', 'field_notes', 'recent_projects', 'header')."
        },
        "text": {
          "type": [
            "string",
            "null"
          ],
          "description": "Sanitized inner text or accessible label of the interacted element."
        },
        "target_url": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri-reference",
          "description": "Destination URI or path if the interaction initiates navigation."
        },
        "is_outbound": {
          "type": "boolean",
          "description": "Flag indicating whether the destination link navigates off-domain."
        },
        "state": {
          "type": [
            "string",
            "null"
          ],
          "description": "Optional component state indicator (e.g., 'open', 'closed', 'active')."
        }
      },
      "additionalProperties": false
    },
    "context": {
      "type": [
        "object",
        "null"
      ],
      "description": "Extensible environmental context bag preserving custom dimension quotas.",
      "properties": {
        "page_path": {
          "type": "string",
          "description": "Current URL pathname at event time."
        },
        "page_title": {
          "type": "string",
          "description": "Document title at event time."
        },
        "referrer": {
          "type": [
            "string",
            "null"
          ],
          "description": "Document referrer URL if available."
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
