1const dl = drupalSettings.gtm ? drupalSettings.gtm.settings.data_layer : 'dataLayer'; 2window[dl] = window[dl] || []; 3 4// Define the gtag function for this scope. 5function gtag(){window[dl].push(arguments);} 6 7(function (drupalSettings) { 8 if (!drupalSettings.gtm) {return;} 9 const config = drupalSettings.gtm; 10 11 // Setting default consent before gtm.js 12 // Ref: https://developers.google.com/tag-platform/security/concepts/consent-mode#consent-types 13 if (config.consentMode === true) { 14 gtag('consent', 'default', { 15 ad_personalization: 'denied', 16 ad_storage: 'denied', 17 ad_user_data: 'denied', 18 analytics_storage: 'denied', 19 functionality_storage: 'denied', 20 personalization_storage: 'denied', 21 security_storage: 'denied', 22 wait_for_update: 500, 23 }); 24 } 25 26 window[dl].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); 27 const gtmSettings = config.settings; 28 if (gtmSettings.include_classes === true) { 29 window[dl].push({ 30 'gtm.allowlist': gtmSettings.allowlist_classes ?? [], 31 'gtm.blocklist': gtmSettings.blocklist_classes ?? [], 32 }); 33 } 34 35 let gtm_environment = ''; 36 if (gtmSettings.include_environment === true) { 37 const gtm_auth = gtmSettings.environment_token ?? ''; 38 const gtm_preview = gtmSettings.environment_id ?? ''; 39 gtm_environment = `>m_auth=${gtm_auth}>m_preview=${gtm_preview}>m_cookies_win=x`; 40 } 41 config.tagIds.forEach(function (tagId) { 42 const script = document.createElement('script'); 43 script.async = true; 44 const dLink = dl != 'dataLayer' ? `&l=${dl}` : ''; 45 script.src = `https://www.googletagmanager.com/gtm.js?id=${tagId}${gtm_environment}${dLink}`; 46 script.type = 'text/javascript'; 47 48 if (gtmSettings.include_script_attributes === true && gtmSettings.script_attributes.length) { 49 gtmSettings.script_attributes.forEach(function(script_attribute) { 50 const [name, value = ''] = script_attribute.split(/\|/); 51 script.setAttribute(name, value) 52 }); 53 } 54 55 document.getElementsByTagName('head')[0].appendChild(script); 56 }); 57})(drupalSettings);
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.