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
Section titled βWhen to Use ThisβValue Utilities
Handle edge cases β defaults for undefined/null, type checks, coercion.
Examples
Section titled β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
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.
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
Section titled βRelated VariablesβSame category: Value
Under the Hood
Section titled β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 ? defaultValue : data.def; 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