1document.addEventListener('DOMContentLoaded', () => { 2 const head = document.querySelector('head'); 3 const body = document.querySelector('body'); 4 5 // HTML ELEMENTS 6 const storeSelectorValue = document.querySelector('.store-selector-value-container'); 7 const storeSelectorCountriesList = document.querySelector('.store-selector-list'); 8 const storeSelectorCountriesListItems = document.querySelectorAll('.store-selector-item'); 9 const storeSelectorSubmitButton = document.querySelector('.store-selector-button'); 10 const storeSelectorChipsList = document.querySelectorAll('.store-selector-chip'); 11 12 const gtmId = 'GTM-MGXF8K'; 13 const countryCodes = Object.keys(countries); 14 const isDetected = countryCodes.includes(countryCode.toUpperCase()); 15 16 const handleGTMScript = () => { 17 const script = document.createElement('script'); 18 19 script.innerHTML = ` 20 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 21 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 22 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
23 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 24 })(window,document,'script','dataLayer','${gtmId}'); 25 ` 26 27 head.appendChild(script); 28 } 29 30 const getCookieBotCookie = () => { 31 const match = document.cookie.match(RegExp('(?:^|;\\s*)CookieConsent=([^;]*)')); 32 return match ? match[1].toString() : ''; 33 } 34 35 const handleGTMIframe = () => { 36 const noscript = document.createElement('noscript'); 37 noscript.innerHTML = `<iframe src="//www.googletagmanager.com/ns.html?id=${gtmId}" height="0" width="0" style="display:none;visibility:hidden"></iframe>` 38 39 body.appendChild(noscript); 40 } 41 42 const handleGTMDataLayer = () => { 43 const script = document.createElement('script'); 44 script.type = 'text/javascript'; 45 script.innerHTML = ` 46 dataLayer.push({"event":"gtmData","pageType":"special_store"}); 47 `; 48 49 body.appendChild(script); 50 } 51 52 const handleStoreSelectorValue = () => { 53 if (storeSelectorCountriesList.classList.value.includes('store-selector-list-open')) { 54 window.dataLayer.push({ 55 'event': 'storeSelectorInteraction', 56 'storeSelectorAction': 'open_selection_list', 57 'storeSelectorPlace': isDetected ? 'autodetected_store' : 'global_store', 58 'storeSelectorLocation': 'special_store' 59 }); 60 } 61 } 62 63 const handleCountryItemClick = (item) => { 64 window.dataLayer.push({ 65 'event': 'storeSelectorInteraction', 66 'storeSelectorAction': 'selected_country', 67 'storeSelectorLabel': item.getAttribute('data-lang'), 68 'storeSelectorPlace': isDetected ? 'autodetected_store' : 'global_store', 69 'storeSelectorLocation': 'special_store' 70 }); 71 } 72 73 const handleCountryChipClick = (chip) => { 74 window.dataLayer.push({ 75 'event': 'storeSelectorInteraction', 76 'storeSelectorAction': 'selected_language', 77 'storeSelectorLabel': chip.getAttribute('data-lang'), 78 'storeSelectorPlace': isDetected ? 'autodetected_store' : 'global_store', 79 'storeSelectorLocation': 'special_store' 80 }); 81 }; 82 83 const handleSelectorSubmitButton = () => { 84 window.dataLayer.push({ 85 'event': 'storeSelectorInteraction', 86 'storeSelectorAction': 'go_to_store', 87 'storeSelectorLabel': storeSelectorSubmitButton.getAttribute('data-lang'), 88 'storeSelectorPlace': isDetected ? 'autodetected_store' : 'global_store', 89 'storeSelectorLocation': 'special_store' 90 }); 91 } 92 93 // EVENTS 94 storeSelectorValue && storeSelectorValue.addEventListener('click', () => handleStoreSelectorValue()); 95 96 storeSelectorCountriesListItems.forEach((item) => { 97 item.addEventListener('click', () => handleCountryItemClick(item)); 98 }); 99 100 storeSelectorChipsList.forEach((chip) => { 101 chip.addEventListener('click', () => handleCountryChipClick(chip)); 102 }); 103 104 storeSelectorSubmitButton.addEventListener('click', () => handleSelectorSubmitButton()); 105 106 if (getCookieBotCookie() && getCookieBotCookie().includes('statistics:true')) { 107 handleGTMScript(); 108 handleGTMIframe(); 109 handleGTMDataLayer(); 110 } else { 111 window.addEventListener('CookiebotOnAccept', () => { 112 if (Cookiebot && Cookiebot.consent.statistics) { 113 handleGTMScript(); 114 handleGTMIframe(); 115 handleGTMDataLayer(); 116 } 117 }); 118 } 119}) 120 121 122 123 124
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.