pluckProperty β GTM Variable Template for Items
pluckProperty EXTENDED Items
Extracts values from an array of objects by property name, filtering out null/undefined values.
When to Use This
Section titled β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
Section titled β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
Property Name: name
OUTPUT
["John", "Jane", "Bob"]
Empty array returns empty
INPUT
Items (Array of Objects with shared schema): []
Property Name: name
Property Name: name
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.
pluckProperty
Items (Array of Objects with shared schema)
πΎ Array of objects to extract values from.
Supported formats:
β Array
Supported formats:
β Array
Property Name
πΎ Property name to extract from each object.
Supported formats:
β String
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
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
pluckProperty()
Related Variables
Section titled βRelated VariablesβSame category: Items
Under the Hood
Section titled β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 pluckProperty = 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);// ===============================================================================// pluckProperty - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(pluckProperty(value, data.prp));// ===============================================================================// pluckProperty(...) β Apply Mode// ===============================================================================/*return function(value, property) { property = data.rp1 ? property : data.prp; return out(pluckProperty(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