๐งฉ OR โ GTM Variable Template for Logic
๐งฉ OR CORE Logic
Checks a list of parameters and returns the first truthy value. If no truthy value is found, it returns false, mimicking the logical OR (||) operator.
When to Use This
Logic Operations
Boolean algebra โ AND, OR, NOT, XOR for combining conditions.
Comparison
Test equality, containment, and ordering between values.
URL Processing
Parse, build, decode, and manipulate URLs and query parameters.
Examples
First truthy returned
INPUT
Values To Test: [
{val: false},
{val: 0},
{val: 'first truthy'},
{val: 'second truthy'}
]
{val: false},
{val: 0},
{val: 'first truthy'},
{val: 'second truthy'}
]
OUTPUT
first truthy
All falsy returns false
INPUT
Values To Test: [
{val: false},
{val: 0},
{val: ''},
{val: null},
{val: undefined}
]
{val: false},
{val: 0},
{val: ''},
{val: null},
{val: undefined}
]
OUTPUT
false
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
๐งฉ OR
OR โฌ
Values To Test (Return first truthy)
โ
Input Setup
Input Function (optional)
Optional pre-processing function applied to each value before internal logic (e.g., convert object to string, normalize case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
Optional function to apply to the result before returning it (e.g., `str => str + ' โฌ'`). Useful for chaining transformations on the output.
Values To Test (Return first truthy) list
๐ Result Handling โ Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
or()
Related Variables
Same category: Logic
Under the Hood
๐ View Implementation Code
/**
* Returns the first **truthy** `val` found in a list of parameter objects.
*
* @param {Array<Object>} ls1 - List of parameter objects to evaluate.
* @param {*} ls1[].val - Value to evaluate for truthiness
*
* @returns {*} The first truthy value (`val`) found in the list, or `false` if none is found.
*
* @framework ggLowCodeGTMKit
*/
const or = function(ls1) {
for (const parameter of ls1) {
if (parameter && parameter.val) {
return parameter.val;
}
}
return false;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const out = safeFunction(data.out);
// ===============================================================================
// or - Direct mode
// ===============================================================================
const values = (data.ls1 || []).map(item => ({val: applyCast(data.pre, item ? item.val : undefined)}));
return out(or(values));๐งช View Test Scenarios (5 tests)
โ
'[example] First truthy returned'
โ
'[example] All falsy returns false'
โ
Test first value truthy returns immediately
โ
Test with pre function that transforms values
โ
Test with pre function where all values fail condition