Skip to content

getType β€” GTM Variable Template for Value

VARIABLES β€Ί VALUE
getType EXTENDED Value
Direct (.tpl) Apply (.tpl)

Returns the type of the provided value as a string.



String type
INPUT
Value To Check: hello
OUTPUT
string
Number type
INPUT
Value To Check: 42
OUTPUT
number
Object type
INPUT
Value To Check: {key: 'value'}
OUTPUT
object

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

getType
Value To Check
πŸ’Ύ The value whose type is to be evaluated.

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.
Value To Check any
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
getType()


πŸ“œ View Implementation Code
/**
* Returns the type of the given value.
*
* @param {any} data.src - The value whose type is to be evaluated.
* @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 type.
*
* @returns {string} The type of the value (e.g., "string", "number", "object", "array" etc.).
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const getTypeOf = function(input) {
return getType(input);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// getTypeOf - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(getTypeOf(value));
// ===============================================================================
// getTypeOf() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(getTypeOf(value));
};
*/
πŸ§ͺ View Test Scenarios (10 tests)
βœ… '[example] String type'
βœ… '[example] Number type'
βœ… Boolean type - should return boolean
βœ… '[example] Object type'
βœ… Array type - should return array
βœ… Function type - should return function
βœ… Null type - should return null
βœ… Undefined type - should return undefined
βœ… NaN type - should return number
βœ… Infinity type - should return number