Rules and Conditions¶
Rules are the decision-making engine of Dxtra Tag Manager. Each rule combines events, conditions, exceptions, and actions to control when and what happens on your pages.
Rule Logic¶
Every rule follows this evaluation pattern:
IF (any Event matches)
AND (all Conditions are true)
AND NOT (any Exception is true)
THEN (execute Action Groups)
- Events: At least one event must fire (OR logic)
- Conditions: All conditions must be true (AND logic)
- Exceptions: If any exception is true, the rule is blocked (NOT logic)
- Actions: All action groups execute (subject to distribution settings)
Conditions¶
Conditions compare a value from a data container against an expected value using an operator.
Condition Structure¶
Each condition has three parts:
- Variable: A value from a data container, using template syntax
- Operator: How to compare the values
- Value: The expected value to compare against
Template Syntax¶
Reference data container values using double curly braces:
Examples:
| Template | Source |
|---|---|
{{QueryString.utm_source}} | URL query parameter |
{{Browser.userAgent}} | Browser user agent string |
{{Environment.GA_TRACKING_ID}} | Environment variable |
{{AppState.user_logged_in}} | App state variable |
{{LocalStorage.preference}} | Browser local storage value |
{{Custom.campaign_type}} | Custom data container value |
{{ElementClick.href}} | Clicked element's href attribute |
{{BrowserError.message}} | JavaScript error message |
Operators¶
| Operator | Description | Example |
|---|---|---|
| Equal | Exact match | {{QueryString.page}} Equal home |
| Not Equal | Does not match | {{Browser.language}} Not Equal en |
| Contains | Substring match | {{Browser.userAgent}} Contains Mobile |
| Begins With | Starts with | {{QueryString.utm_source}} Begins With google |
| Ends With | Ends with | {{Browser.url}} Ends With .pdf |
| Regular Expression | Regex match | {{Browser.url}} Regular Expression \/product\/\d+ |
| Greater Than | Numeric > | {{AppState.cart_total}} Greater Than 100 |
| Greater Than Equal | Numeric >= | {{AppState.page_views}} Greater Than Equal 5 |
| Less Than | Numeric < | {{AppState.error_count}} Less Than 3 |
| Less Than Equal | Numeric <= | {{Custom.score}} Less Than Equal 50 |
| Is Defined | Value exists | {{QueryString.promo}} Is Defined |
| Is Not Defined | Value missing | {{LocalStorage.returning_user}} Is Not Defined |
Exceptions¶
Exceptions use the same structure as conditions but act as blockers. If any exception evaluates to true, the rule does not execute, regardless of whether events and conditions are met.
Use exceptions for:
- Excluding specific pages (e.g., privacy policy pages)
- Blocking rules for certain user agents (e.g., bots)
- Preventing duplicate tracking
Rule Priority¶
When multiple rules could fire simultaneously, priority determines execution order. Lower priority values execute first.
Best practices:
- 1-10: Critical rules (consent, essential functionality)
- 11-50: Standard tracking rules
- 51-100: Optional or supplementary rules
Common Rule Patterns¶
Universal Page Tracking¶
Track all page views with no conditions:
Conditional Tracking¶
Track only specific pages:
Event: Page Loaded
Condition: {{Browser.url}} Contains "/products/"
Action: Track Event "product_page_view"
Consent-Gated Rule¶
Only fire when analytics consent is granted:
Event: CMP Check
Condition: CMP analytics consent equals "true"
Action: Load JS (analytics script)
Exclude Specific Pages¶
Track everything except the privacy policy:
Event: Page Loaded
Conditions: (none)
Exception: {{Browser.url}} Contains "/privacy-policy"
Action: Track Event "page_view"
Click Tracking with Context¶
Track button clicks with additional context:
Event: Click Elements (CSS: ".purchase-btn")
Condition: {{AppState.user_logged_in}} Equal "true"
Action: Track Event "purchase_click"
Time-Based Engagement¶
Track users who stay on a placement for a set time:
Event: Tag Timer (delay: 30000ms)
Conditions: (none)
Action: Track Event "engaged_30_seconds"
Testing Rules¶
- Deploy to your development environment
- Navigate to the page with
#dxtra-debugin the URL - The debug overlay shows:
- Which rules are being evaluated
- Which conditions passed or failed
- Which actions executed
- A timeline of rule evaluation
Related Documentation¶
- Overview -- Tag Manager concepts
- Events -- Event types and configuration
- Actions -- Action types
- Action Groups -- Action group distribution
- Global Triggers -- Reusable trigger configurations
- Debugging -- Debug rule evaluation