falseTo — GTM Variable Template for Value
falseTo CORE Value
Replaces false values with a default. Non-false values pass through unchanged.
When to Use This
Value Utilities
Handle edge cases — defaults for undefined/null, type checks, coercion.
Examples
False returns default
INPUT
Value To Check: false
Default Value: default
Default Value: default
OUTPUT
default
True passes through
INPUT
Value To Check: true
Default Value: default
Default Value: default
OUTPUT
true
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
falseTo
Value To Check
💾 The value to check for false.
Supported formats:
✓ Any type
Supported formats:
✓ Any type
Default Value
💾 The value to return if the input is false.
Supported formats:
✓ Any type
Supported formats:
✓ Any type
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 string
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
Default Value string
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
falseTo()
Related Variables
Same category: Value
Under the Hood
📜 View Implementation Code
/**
* Replaces false with a specific default value.
*
* @param {any} data.src - The value to check.
* @param {any} data.def - The default value to return if the value is false.
* @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 {any} Returns the original value if it's not false, otherwise returns the default value.
*
* @framework ggLowCodeGTMKit
*/
const falseTo = function(value, defaultValue) {
return value === false ? defaultValue : value;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// falseTo - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(falseTo(value, data.def));
// ===============================================================================
// falseTo(...) – Apply Mode
// ===============================================================================
/*
return function(value, defaultValue) {
defaultValue = data.rp1 ? data.def : defaultValue;
return out(falseTo(value, defaultValue));
};
*/🧪 View Test Scenarios (5 tests)
✅ '[example] False returns default'
✅ '[example] True passes through'
✅ String value - returns original value
✅ Zero value - returns original zero value
✅ Null value - returns original null value