Template: Variable Comparison (Boolean Conditions)
GTM variable template for comparing two values with boolean operators. Supports equals, not equals, contains, not contains, starts with, and not starts with conditions. Perfect for URL filtering and conditional trigger logic.
General Description
This macro template provides boolean comparison functionality between two variables, allowing flexible conditional checks within Google Tag Manager.
Resources
| GitHub Repository |
| Template Gallery |
Input
The template accepts three input parameters:
Input Variable: Variable to be checkedCondition: Type of comparison to performUser Input: Value to compare against
Supported Conditions
- Equals
- Not equals
- Contains
- Not contains
- Starts with
- Does not start with
Execution Flow
Input Acquisition
const inputA = data.inputVar; const inputB = data.inputUsr; const condition = data.condition;Conditional Evaluation Specific checks are performed based on the selected condition:
- Direct equality comparison
- Substring search
- String start verification
Use Cases
- URL filtering
- Input validation
- Conditional checks in tags and triggers
Usage Example
// Check if a URL contains a specific domain
const data = {
inputVar: 'https://www.google.com',
inputUsr: 'google',
condition: 'contains',
};
// Will return: trueImportant Notes
- Supports string comparisons only
- Case-sensitive
- Always returns a boolean value