Skip to content

itemOmit β€” GTM Variable Template for Items

VARIABLES β€Ί ITEMS
itemOmit EXTENDED Items
Direct (.tpl) Apply (.tpl)

Removes specified properties from each object in an array.



Remove single property
INPUT
Source Array: [
{name: 'Shirt', price: 10, internalId: 'abc'},
{name: 'Pants', price: 20, internalId: 'def'}
]
Properties to Remove:
[{value: 'internalId'}]
OUTPUT
[ {name: 'Shirt', price: 10}, {name: 'Pants', price: 20} ]
Remove multiple properties
INPUT
Source Array: [
{name: 'Shirt', price: 10, cost: 5, internalId: 'abc'},
{name: 'Pants', price: 20, cost: 8, internalId: 'def'}
]
Properties to Remove:
[{value: 'cost'}, {value: 'internalId'}]
OUTPUT
[ {name: 'Shirt', price: 10}, {name: 'Pants', price: 20} ]

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

itemOmit
Source Array
πŸ’Ύ The array of objects to process.

Supported formats:
  βœ“ Items variable: {{ecommerce.items}}
  βœ“ Array literal: [{name: "Shirt", price: 10, internalId: "abc"}]
Properties to Remove
πŸ’Ύ The property name to remove from each item (e.g., "internalId", "cost", "_private").

*** Remove single property***

*** Remove multiple properties***
βŠ–
Input Setup
Input Function (optional)
βš™οΈ Optional pre-processing function applied to the source array before processing.
Result Handling
Output Function (optional)
βš™οΈ Optional function to apply to the resulting array before returning it (e.g., arr => arr.filter(x => x.price > 0) to keep only items with a positive price).
Source Array array
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
Properties to Remove list
itemOmit()


πŸ“œ View Implementation Code
/**
* Creates a new array of objects with specified properties removed from each item.
* Preserves all other existing properties.
*
* @param {Array} data.src - The array of objects to process.
* @param {Array} data.kys - Array of objects with property names to remove.
* @param {Function|string} [data.out] - Optional output handler.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function to transform src before processing.
*
* @returns {Array} A new array of objects with the specified properties removed.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const createFlatArrayFromValues = function(list, property) {
const result = [];
if (!list) return 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 if (val) {
result.push(val);
}
}
return result;
};
const itemOmit = function(arr, keys) {
if (getType(arr) !== 'array') return [];
if (!keys || keys.length === 0) return arr;
const omitMap = {};
for (let i = 0; i < keys.length; i++) {
omitMap[keys[i]] = true;
}
return arr.map(function(item) {
if (item == null || typeof item !== 'object') return item;
const result = {};
for (const k in item) {
if (item.hasOwnProperty(k) && !omitMap[k]) {
result[k] = item[k];
}
}
return result;
});
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// itemOmit - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
const keys = createFlatArrayFromValues(data.kys, "value");
return out(itemOmit(value, keys));
// ===============================================================================
// itemOmit(...) – Apply Mode
// ===============================================================================
/*
return function(arr) {
const keys = createFlatArrayFromValues(data.kys, "value");
return out(itemOmit(arr, keys));
};
*/
πŸ§ͺ View Test Scenarios (6 tests)
βœ… '[example] Remove single property'
βœ… '[example] Remove multiple properties'
βœ… Non-existent property is ignored
βœ… Empty keys returns original array
βœ… Invalid src returns empty array
βœ… Preserves items with null values for non-omitted properties