Skip to main content
Version: 1.2.0

Choice Event

An example event that uses oneOf and anyOf.

DataLayer Examples

user_id options:

window.dataLayer.push({
"event": "one_of_event",
"$schema": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/choice-event.json",
"user_id": "user-123",
"payment_method": {
"payment_type": "credit_card",
"card_number": "1234-5678-9012-3456",
"expiry_date": "12/26"
}
});

payment_method options:

window.dataLayer.push({
"event": "one_of_event",
"$schema": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/choice-event.json",
"user_id": "user-123",
"payment_method": {
"payment_type": "credit_card",
"card_number": "1234-5678-9012-3456",
"expiry_date": "12/26"
}
});

Event Properties

PropertyTypeConstraintsExamplesDescription
eventstringrequired
"one_of_event"
The name of the event.
const: "one_of_event"
$schemastringconst: "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/choice-event.json"
"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/choice-event.json"
Defines the structure of the event. This can be used to validate an event against the schema provided.

user_id - Select one of the following options:

The user's ID.

The user's ID as a string.

user_idstringrequired
"user-123"
The user's ID as a string.

The user's ID as an integer.

{}payment_methodobjectrequiredThe user's payment method.

Select any of the following options:

View Raw JSON Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/choice-event.json",
  "title": "Choice Event",
  "description": "An example event that uses oneOf and anyOf.",
  "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.2.0/events/choice-event.json"
    },
    "event": {
      "type": "string",
      "const": "one_of_event",
      "description": "The event name."
    },
    "user_id": {
      "description": "The user's ID.",
      "oneOf": [
        {
          "type": "string",
          "title": "User ID as String",
          "description": "The user's ID as a string.",
          "examples": [
            "user-123"
          ]
        },
        {
          "type": "integer",
          "title": "User ID as Integer",
          "description": "The user's ID as an integer.",
          "examples": [
            123
          ]
        }
      ]
    },
    "payment_method": {
      "description": "The user's payment method.",
      "type": "object",
      "anyOf": [
        {
          "title": "Credit Card",
          "type": "object",
          "properties": {
            "payment_type": {
              "type": "string",
              "description": "The type of payment.",
              "enum": [
                "credit_card",
                "debit_card"
              ],
              "examples": [
                "credit_card"
              ]
            },
            "card_number": {
              "type": "string",
              "description": "The card number.",
              "examples": [
                "1234-5678-9012-3456"
              ]
            },
            "expiry_date": {
              "type": "string",
              "description": "The card expiry date.",
              "examples": [
                "12/26"
              ]
            }
          },
          "required": [
            "card_number",
            "expiry_date"
          ]
        },
        {
          "title": "PayPal",
          "type": "object",
          "properties": {
            "payment_type": {
              "type": "string",
              "const": "paypal",
              "description": "The type of payment."
            },
            "email": {
              "type": "string",
              "format": "email",
              "description": "The PayPal account email address.",
              "examples": [
                "test@example.com"
              ]
            }
          },
          "required": [
            "email"
          ]
        }
      ]
    }
  },
  "required": [
    "event",
    "user_id",
    "payment_method"
  ]
}