### GTM Variable Setup Example Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt Illustrates the configuration steps for creating a GA4 Ecommerce Items DLV Version 1 variable in GTM. Ensure to repeat this for each required ecommerce parameter. ```plaintext Variable setup (repeat for each parameter needed): 1. Go to Variables → User-Defined Variables → New 2. Choose "GA4 Ecommerce Items Data Layer Version 1 Variable" as type 3. Set "Standard Ecommerce Parameters" to desired value (e.g., "items") 4. If selecting "items", optionally enable "Remove null or empty Values from Items" 5. Name the variable, e.g.: ecom - items - DLV - V1 6. Save ``` -------------------------------- ### GA4 Ecommerce Data Layer Push Example Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt Demonstrates a typical data layer push for GA4 ecommerce events, including clearing the previous ecommerce object and pushing a new event with item details. This example highlights how Data Layer Version 1 reads only the latest push, contrasting with Version 2's merging behavior. ```javascript // Data layer push example (website implementation) window.dataLayer = window.dataLayer || []; // Step 1: Clear the ecommerce object (recommended best practice) window.dataLayer.push({ ecommerce: null }); // Step 2: Push the ecommerce event window.dataLayer.push({ event: 'add_to_cart', ecommerce: { currency: 'USD', value: 29.99, coupon: 'SUMMER10', items: [ { item_id: 'SKU_001', item_name: 'Blue T-Shirt', item_category: 'Apparel', price: 29.99, quantity: 1 } ] } }); // With DLV Version 1, GTM reads ONLY the above push. // With DLV Version 2, GTM would merge with any previous ecommerce push. // Variable configured with ecomParam = "items" returns: // [{ item_id: 'SKU_001', item_name: 'Blue T-Shirt', item_category: 'Apparel', price: 29.99, quantity: 1 }] // Variable configured with ecomParam = "value" returns: // 29.99 // Variable configured with ecomParam = "coupon" returns: // "SUMMER10" ``` -------------------------------- ### GA4 Event Tag Configuration Example Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt Shows how to integrate the custom DLV variable into a GA4 Event tag. This pattern is applicable for all standard GA4 ecommerce events. ```plaintext GA4 Event Tag setup: - Tag Type: Google Analytics: GA4 Event - Event name: purchase (or add_to_cart, view_item, etc.) - Event Parameters: items → {{ecom - items - DLV - V1}} transaction_id → {{ecom - transaction_id - DLV - V1}} value → {{ecom - value - DLV - V1}} currency → (use a standard DLV for currency) ``` -------------------------------- ### GA4 Ecommerce Data Layer Push with Null Values Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt Illustrates a GA4 ecommerce data layer push containing null or empty string values within the items array. This example shows the output when the `removeNullfromItems` parameter is enabled versus disabled, demonstrating how nulls and empty strings are handled. ```javascript // Data layer push with null values in items window.dataLayer.push({ ecommerce: null }); window.dataLayer.push({ event: 'purchase', ecommerce: { transaction_id: 'T_12345', value: 59.98, items: [ { item_id: 'SKU_001', item_name: 'Blue T-Shirt', item_category: 'Apparel', item_category2: null, // null — will become undefined and be dropped item_variant: '', // empty string — will become undefined and be dropped price: 29.99, quantity: 2 } ] } }); // Variable configured with ecomParam = "items", removeNullfromItems = true returns: // [ // { // item_id: 'SKU_001', // item_name: 'Blue T-Shirt', // item_category: 'Apparel', // // item_category2 and item_variant are omitted entirely // price: 29.99, // quantity: 2 // } // ] // Variable configured with ecomParam = "items", removeNullfromItems = false returns: // [ // { // item_id: 'SKU_001', // item_name: 'Blue T-Shirt', // item_category: 'Apparel', // item_category2: null, // sent to GA4 as the string "null" // item_variant: '', // price: 29.99, // quantity: 2 // } // ] ``` -------------------------------- ### GA4 Ecommerce Parameter Mapping Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt Maps standard GA4 ecommerce parameter names to their corresponding data layer keys. This is useful for configuring GTM variables to read ecommerce data. ```javascript const parameterMap = { 'items': 'ecommerce.items', 'item_list_id': 'ecommerce.item_list_id', 'item_list_name': 'ecommerce.item_list_name', 'creative_name': 'ecommerce.creative_name', 'creative_slot': 'ecommerce.creative_slot', 'promotion_id': 'ecommerce.promotion_id', 'promotion_name': 'ecommerce.promotion_name', 'location_id': 'ecommerce.location_id', 'payment_type': 'ecommerce.payment_type', 'shipping_tier': 'ecommerce.shipping_tier', 'transaction_id': 'ecommerce.transaction_id', 'affiliation': 'ecommerce.affiliation', 'coupon': 'ecommerce.coupon', 'value': 'ecommerce.value', 'shipping': 'ecommerce.shipping', 'tax': 'ecommerce.tax' }; // GTM variable naming convention (recommended): // {{ecom - items - DLV - V1}} // {{ecom - transaction_id - DLV - V1}} // {{ecom - value - DLV - V1}} // Usage in a GA4 Event Tag (GTM Tag configuration): // Tag Type: Google Analytics: GA4 Event // Event Parameters: // items → {{ecom - items - DLV - V1}} // transaction_id → {{ecom - transaction_id - DLV - V1}} // value → {{ecom - value - DLV - V1}} // coupon → {{ecom - coupon - DLV - V1}} // shipping → {{ecom - shipping - DLV - V1}} // tax → {{ecom - tax - DLV - V1}} ``` -------------------------------- ### GTM Sandboxed JS for Ecommerce Data Source: https://context7.com/gtm-templates-knowit-experience/gtm-ga4-ecom-items-dlv-version-1-variable/llms.txt This simplified code represents the template's core logic using GTM's sandboxed `copyFromDataLayer` API. It reads the most recent ecommerce push and returns the selected parameter value. ```javascript const dataLayer = require('copyFromDataLayer'); // Version 1 = reads only the most recently pushed value for the key let ecom = dataLayer('ecommerce', 1); if (ecom) { switch (data.ecomParam) { case 'transaction_id': return ecom.transaction_id; case 'value': return ecom.value; case 'coupon': return ecom.coupon; case 'shipping': return ecom.shipping; case 'tax': return ecom.tax; case 'payment_type': return ecom.payment_type; case 'shipping_tier': return ecom.shipping_tier; case 'affiliation': return ecom.affiliation; // ... (all other scalar parameters) default: // ecomParam === 'items' ecom = ecom.items; if (data.removeNullfromItems && ecom) { ecom.forEach(function(object) { for (let key in object) { if (object[key] === null || object[key] === '') { object[key] = undefined; // GTM drops undefined keys } } }); } return ecom; } } return undefined; // ecommerce key not found in data layer ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.