Conditional Event
An event demonstrating if/then/else conditional properties. The postal code format depends on the selected country.
DataLayer Example
conditional options:
- When condition is met
- When condition is not met
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"
});
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": "K1A 0B1",
"province": "ON"
});
Event Properties
| Property | Type | Constraints | Examples | Description |
|---|---|---|---|---|
| event | string | required | | The name of the event. |
const: "address_submitted" | ||||
| $schema | string | const: "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. |
| country | string | required | | The user's country code. |
enum: [US, CA] | ||||
| If | ||||
| country | object | required | | |
const: "US" | ||||
| postal_code | string | required | | US ZIP code (5-digit format). |
pattern: /^[0-9]{5}$/ | ||||
| state | string | minLength: 2 | | US state abbreviation. |
maxLength: 2 | ||||
View Raw JSON Schema
{
: "https://json-schema.org/draft/2020-12/schema",
: "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"
]
}
}