You are viewing documentation for an older version.
Reuse Event Rules across Tracking Plans using Includes Alpha
5 minute read
Experimental feature
includesis an experimental feature that is disabled by default. You must explicitly opt in by enabling experimental mode and theeventRuleIncludesflag before you can use it. Experimental features are functional but can change or be removed in future releases, so avoid relying on them in production workflows.
This guide shows you how to share event rules between Tracking Plans using the experimental includes feature in Rudder CLI.
Overview
The includes directive lets a Tracking Plan inherit event rules from another Tracking Plan. This eliminates duplication when multiple plans share common rules.
When you apply your project, Rudder CLI:
- Expands each
includesreference - Pulls in the matching
event_ruleentries from the referenced Tracking Plan - Merges them into the current plan before pushing to RudderStack
The resulting Tracking Plan behaves exactly as if those rules had been defined inline.
Compatibility
| Spec version | Supported |
|---|---|
rudder/v0.1 (kind: tp) | Yes |
rudder/v1 (kind: tracking-plan) | No |
If you use includes in a rudder/v1 (kind: tracking-plan) spec, Rudder CLI rejects validation with:
error[datacatalog/tracking-plans/spec-syntax-valid]: includes is not supported for tracking-plan v1 event rulesPrerequisites
Before using includes:
- Install Rudder CLI and authenticate the tool.
- Set up a Data Catalog project with Events and Properties defined in it.
- Create at least one
rudder/v0.1Tracking Plan in the same project whose event rules you want to reuse.
Enable the experimental flag
Using includes requires two settings to be enabled:
- Experimental mode (
experimental): The master switch for all experimental features. While it is off, Rudder CLI ignores every experimental flag. - The
eventRuleIncludesflag: Turns onincludesspecifically.
If either is disabled, Rudder CLI rejects any rule that uses includes during validation with the error 'includes' is not supported.
Enable both using any of the following methods.
Edit your Rudder CLI configuration file (~/.rudder/config.json) and set both keys:
{
"experimental": true,
"flags": {
"eventRuleIncludes": true
}
}This is the most durable option for local development, since the setting persists across sessions.
Experimental mode must be on before the experimental subcommands will run. Enable it via the config file (above) or by exporting RUDDERSTACK_CLI_EXPERIMENTAL=true, then enable the flag:
rudder-cli experimental enable eventRuleIncludesVerify that the flag is enabled:
rudder-cli experimental listThe output lists eventRuleIncludes as enabled.
Use environment variables in CI/CD pipelines or non-interactive shells:
export RUDDERSTACK_CLI_EXPERIMENTAL=true
export RUDDERSTACK_X_EVENT_RULE_INCLUDES=trueSee Use includes in CI/CD for a complete example.
All experimental settings default tofalseand require explicit opt-in. Experimental-flag environment variables take the formRUDDERSTACK_X_<FLAG_NAME>, where the flag name is converted to upper snake case (eventRuleIncludes→RUDDERSTACK_X_EVENT_RULE_INCLUDES).
Reference syntax
To include event rules from another Tracking Plan, add a rule with an includes block instead of an event block. The $ref value follows this pattern:
#/tp/<tracking-plan-id>/event_rule/<rule-id-or-*>| Pattern | Meaning |
|---|---|
#/tp/common-rules-plan/event_rule/* | Include all event rules from common-rules-plan. |
#/tp/common-rules-plan/event_rule/identify-rule | Include only the identify-rule from common-rules-plan. |
Where:
<tracking-plan-id>is theidof the Tracking Plan whose event rules you want to reuse. It must exist in the same project (same Data Catalog directory) and must also use therudder/v0.1spec.<rule-id-or-*>is theidof a specific event rule, or*to include every event rule from the referenced plan.
Include all event rules
Use the * wildcard to inherit every event rule defined in another Tracking Plan. In the example below, the crm-plan plan includes all rules from common-rules-plan alongside its own rule:
# data-catalog/trackingplans/crm-plan.yaml
version: "rudder/v0.1"
kind: "tp"
metadata:
name: "crm-plan"
spec:
display_name: "CRM - Salesforce Plan"
id: "crm-plan"
rules:
- includes:
$ref: "#/tp/common-rules-plan/event_rule/*"
id: "common-rules-include"
type: "event_rule"
- event:
$ref: "#/events/crm-events/opportunity-converted"
allow_unplanned: false
identity_section: "properties"
id: "opportunity-converted-rule"
properties:
- $ref: "#/properties/common-properties/project-code"
required: true
type: "event_rule"After expansion, crm-plan contains every event rule from common-rules-plan, plus its own opportunity-converted-rule.
Include a specific event rule
To reuse only one rule, reference it by its id instead of using the wildcard:
rules:
- includes:
$ref: "#/tp/common-rules-plan/event_rule/identify-rule"
id: "identify-include"
type: "event_rule"
- event:
$ref: "#/events/crm-events/opportunity-converted"
id: "opportunity-converted-rule"
properties:
- $ref: "#/properties/common-properties/project-code"
required: true
type: "event_rule"This includes only the identify-rule from common-rules-plan.
Avoid including the same event into a plan more than once — whether directly or through anincludesreference. Rudder CLI flags duplicate events introduced viaincludesduring validation.
Constraints
- A rule can have either
eventorincludes, not both. Specifying both fails validation withevent and includes cannot be specified together; specifying neither fails withevent or includes is required. - An
includes-only rule does not need aneventfield — the event is inherited from the referenced plan. - The
$refvalue must match the pattern#/tp/<id>/event_rule/<id-or-*>, where IDs contain only alphanumeric characters, hyphens, and underscores. A malformed reference fails validation with'$ref' is not valid: must be of pattern #/tp/<group>/event_rule/<id-or-*>.
Validate and deploy
Validate and deploy plans that use includes exactly as you would any other Tracking Plan. Make sure experimental mode and the eventRuleIncludes flag are enabled in the same environment that runs these commands.
- Validate your definitions:
rudder-cli validate -l ~/tutorial-catalog- Review the changes before deploying:
rudder-cli apply -l ~/tutorial-catalog --dry-run- Deploy the validated Tracking Plans:
rudder-cli apply -l ~/tutorial-catalogUse includes in CI/CD
In CI/CD environments, enable experimental mode and the flag with environment variables instead of interactive commands.
jobs:
apply:
runs-on: ubuntu-latest
env:
RUDDERSTACK_CLI_EXPERIMENTAL: "true"
RUDDERSTACK_X_EVENT_RULE_INCLUDES: "true"
RUDDERSTACK_ACCESS_TOKEN: ${{ secrets.RUDDERSTACK_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@v4
# ... install Rudder CLI, then validate and applySee GitHub Actions for a full workflow.
#!/usr/bin/env bash
set -euo pipefail
export RUDDERSTACK_CLI_EXPERIMENTAL=true
export RUDDERSTACK_X_EVENT_RULE_INCLUDES=true
rudder-cli validate -l .
rudder-cli apply -l .