Skip to main content
Version: 1.3.0

Conditional Event

An event demonstrating if/then/else conditional properties. The postal code format depends on the selected country.

DataLayer Example

conditional options:

window.dataLayer.push({
"event": "address_submitted",
"$schema": "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/web/conditional-event.json",
"country": "US",
"postal_code": "90210",
"state": "CA"
});

Event Properties

PropertyTypeConstraintsExamplesDescription
eventstringrequired
"address_submitted"
The name of the event.
const: "address_submitted"
$schemastringconst: "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/web/conditional-event.json"
"https://tracking-docs-demo.buchert.digital/schemas/1.3.0/web/conditional-event.json"
Defines the structure of the event. This can be used to validate an event against the schema provided.
countrystringrequired
"US"
The user's country code.
enum: [US, CA]
iThe properties below define the condition. When the condition is met, the “Then” branch applies. Otherwise, the “Else” branch applies.If
countryobjectrequired
"US"
const: "US"
postal_codestringrequired
"90210"
US ZIP code (5-digit format).
pattern: /^[0-9]{5}$/
statestringminLength: 2
"CA"
US state abbreviation.
maxLength: 2
View Raw JSON Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/web/conditional-event.json",
  "title": "Conditional Event",
  "description": "An event demonstrating if/then/else conditional properties. The postal code format depends on the selected country.",
  "x-tracking-targets": [
    "web-datalayer-js"
  ],
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Defines the structure of the event. This can be used to validate an event against the schema provided.",
      "const": "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/web/conditional-event.json"
    },
    "event": {
      "type": "string",
      "const": "address_submitted",
      "description": "The event name.",
      "examples": [
        "address_submitted"
      ]
    },
    "country": {
      "type": "string",
      "description": "The user's country code.",
      "enum": [
        "US",
        "CA"
      ],
      "examples": [
        "US"
      ]
    }
  },
  "required": [
    "event",
    "country"
  ],
  "if": {
    "properties": {
      "country": {
        "const": "US"
      }
    },
    "required": [
      "country"
    ]
  },
  "then": {
    "properties": {
      "postal_code": {
        "type": "string",
        "description": "US ZIP code (5-digit format).",
        "pattern": "^[0-9]{5}$",
        "examples": [
          "90210"
        ]
      },
      "state": {
        "type": "string",
        "description": "US state abbreviation.",
        "minLength": 2,
        "maxLength": 2,
        "examples": [
          "CA"
        ]
      }
    },
    "required": [
      "postal_code"
    ]
  },
  "else": {
    "properties": {
      "postal_code": {
        "type": "string",
        "description": "Canadian postal code (letter-number format).",
        "pattern": "^[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$",
        "examples": [
          "K1A 0B1"
        ]
      },
      "province": {
        "type": "string",
        "description": "Canadian province abbreviation.",
        "examples": [
          "ON"
        ]
      }
    },
    "required": [
      "postal_code"
    ]
  }
}