min β GTM Variable Template for Number
min EXTENDED Number
Returns the minimum (smallest) value from an array of numbers.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβMinimum of positive numbers
INPUT
Numbers to Compare: [{arg: 10}, {arg: 25}, {arg: 15}, {arg: 5}]
OUTPUT
5
Minimum with mixed signs
INPUT
Numbers to Compare: [{arg: -10}, {arg: 0}, {arg: 15}, {arg: -3}, {arg: 8}]
OUTPUT
-10
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.
min
Numbers to Compare
πΎ A list of numbers to find the minimum value from. Non-numeric values will be ignored.
Supported formats:
β Number: 42, 3.14
β Variable reference
*** Minimum of positive numbers***
*** Minimum with mixed signs***
Supported formats:
β Number: 42, 3.14
β Variable reference
*** Minimum of positive numbers***
*** Minimum with mixed signs***
β
Input Setup
Input Function (optional)
βοΈ Optional pre-processing function applied to the extracted numbers array before finding the minimum (e.g., filter values, transform array). Note: Values are extracted from the table's
arg property before this function is applied.Result Handling
Output Function (optional)
βοΈ Optional function to apply to the minimum value before returning it (e.g.,
val => val * 2, val => Math.abs(val)). Useful for chaining transformations on the output.Numbers to Compare list
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
min()
Related Variables
Section titled βRelated VariablesβSame category: Number
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Returns the minimum value from an array of numbers. * * @param {Array} data.src - Array of objects with 'arg' property (Direct mode) or array of numbers (Apply mode). * @param {Array} data.add - Additional numbers to include in the comparison (Apply mode only). * @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 processing. * * @returns {number} The minimum value found, or NaN if the array is empty or contains no valid numbers. * * @framework ggLowCodeGTMKit */const min = function(numberArray, additionalNumbers) { const additional = additionalNumbers || []; const combined = additional.length > 0 ? numberArray.concat(additional) : numberArray; const validNumbers = combined.filter(arg => typeof arg === 'number' && arg === arg);
if (validNumbers.length === 0) return 0/0; // NaN
let result = validNumbers[0]; for (let i = 1; i < validNumbers.length; i++) { if (validNumbers[i] < result) { result = validNumbers[i]; } } return result;};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// min - Direct mode// ===============================================================================const extractArgumentValues = (items) => items.map(item => item ? item.arg : null);const applyCast = (castFn, value) => safeFunction(castFn)(value);const extractedValues = extractArgumentValues(data.src);const value = applyCast(data.pre, extractedValues);return out(min(value));// ===============================================================================// min(...) β Apply Mode// ===============================================================================/*return function(numberArray) { const extractAdditionalValues = (items) => items ? items.map(item => item ? item.arg : null) : []; const additionalNumbers = extractAdditionalValues(data.add); return out(min(numberArray, additionalNumbers));};*/π§ͺ View Test Scenarios (8 tests)
β
'[example] Minimum of positive numbers'β
Test finding minimum from negative numbersβ
'[example] Minimum with mixed signs'β
Test with empty array returns NaNβ
Test with single numberβ
Test finding minimum with additional numbers includedβ
Test with floor value from additional numbersβ
Test with empty chained array but additional numbers provided