multiply β GTM Variable Template for Number
multiply CORE Number
Multiplies two numbers and returns the product. Returns undefined if invalid.
When to Use This
Section titled βWhen to Use ThisβNumber Operations
Arithmetic, rounding, clamping, and mathematical transformations on numeric values.
Examples
Section titled β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
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.
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
Section titled βRelated VariablesβSame category: Number
Under the Hood
Section titled β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 ? multiplier : data.mul; 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'