๐๐๐๐๐๐๐ ๐๐๐๐๐ Lazy Generator (Advanced) - Object โ GTM Variable Template for GTM
๐๐๐๐๐๐๐ ๐๐๐๐๐ Lazy Generator (Advanced) - Object CORE GTM
Generates an object from global and event-specific parameters using a command table pattern.
Examples
Global parameters
INPUT
Add Global Parameter (not Lazy and shared): true
gpm: [
Add Event Parameter (Lazy): false
gpm: [
Add Event Parameter (Lazy): false
OUTPUT
{tracker_id: 'UA-12345', send_page_view: 'true'}
Event parameters match
INPUT
Add Global Parameter (not Lazy and shared): false
Add Event Parameter (Lazy): true
epm: [
inp: purchase
urm: false
Add Event Parameter (Lazy): true
epm: [
inp: purchase
urm: false
OUTPUT
{transaction_id: 'TX-123'}
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
Read-only Preview
๐๐๐๐๐๐๐ ๐๐๐๐๐ Lazy Generator (Advanced) - Object
OBJECT โฌ
โ Include global parameters that are always added to the output object, regardless of event matching.
โ Include event-specific parameters that are only evaluated and added when the input variable matches.
globalParam
-------------------------------------------------------- Global Parameters โฌ--------------------------------------------------------
๐พ Global parameters that are always included in the output object.
Process as:
โข Value: Use as-is
โข Data Layer Variable: Read from dataLayer using the value as path
โข Lazy Variable: Evaluate function on execution
Process as:
โข Value: Use as-is
โข Data Layer Variable: Read from dataLayer using the value as path
โข Lazy Variable: Evaluate function on execution
Global ParameterValueProcess as
โ
โ
eventParam
--------------------------------------------------------- Event Parameters โฌ--------------------------------------------------------
Input Variable
๐ The variable to match against event parameter input patterns.
Example:
Example:
{{Event Name}} or {{Page Type}}Enable regex pattern matching for event parameter inputs. When unchecked, uses exact string matching.
๐พ Event-specific parameters that are only included when the Input Pattern matches the Input Variable above.
Input Pattern:
โข Exact match (default):
โข Regex match (if enabled):
Process as:
โข Value: Use as-is
โข Data Layer Variable: Read from dataLayer
โข Lazy Variable: Evaluate function on execution
Input Pattern:
โข Exact match (default):
"page_view"โข Regex match (if enabled):
"^purchase.*"Process as:
โข Value: Use as-is
โข Data Layer Variable: Read from dataLayer
โข Lazy Variable: Evaluate function on execution
Input PatternEvent ParameterValueProcess as
โ
โ
Property Access
Setter Function (optional)
โ๏ธ Optional function to customize how values are assigned:
Default behavior:
Use this for:
โข Deep path assignment
โข Validation before setting
โข Custom assignment logic
(obj, key, value) => {...}Default behavior:
obj[key] = value (shallow assignment).Use this for:
โข Deep path assignment
โข Validation before setting
โข Custom assignment logic
Result Handling
Output Function (optional)
โ๏ธ Optional function to transform the final object before returning it (e.g.,
obj => JSON.stringify(obj), obj => Object.freeze(obj)). Useful for chaining transformations on the output.Related Variables
Same category: GTM
Under the Hood
๐ View Implementation Code
/**
* Creates a parameter object for tracker commands with global and event-specific parameters.
* Event parameters are evaluated only when input matches the condition.
*
* @param {boolean} data.agp - Whether to include global parameters.
* @param {Array<{key: string, val: any, typ?: string}>} data.gpm - Global parameters (always included).
* @param {boolean} data.aep - Whether to include event parameters.
* @param {Array<{key: string, val: any, typ?: string, inp: string}>} data.epm - Event parameters with input matching.
* @param {string} data.inp - Input variable to match against event parameters.
* @param {boolean} data.urm - Whether to use regex matching (true) or exact matching (false).
* @param {Function} [data.set] - Optional custom setter function (defaults to shallow assignment).
* @param {Function|string} [data.out] - Optional output handler.
*
* @returns {Object} Parameter object with applied transformations.
*
* @framework ggLowCodeGTMKit
*/
const copyFromDataLayer = require('copyFromDataLayer');
const globalParameters = data.agp ? (data.gpm || []) : [];
const eventParameters = data.aep ? (data.epm || []) : [];
const inputVariable = data.inp;
const useRegex = data.urm;
const matchRule = function(pattern, value, isRegex) {
if (isRegex) {
return value && value.toString().match(pattern);
}
return pattern === value;
};
const applyTypToVal = function(arr) {
return arr.map(item => {
let val = item.val;
if (item.typ === 'dlv') {
val = copyFromDataLayer(val);
} else if (item.typ === 'lzv' && typeof val === 'function') {
val = val();
}
return {
key: item.key,
val: val
};
});
};
const setShallow = (obj, key, value) => {
obj[key] = value;
};
const setter = typeof data.set === 'function' ? data.set : setShallow;
const assignFromPairs = (targetObj, keyValuePairs, setterFn) => {
keyValuePairs.forEach(pair => {
setterFn(targetObj, pair.key, pair.val);
});
return targetObj;
};
const eventParametersToKeep = eventParameters.filter(x => matchRule(x.inp, inputVariable, useRegex));
let finalTable = globalParameters.concat(eventParametersToKeep);
finalTable = applyTypToVal(finalTable);
const result = assignFromPairs({}, finalTable, setter);
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
return out(result);
___WEB_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "read_data_layer",
"versionId": "1"
},
"param": [
{
"key": "allowedKeys",
"value": {
"type": 1,
"string": "any"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]๐งช View Test Scenarios (10 tests)
โ
'[example] Global parameters'
โ
'[example] Event parameters match'
โ
Event parameters with no match - should return empty object
โ
Event parameters with regex match - should include parameters matching regex pattern
โ
Combination of global and event parameters - should merge both
โ
Lazy Variable processing - should evaluate function
โ
Multiple event parameter matches with regex - should include all matching patterns
โ
No parameters enabled - should return empty object
โ
Custom setter and output function - should apply custom logic
โ
Data Layer Variable processing - should read from dataLayer