isInRange — GTM Variable Template for Condition
isInRange CORE Condition
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
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
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
GTM Configuration
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
Same category: Condition
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 ? data.min : min;
max = data.rp2 ? data.max : 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