Skip to content

every β€” GTM Variable Template for Array

VARIABLES β€Ί ARRAY
every CORE Array
Direct (.tpl) Apply (.tpl)

Returns true if all items in the array satisfy the given predicate function.


Array Processing

Iterate, filter, map, and reshape arrays of items for batch data operations.

GA4 Ecommerce

Build and transform ecommerce data structures for GA4 event tracking.


All match predicate
INPUT
Array To Test: [2, 4, 6, 8]
Predicate Function: function(x) { return x % 2 === 0; }
OUTPUT
true
Not all match
INPUT
Array To Test: [2, 4, 5, 8]
Predicate Function: function(x) { return x % 2 === 0; }
OUTPUT
false

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

every
Array To Test
πŸ’Ύ The array of values to evaluate against the predicate function.

Supported formats:
  βœ“ Array
Predicate Function
βš–οΈ A predicate function that receives each value and returns true or false.

Supported formats:
  βœ“ Function
Input Setup
Input Function (optional)
βš™οΈ Optional pre-processing function applied to the input 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 + ' €', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.
Array To Test array
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
Predicate Function function
every()


πŸ“œ View Implementation Code
/**
* Returns true if every item in the input array satisfies the given predicate function.
*
* @param {Array} data.src - The array of values to evaluate.
* @param {Function} data.prd - A predicate function that receives each value and returns true or false.
* @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function to transform src before evaluation.
*
* @returns {boolean} True if all values pass the predicate, false otherwise or if input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const every = function(arr, predicate) {
if (getType(arr) !== 'array' || typeof predicate !== 'function') {
return false;
}
return arr.every(predicate);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// every - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(every(value, data.prd));
// ===============================================================================
// every(...) – Apply Mode
// ===============================================================================
/*
return function(value, predicate) {
predicate = data.rp1 ? predicate : data.prd;
return out(every(value, predicate));
};
*/
πŸ§ͺ View Test Scenarios (8 tests)
βœ… '[example] All match predicate'
βœ… '[example] Not all match'
βœ… Empty array - should return true
βœ… All strings pass length check - should return true
βœ… Not all strings pass length check - should return false
βœ… Non-array input - should return false
βœ… Null input - should return false
βœ… Non-function predicate - should return false