addValues — GTM Variable Template for Number
addValues EXTENDED Number
Adds two number values and returns the sum. Returns undefined if inputs are invalid.
Examples
Invalid input returns undefined
INPUT
First Number: 50
Second Number: undefined
Second Number: undefined
OUTPUT
undefined
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
addValues
First Number
💾 The first number (the base value to add to).
Supported formats:
✓ Number
✓ String
Supported formats:
✓ Number
✓ String
Second Number
💾 The second number (the value to add).
Supported formats:
✓ Number
✓ String
Supported formats:
✓ Number
✓ String
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the input before internal logic (e.g., convert string to number, apply transformations). Internal transformations such as number conversion will still apply afterward.
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result before returning it (e.g., num => num.toFixed(2), val => val + ' total' for formatting). Useful for chaining transformations on the output.
First Number number
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
Second Number number
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
addition()
Related Variables
Same category: Number
Under the Hood
📜 View Implementation Code
/**
* Adds two numbers and returns the result.
*
* @param {*} data.src - The first number (the base value to add to).
* @param {*} data.add - The second number (the value to add).
* @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 addition.
*
* @returns {number|undefined} The result of the addition, or undefined if invalid.
*
* @framework ggLowCodeGTMKit
*/
const makeNumber = require('makeNumber');
const addition = function(augend, addend) {
const num1 = makeNumber(augend);
const num2 = makeNumber(addend);
if (num1 === num1 && num2 === num2) {
return num1 + num2;
}
return undefined;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// addition - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(addition(value, data.add));
// ===============================================================================
// addition(...) – Apply Mode
// ===============================================================================
/*
return function(value, addend) {
addend = data.rp1 ? data.add : addend;
return out(addition(value, addend));
};
*/🧪 View Test Scenarios (5 tests)
✅ Valid numbers addition - returns sum
✅ String numbers addition - converts and adds
✅ Negative numbers addition - handles negative values
✅ Invalid first parameter - returns undefined
✅ '[example] Invalid input returns undefined'