omit — GTM Variable Template for Object
Examples
Omit single property
INPUT
Source Object: {name: 'John', age: 30, city: 'Paris'}
Properties to Omit: [{value: 'age'}]
Properties to Omit: [{value: 'age'}]
OUTPUT
John
Omit multiple properties
INPUT
Source Object: {a: 1, b: 2, c: 3, d: 4}
Properties to Omit: [{value: 'b'}, {value: 'd'}]
Properties to Omit: [{value: 'b'}, {value: 'd'}]
OUTPUT
1
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
omit
Source Object
💾 The source object to omit properties from.
Supported formats:
✓ Object variable: {{myObject}}
✓ Object literal
Supported formats:
✓ Object variable: {{myObject}}
✓ Object literal
Properties to Omit
💾 List of property names to exclude from the result object. All other properties will be included.
Supported formats:
✓ String: property name
✓ Array of strings: for multiple properties at once
*** Omit single property***
*** Omit multiple properties***
Supported formats:
✓ String: property name
✓ Array of strings: for multiple properties at once
*** Omit single property***
*** Omit multiple properties***
⊖
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the source object before omitting properties (e.g., normalize object structure, parse JSON).
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result object before returning it (e.g.,
obj => JSON.stringify(obj), obj => Object.freeze(obj)). Useful for chaining transformations on the output.Source Object object
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
Properties to Omit list
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
omit()
Related Variables
Same category: Object
Under the Hood
📜 View Implementation Code
/**
* Creates a new object by omitting specified properties from the source object.
*
* @param {Object} data.src - The source object.
* @param {Array} data.kys - Array of objects with property names to omit.
* @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 processing.
*
* @returns {Object} A new object without the specified properties.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const createFlatArrayFromValues = function(list, property) {
const result = [];
for (let i = 0; i < list.length; i++) {
const val = list[i][property];
if (getType(val) === 'array') {
for (let j = 0; j < val.length; j++) {
result.push(val[j]);
}
} else {
result.push(val);
}
}
return result;
};
const omit = function(object, keysToOmit) {
const result = {};
if (object == null || typeof object !== 'object') {
return result;
}
for (let key in object) {
if (object.hasOwnProperty(key) && keysToOmit.indexOf(key) === -1) {
result[key] = object[key];
}
}
return result;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// omit - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
const keys = createFlatArrayFromValues(data.kys, "value");
return out(omit(value, keys));
// ===============================================================================
// omit(...) – Apply Mode
// ===============================================================================
/*
return function(object, keys) {
keys = data.rp1 ? createFlatArrayFromValues(data.kys, "value") : keys;
return out(omit(object, keys));
};
*/🧪 View Test Scenarios (10 tests)
✅ '[example] Omit single property'
✅ '[example] Omit multiple properties'
✅ Test omitting non-existent property
✅ Test with empty keys array
✅ Test with array of keys in value property
✅ Test with null object returns empty object
✅ Test with undefined object returns empty object
✅ Test with non-object input returns empty object
✅ Test omitting all properties
✅ Test with nested object values preserved