wrapInArray — GTM Variable Template for Array
Examples
Wrap string
INPUT
Value To Wrap: hello
OUTPUT
["hello"]
Wrap number
INPUT
Value To Wrap: 42
OUTPUT
[42]
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
wrapInArray
Value To Wrap
💾 The value to be wrapped into an array.
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.
Value To Wrap string
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
wrapInArray()
Related Variables
Same category: Array
Under the Hood
📜 View Implementation Code
/**
* Wraps the provided input into a new array and returns the array.
*
* @param {any} data.src - The value to be wrapped into the array.
* @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 wrapping.
*
* @returns {Array} The new array containing the input value as the only element.
*
* @framework ggLowCodeGTMKit
*/
const wrapInArray = function(input) {
const result = [];
result.push(input);
return result;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// wrapInArray - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(wrapInArray(value));
// ===============================================================================
// wrapInArray() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(wrapInArray(value));
};
*/🧪 View Test Scenarios (4 tests)
✅ '[example] Wrap string'
✅ '[example] Wrap number'
✅ Object value - wraps in array
✅ Null value - wraps null in array