getKeys β GTM Variable Template for Object
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβGet object keys
INPUT
Object Input: {name: 'John', age: 30, city: 'Paris'}
OUTPUT
['name', 'age', 'city']
Empty object returns empty
INPUT
Object Input: {}
OUTPUT
[]
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.
getKeys
Object Input
πΎ The object whose keys are to be retrieved.
Supported formats:
β Object
Supported formats:
β Object
Input Setup
Input Function (optional)
βοΈ Optional pre-processing function applied to the object before internal logic (e.g., filter properties, normalize structure). Internal transformations will still apply afterward.
Result Handling
Output Function (optional)
βοΈ Optional function to apply to the result before returning it (e.g., arr => arr.sort(), arr => arr.filter(key => key.length > 3) for filtering). Useful for chaining transformations on the output.
Object Input object
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
getKeys()
Related Variables
Section titled βRelated VariablesβSame category: Object
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Retrieves the keys of an object. * * @param {Object} data.obj - The object whose keys are to be retrieved. * @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 obj before extracting keys. * * @returns {Array} An array of the keys of the provided object. * * @framework ggLowCodeGTMKit */const Object = require('Object');
const getKeys = function(objectInput) { return Object.keys(objectInput);};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// getKeys - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const processedObject = applyCast(data.pre, data.obj);return out(getKeys(processedObject));// ===============================================================================// getKeys() β Apply Mode// ===============================================================================/*return function(value) { return out(getKeys(value));};*/π§ͺ View Test Scenarios (5 tests)
β
'[example] Get object keys'β
Object with single key - should return array with one keyβ
'[example] Empty object returns empty'β
Object with numeric keys - should return array of string keysβ
Nested object - should return only top-level keys