π§© 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
Section titled β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
Section titled β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
Live Sandbox
Section titled βLive Sandboxβ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
Section titled βRelated VariablesβSame category: Logic
Under the Hood
Section titled β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