⚡ COMMAND TABLE › Lazy (Advanced) Generator — GTM Variable Template for GTM
⚡ COMMAND TABLE › Lazy (Advanced) EXTENDED GTM
Builds a parameter object combining global and event-specific parameters. Supports dlv and lzv types — event parameters evaluate only when the input matches their pattern.
Examples
Section titled “Examples”Global parameters
INPUT
Add Global Parameter (not Lazy and shared): true
Global Parameters: [{key: 'tracker_id', val: 'UA-12345', typ: 'val'}, {key: 'send_page_view', val: 'true', typ: 'val'}]
Add Event Parameter (Lazy): false
Global Parameters: [{key: 'tracker_id', val: 'UA-12345', typ: 'val'}, {key: 'send_page_view', val: 'true', typ: 'val'}]
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
Input Variable: {{Event}}
Use regex matching: false
Event Parameters: [{inp: 'purchase', key: 'transaction_id', val: 'TX-123', typ: 'val'}, {inp: 'page_view', key: 'page_title', val: 'Home', typ: 'val'}]
//When Event === purchase
Add Event Parameter (Lazy): true
Input Variable: {{Event}}
Use regex matching: false
Event Parameters: [{inp: 'purchase', key: 'transaction_id', val: 'TX-123', typ: 'val'}, {inp: 'page_view', key: 'page_title', val: 'Home', typ: 'val'}]
//When Event === purchase
OUTPUT
{transaction_id: 'TX-123'}
GTM Configuration
Section titled “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
⚡ COMMAND TABLE › Lazy (Advanced)
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.
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
⊖
⊖
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
Section titled “Related Variables”Same category: GTM
Under the Hood
Section titled “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 buildCommandTable = function(agp, gpm, aep, epm, inp, urm, set) { const globalParameters = agp ? (gpm || []) : []; const eventParameters = aep ? (epm || []) : []; const inputVariable = inp; const useRegex = 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 set === 'function' ? 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);
return assignFromPairs({}, finalTable, setter);};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);
return out(buildCommandTable(data.agp, data.gpm, data.aep, data.epm, data.inp, data.urm, data.set));
___WEB_PERMISSIONS___
[ { "instance": { "key": { "publicId": "read_data_layer", "versionId": "1" }, "param": [ { "key": "allowedKeys", "value": { "type": 1, "string": "any"🧪 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