Skip to content

🧩 OR β€” GTM Variable Template for Logic

VARIABLES β€Ί LOGIC
🧩 OR CORE Logic
Direct (.tpl)

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.


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.


First truthy returned
INPUT
Values To Test: [
{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}
]
OUTPUT
false

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
or()


πŸ“œ 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