Event Rule Variants Alpha

Define dynamic property requirements for events based on contextual values using event rule variants.
Available Plans
  • free
  • starter
  • growth
  • enterprise

This guide shows you how to define and use event rule variants in your Tracking Plans.

Overview

Event rule variants let you define different property requirements for the same event based on a discriminating property value. This feature is particularly useful when an event needs different validation rules depending on the context in which it occurs.

info
Event rule variants use a discriminator field to determine which set of property requirements apply. The discriminator is a property whose value determines which variant case to use.

Define event rule variants

Using your preferred text editor, add variants to your event rules in the Tracking Plan YAML file:

Basic structure

Event rule variants are defined within event rules in Tracking Plans. See Variants YAML Reference for the detailed variant specification.

The following snippet is a simplified example to demonstrate the structure. See the Examples section below for real-world use cases with complete implementations.

version: rudder/0.1
kind: tp
metadata:
  name: mytrackingplan
spec:
  rules:
    - type: event_rule
      id: example_rule
      event:
        $ref: "#/events/example_events/example_event"
        allow_unplanned: false
      
      # Common properties for all variants
      properties:
        - $ref: "#/properties/common_props/property_1"
          required: true    # Discriminator property must be required
        - $ref: "#/properties/common_props/property_2"
          required: false   # Common property that may be required by variants
        - $ref: "#/properties/common_props/property_3"
          required: false   # Property used in default case
      
      variants:
        - type: discriminator
          discriminator: "#/properties/common_props/property_1"    # Must match the property defined above
          cases:
            - id: case_a
              display_name: "Case A"
              match: 
                - "value1"
                - "value2"
              description: "Description of Case A"
              properties:
                - $ref: "#/properties/common_props/property_2"
                  required: true
            
            - id: case_b
              display_name: "Case B"
              match:
                - "value3"
              description: "Description of Case B"
              properties:
                - $ref: "#/properties/common_props/property_2"
                  required: true
          
          # Default case for unmatched values
          default:
            - $ref: "#/properties/common_props/property_3"
              required: true

Each variant definition requires:

  • The discriminator type (type: discriminator)
  • The discriminating property name (discriminator)
  • One or more cases with:
    • A unique identifier (id)
    • A display name (display_name)
    • Match values (match)
    • Description (description) explaining when this case applies
    • Property requirements (properties) specific to this case
  • Optional default case (default) for when no cases match
warning

The discriminator property must be:

  • Defined in the event rule’s properties section
  • Marked as required
  • Have a type matching your match values (string, boolean, or number)

Supported discriminator types

You can use the following discriminator types in your event rule variants:

TypeDescriptionExample values
StringMatch against text values"search", "product", "category_search"
BooleanMatch true/false conditionstrue, false
NumberMatch against numeric thresholds500, 1000, 2000
info

Note that for each type:

  • You can specify multiple match values in an array
  • Values are matched exactly (no range or pattern matching)
  • String matches are case-sensitive

Examples

The following examples show variant definitions for different use cases:

Best practices

Follow these best practices when defining event rule variants:

  • Discriminator selection

    • Choose properties that clearly indicate different contexts
    • Ensure the discriminator property is always available
    • Use simple, predictable property values
  • Case definition

    • Use clear, descriptive IDs and display names
    • Group related match values in the same case
    • Include helpful descriptions
  • Property requirements

    • Include only relevant properties for each case
    • Consider required vs. optional carefully
    • Use default case for common requirements
  • Validation

    • Test all variant cases
    • Verify property references
    • Check for edge cases

Validate and deploy variants

To update your Tracking Plans with the newly-added variants, make sure to validate and deploy the changes using Rudder CLI.

info
See the End-to-end Walkthrough for detailed steps on validating and deploying Tracking Plans.

See also



Questions? Contact us by email or on Slack