1"use strict" 2 3document.addEventListener('DOMContentLoaded', function () { 4 document.querySelectorAll('[data-gtm-on]').forEach(function (element) { 5 var data = element.dataset, 6 trigger = data.gtmOn; 7 8 // Set the event listener. 9 element.addEventListener(trigger, function () { 10 // Check for custom variable. 11 var variable = data.gtmVar || 'dataLayer', 12 entry = {}; 13 14 // Instantiate the dataLayer variable if it doesn't exist. 15 window[variable] = window[variable] || []; 16 17 data.gtmEvent && (entry.event = String(data.gtmEvent)); 18 data.gtmCategory && (entry.category = String(data.gtmCategory)); 19 data.gtmLabel && (entry.label = String(data.gtmLabel)); 20 data.gtmValue && (entry.value = Number(data.gtmValue)); 21 data.gtmFields && (entry.fields = JSON.parse(data.gtmFields)); 22 23 // Push the entry onto the dataLayer. 24 window[variable].push(entry); 25 }); 26 }); 27});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.