getKeys — GTM Variable Template for Object
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
[]
GTM Configuration
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
Same category: Object
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