๐๐๐๐๐ From Values Generator - Array โ GTM Variable Template for GTM
๐๐๐๐๐ From Values Generator - Array CORE GTM
Generates an array from a simple GTM table of values.
When to Use This
GTM Utilities
Access GTM-specific APIs: dataLayer, debug mode, container settings.
Type Conversion
Safely convert between data types โ strings, numbers, booleans, arrays, objects.
Extraction
Pull specific values, segments, or patterns from complex data structures.
Examples
Array from table values
INPUT
Array Values: [
OUTPUT
['apple', 'banana', 'cherry']
Empty table returns empty
INPUT
Array Values: []
OUTPUT
[]
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
๐๐๐๐๐ From Values Generator - Array
ARRAY โฌ
Array Values
๐พ Define the values to include in the array.
Each row will become an element in the resulting array. Empty values and variables are preserved.
Each row will become an element in the resulting array. Empty values and variables are preserved.
โ
Value Processing
Mapper Function (optional)
โ๏ธ Optional function to transform each individual value before adding it to the array:
Use this for:
โข Split strings:
โข Trim whitespace:
โข Parse numbers:
โข Transform case:
Note: This applies to each value individually, before creating the final array.
val => transformedValUse this for:
โข Split strings:
val => val.split(',')โข Trim whitespace:
val => val.trim()โข Parse numbers:
val => parseFloat(val)โข Transform case:
val => val.toUpperCase()Note: This applies to each value individually, before creating the final array.
Result Handling
Output Function (optional)
โ๏ธ Optional function to transform the entire array before returning it:
Use this for:
โข Filter array:
โข Flatten nested arrays:
โข Convert to string:
โข Sort array:
Note: This applies to the complete array after all values have been processed.
arr => transformedArrUse this for:
โข Filter array:
arr => arr.filter(x => x)โข Flatten nested arrays:
arr => arr.flat()โข Convert to string:
arr => arr.join(',')โข Sort array:
arr => arr.sort()Note: This applies to the complete array after all values have been processed.
Array Values list
๐ Result Handling โ Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
getType()
Related Variables
Same category: GTM
Under the Hood
๐ View Implementation Code
/**
* Creates an array from a simple table by extracting and optionally transforming values from the 'val' column.
*
* @param {Array<Object>} data.tbl - The array of objects representing the simple table.
* @param {Function} [data.map] - Optional function to transform each value before adding to array.
* @param {Function|string} [data.out] - Optional output handler.
*
* @returns {Array} An array of values extracted from the 'val' column.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const simpleTable = getType(data.tbl) === 'array' && data.tbl || [];
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const mapper = safeFunction(data.map);
const result = [];
for (let i = 0; i < simpleTable.length; i++) {
const item = simpleTable[i];
if (item) {
result.push(mapper(item.val));
}
}
const out = safeFunction(data.out);
return out(result);๐งช View Test Scenarios (10 tests)
โ
'[example] Array from table values'
โ
'[example] Empty table returns empty'
โ
Table with undefined and empty values - should preserve them
โ
Table with null items - should skip null items
โ
Mapper function to transform each value - should apply to all values
โ
Mapper with split function - should split each string into array
โ
Output function to filter array - should remove empty values
โ
Output function to join array - should convert to CSV string
โ
Combination of mapper and output - should apply mapper first then output
โ
Different value types - should preserve types