Define dynamic property requirements for events based on contextual values using event rule variants.
Available Plans
free
starter
growth
enterprise
6 minute read
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.
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.1kind:tpmetadata:name:mytrackingplanspec:rules:- type:event_ruleid:example_ruleevent:$ref:"#/events/example_events/example_event"allow_unplanned:false# Common properties for all variantsproperties:- $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 casevariants:- type:discriminatordiscriminator:"#/properties/common_props/property_1"# Must match the property defined abovecases:- id:case_adisplay_name:"Case A"match:- "value1"- "value2"description:"Description of Case A"properties:- $ref:"#/properties/common_props/property_2"required:true- id:case_bdisplay_name:"Case B"match:- "value3"description:"Description of Case B"properties:- $ref:"#/properties/common_props/property_2"required:true# Default case for unmatched valuesdefault:- $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
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:
Type
Description
Example values
String
Match against text values
"search", "product", "category_search"
Boolean
Match true/false conditions
true, false
Number
Match against numeric thresholds
500, 1000, 2000
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:
Use Case: Different property requirements based on page type
This example shows how to validate different properties based on which type of page the user is viewing (search, product, or checkout):
version:rudder/0.1kind:tpmetadata:name:ecommerce_tracking_planspec:rules:- type:event_ruleid:page_viewed_ruleevent:$ref:"#/events/ecommerce_events/page_viewed"allow_unplanned:falseproperties:- $ref:"#/properties/ecommerce_properties/page_type"required:true- $ref:"#/properties/ecommerce_properties/page_url"required:falsevariants:- type:discriminatordiscriminator:"#/properties/ecommerce_properties/page_type"cases:- id:search_pagedisplay_name:"Search Results Page"match:- "search"- "search_results"- "category_search"description:"When user is on search or category pages"properties:- $ref:"#/properties/ecommerce_properties/search_term"required:true- $ref:"#/properties/ecommerce_properties/search_filters"required:false- id:product_pagedisplay_name:"Product Detail Page"match:- "product"- "product_detail"description:"When user is viewing a specific product"properties:- $ref:"#/properties/ecommerce_properties/product_id"required:true- $ref:"#/properties/ecommerce_properties/product_category"required:true- $ref:"#/properties/ecommerce_properties/product_price"required:true- $ref:"#/properties/ecommerce_properties/recommendation_source"required:false- id:checkout_pagedisplay_name:"Checkout Flow Pages"match:- "checkout"- "payment"- "review_order"description:"When user is in checkout process"properties:- $ref:"#/properties/ecommerce_properties/checkout_step"required:true- $ref:"#/properties/ecommerce_properties/payment_method"required:falsedefault:- $ref:"#/properties/ecommerce_properties/page_url"required:true
Key takeaways
Uses string-based page type discrimination
Handles multiple match values per case (for example, search, search_results, category_search)
Shows required and optional properties for each page type
Includes a default case for unmatched page types
Use Case: Different requirements based on user subscription status
This example demonstrates how to validate different properties based on whether a user has premium access or not:
version:rudder/0.1kind:tpmetadata:name:user_management_planspec:rules:- type:event_ruleid:feature_accessed_ruleevent:$ref:"#/events/user_events/feature_accessed"allow_unplanned:falseproperties:- $ref:"#/properties/user_properties/user_id"required:true- $ref:"#/properties/user_properties/is_premium"required:truevariants:- type:discriminatordiscriminator:"#/properties/user_properties/is_premium"cases:- id:premium_userdisplay_name:"Premium Users"match:- truedescription:"Premium subscribers with full access"properties:- $ref:"#/properties/user_properties/subscription_tier"required:true- $ref:"#/properties/user_properties/feature_access_level"required:true- id:free_userdisplay_name:"Free Users"match:- falsedescription:"Free tier users with limitations"properties:- $ref:"#/properties/user_properties/trial_days_remaining"required:false- $ref:"#/properties/user_properties/usage_limit"required:true
Key takeaways
Uses simple boolean discrimination (true/false)
Shows different property requirements for premium vs. free users
Demonstrates required user identification for all cases
Shows how to handle optional properties like trial information
Use Case: Different requirements based on order total amount
This example shows how to validate different properties based on the order value, with special handling for high-value orders:
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.