Skip to content

itemPluckProperty — GTM Variable Template for Items

VARIABLES › ITEMS
itemPluckProperty CORE Items

Extracts values from an array of objects by property name, filtering out null/undefined values.


When to Use This

GA4 Ecommerce

Build and transform ecommerce data structures for GA4 event tracking.

Filtering

Select or exclude items from collections based on criteria or predicates.

Extraction

Pull specific values, segments, or patterns from complex data structures.


Examples

Pluck property values
INPUT
Items (Array of Objects with shared schema): [{name: "John", age: 30}, {name: "Jane", age: 25}, {name: "Bob", age: 35}]
Property Name: name
OUTPUT
["John", "Jane", "Bob"]
Empty array returns empty
INPUT
Items (Array of Objects with shared schema): []
Property Name: name
OUTPUT
[]

GTM Configuration

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

itemPluckProperty
Items (Array of Objects with shared schema)
💾 Array of objects to extract values from.

Supported formats:
  ✓ Array
Property Name
💾 Property name to extract from each object.

Supported formats:
  ✓ String
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.
Items (Array of Objects with shared schema) array
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
Property Name string
itemPluckProperty()


Under the Hood

📜 View Implementation Code
/**
 * Extracts values from an array of objects by property name, filtering out null/undefined values.
 *
 * @param {Array} data.src - Array of objects to extract values from.
 * @param {string} data.prp - Property name to extract from each object.
 * @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 {Array} Array of extracted values with null/undefined filtered out.
 *
 * @framework ggLowCodeGTMKit
 */
const itemPluckProperty = function(items, property) {
    const values = items.map(function(item) {
        return item && item[property] !== undefined ? item[property] : null;
    }).filter(value => value != null); // null == undefined returns true
    return values;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// itemPluckProperty - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(itemPluckProperty(value, data.prp));
// ===============================================================================
// itemPluckProperty(...) – Apply Mode
// ===============================================================================
/*
return function(value, property) {
   property = data.rp1 ? data.prp : property;
   return out(itemPluckProperty(value, property));
};
*/
🧪 View Test Scenarios (5 tests)
✅ '[example] Pluck property values'
✅ Array with some objects missing the property - filters out undefined values
✅ Array with null values in property - filters out null values
✅ '[example] Empty array returns empty'
✅ Array with nested property access - extracts nested values