Skip to content

identity — GTM Variable Template for Value

VARIABLES › VALUE
identity EXTENDED Value

Returns the input value unchanged. Useful as a passthrough function.



Examples

String passthrough
INPUT
Source Value: hello world
OUTPUT
hello world
Number passthrough
INPUT
Source Value: 42
OUTPUT
42

GTM Configuration

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

identity
Source Value
💾 The input value to return as-is.

Supported formats:
  ✓ Any
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.
Source Value any
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
identity()


Under the Hood

📜 View Implementation Code
/**
* Returns the source value as-is.
* 
* @param {*} data.src - The input value to return.
* @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 returning.
* 
* @returns {*} Returns the input src, optionally transformed by out.
*
* @framework ggLowCodeGTMKit
*/
const identity = function(value) {
   return value;
};

const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);

// ===============================================================================
// identity - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(identity(value));
// ===============================================================================
// identity() – Apply Mode
// ===============================================================================
/*
return function(value) {
  return out(identity(value));
};
*/
🧪 View Test Scenarios (5 tests)
✅ '[example] String passthrough'
✅ '[example] Number passthrough'
✅ Object input - should return unchanged
✅ Boolean input - should return unchanged
✅ Null input - should return null