isInRange β GTM Variable Template for Logic
isInRange CORE Logic
Checks if a given value falls within a specified range (inclusive). Returns false if the value or boundaries cannot be converted to numbers.
When to Use This
Section titled βWhen to Use ThisβConditional Logic
Branch logic based on conditions β if/else, ternary, boolean gates.
Type Conversion
Safely convert between data types β strings, numbers, booleans, arrays, objects.
Comparison
Test equality, containment, and ordering between values.
Examples
Section titled βExamplesβValue in range
INPUT
Value To Check: 5
Minimum Value: 1
Maximum Value: 10
Minimum Value: 1
Maximum Value: 10
OUTPUT
true
Value below range
INPUT
Value To Check: 0
Minimum Value: 1
Maximum Value: 10
Minimum Value: 1
Maximum Value: 10
OUTPUT
false
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.
isInRange
Value To Check
πΎ The value to check if it's within the range.
Supported formats:
β Number
β Stringified Number
Supported formats:
β Number
β Stringified Number
Minimum Value
π The minimum value of the range (inclusive).
Supported formats:
β Number
β Stringified Number
Supported formats:
β Number
β Stringified Number
Maximum Value
π The maximum value of the range (inclusive).
Supported formats:
β Number
β Stringified Number
Supported formats:
β Number
β Stringified Number
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.
Value To Check number
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
Minimum Value number
Maximum Value number
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
isInRange()
Related Variables
Section titled βRelated VariablesβSame category: Logic
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Checks if a given value is within a specified range. * * @param {any} data.src - The value to check. * @param {any} data.min - The minimum value of the range. * @param {any} data.max - The maximum value of the range. * @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 checking. * * @returns {boolean} True if the value is within the range (inclusive), false otherwise or if any value cannot be converted to a number. * * @framework ggLowCodeGTMKit */const makeNumber = require('makeNumber');
const isInRange = function(value, min, max) { value = makeNumber(value); if (typeof value !== 'number') { return false; } const minNum = makeNumber(min); const maxNum = makeNumber(max); return value >= minNum && value <= maxNum;};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// isInRange - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(isInRange(value, data.min, data.max));// ===============================================================================// isInRange(...) β Apply Mode// ===============================================================================/*return function(value, min, max) { min = data.rp1 ? min : data.min; max = data.rp2 ? max : data.max; return out(isInRange(value, min, max));};*/π§ͺ View Test Scenarios (7 tests)
β
'[example] Value in range'β
'[example] Value below range'β
Value above range - should return falseβ
Value equal to minimum - should return true (inclusive)β
Value equal to maximum - should return true (inclusive)β
String number within range - should convert and return trueβ
Non-numeric value - should return false