1const dl = drupalSettings.gtm ? drupalSettings.gtm.settings.data_layer : 'dataLayer'; 2window[dl] = window[dl] || []; 3 4(function (drupalSettings) { 5 if (!drupalSettings.gtm) {return;} 6 const config = drupalSettings.gtm; 7 8 // Append a <script> to <head>, but wait for the configured Didomi vendor 9 // to be consented first. With no vendor configured, append directly. 10 function appendWhenConsented(script, vendorId) { 11 function append() { 12 document.getElementsByTagName('head')[0].appendChild(script); 13 } 14 if (!vendorId) { append(); return; } 15 var appended = false; 16 function attempt() { 17 if (appended) return true; 18 if (window.Didomi && 19 typeof window.Didomi.getUserConsentStatusForVendor === 'function' && 20 window.Didomi.getUserConsentStatusForVendor(vendorId) === true) { 21 appended = true; 22 append(); 23 return true; 24 } 25 return false; 26 } 27 window.didomiOnReady = window.didomiOnReady || []; 28 window.didomiOnReady.push(function () { 29 if (attempt()) return; 30 var method = (window.Didomi && typeof window.Didomi.on === 'function') ? 'on' 31 : ((window.Didomi && typeof window.Didomi.addEventListener === 'function') ? 'addEventListener' : null); 32 if (method) { window.Didomi[method]('consent.changed', attempt); } 33 }); 34 } 35 36 window[dl].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); 37 const gtmSettings = config.settings; 38 if (gtmSettings.include_classes === true) { 39 window[dl].push({ 40 'gtm.allowlist': gtmSettings.allowlist_classes ?? [], 41 'gtm.blocklist': gtmSettings.blocklist_classes ?? [], 42 }); 43 } 44 45 let gtm_environment = ''; 46 if (gtmSettings.include_environment === true) { 47 const gtm_auth = gtmSettings.environment_token ?? ''; 48 const gtm_preview = gtmSettings.environment_id ?? ''; 49 gtm_environment = `>m_auth=${gtm_auth}>m_preview=${gtm_preview}>m_cookies_win=x`; 50 } 51 config.tagIds.forEach(function (tagId) { 52 const script = document.createElement('script'); 53 script.async = true; 54 const dLink = dl != 'dataLayer' ? `&l=${dl}` : ''; 55 script.src = `https://www.googletagmanager.com/gtm.js?id=${tagId}${gtm_environment}${dLink}`; 56 script.type = 'text/javascript'; 57 appendWhenConsented(script, drupalSettings.svg_theme_components_cp_didomi?.gtm_didomi_vend
57or_id); 58 }); 59})(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.