multiply — GTM Variable Template for Number
multiply CORE Number
Multiplies two numbers and returns the product. Returns undefined if invalid.
When to Use This
Number Operations
Arithmetic, rounding, clamping, and mathematical transformations on numeric values.
Examples
Multiply positive numbers
INPUT
First Number: 5
Second Number: 3
Second Number: 3
OUTPUT
15
String numbers multiplied
INPUT
First Number: 6
Second Number: 7
Second Number: 7
OUTPUT
42
Invalid returns undefined
INPUT
First Number: hello
Second Number: 5
Second Number: 5
OUTPUT
undefined
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
multiply
First Number
💾 The first number to multiply.
Supported formats:
✓ Number
✓ String
Supported formats:
✓ Number
✓ String
Second Number
💾 The second number to multiply.
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 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.
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.
multiply()
Related Variables
Same category: Number
Under the Hood
📜 View Implementation Code
/**
* Multiplies two numbers and returns the result.
*
* @param {*} data.src - The first number to multiply.
* @param {*} data.mul - The second number to multiply.
* @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 multiplication.
*
* @returns {number|undefined} The result of the multiplication, or undefined if inputs are invalid.
*
* @framework ggLowCodeGTMKit
*/
const makeNumber = require('makeNumber');
const multiply = function(num1, num2) {
const number1 = makeNumber(num1);
const number2 = makeNumber(num2);
if (number1 === number1 && number2 === number2) {
return number1 * number2;
}
return undefined;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// multiply - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(multiply(value, data.mul));
// ===============================================================================
// multiply(...) – Apply Mode
// ===============================================================================
/*
return function(value, multiplier) {
multiplier = data.rp1 ? data.mul : multiplier;
return out(multiply(value, multiplier));
};
*/🧪 View Test Scenarios (5 tests)
✅ '[example] Multiply positive numbers'
✅ Negative number multiplication - should return negative product
✅ '[example] String numbers multiplied'
✅ Decimal numbers - should handle decimals
✅ '[example] Invalid returns undefined'