absolute — GTM Variable Template for Number
absolute EXTENDED Number
Returns the absolute (non-negative) value of a number.
Examples
Positive stays positive
INPUT
Number: 42
OUTPUT
42
Negative to positive
INPUT
Number: -42
OUTPUT
42
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
absolute
Number
💾 The number to calculate the absolute value for.
Supported formats:
✓ Number
Supported formats:
✓ Number
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the input before internal logic (e.g., parse string to number, apply mathematical operations). Internal transformations such as absolute value calculation will still apply afterward.
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result before returning it (e.g., num => num + ' units', val => val.toFixed(2) for decimal formatting). Useful for chaining transformations on the output.
Number number
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
absolute()
Related Variables
Same category: Number
Under the Hood
📜 View Implementation Code
/**
* Returns the absolute value of the provided input.
*
* @param {number} data.num - The number to calculate the absolute value for.
* @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 num before calculation.
*
* @returns {number} The absolute value of the input number.
*
* @framework ggLowCodeGTMKit
*/
const Math = require('Math');
const absolute = function(num) {
return Math.abs(num);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// absolute - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const num = applyCast(data.pre, data.num);
return out(absolute(num));
// ===============================================================================
// absolute() – Apply Mode
// ===============================================================================
/*
return function(num) {
return out(absolute(num));
};
*/🧪 View Test Scenarios (9 tests)
✅ '[example] Positive stays positive'
✅ '[example] Negative to positive'
✅ Zero - should return 0
✅ Negative decimal - should return positive decimal
✅ String negative number - should convert and return positive value
✅ Null input - should return 0
✅ Undefined input - should return NaN
✅ Empty string - should return 0
✅ Array with single string number - should convert and return positive value