1/** 2 * class za delovanje cookies: cookie-consent.ftl 3 */ 4 5let cookieConsentEnabled; 6 7document.addEventListener('DOMContentLoaded', function() { 8 cookieHelpers.initConsentMode(); 9 cookieConsentEnabled = cookieHelpers.cookieGroupsEnabled(); 10 if(cookieConsentEnabled){ 11 cookieHelpers.setGa(); 12 } 13}); 14 15var cookieHelpers = { 16 17 productionMode: true, // false: prikaže console.log outputs 18 19 testScript_Group1: function() { console.log("cookie-helpers.js: cookie group 1 test script activated")}, 20 testScript_Group2: function() { console.log("cookie-helpers.js: cookie group 2 test script activated")}, 21 testScript_Group3: function() { console.log("cookie-helpers.js: cookie group 3 test script activated")}, 22 23 /** 24 * dodajanje GA analitike na stran: SafeMetric 25 */ 26 ccAddAnalytics: function () { 27 if(cookieConsentEnabled){ 28 (function (i, s, o, g, r, a, m) { 29 cookieHelpers.productionMode || console.log('%cccAddAnalytics', 'background: red; color: white'); 30 31 i['GoogleAnalyticsObject'] = r; 32 i[r] = i[r] || function () { 33 (i[r].q = i[r].q || []).push(arguments) 34 }, i[r].l = 1 * new Date(); 35 a = s.createElement(o), 36 m = s.getElementsByTagName(o)[0]; 37 a.async = 1; 38 a.src = g; 39 m.parentNode.insertBefore(a, m) 40 41 // GA profili 42 if(window.gaTrackerBasic != "") { 43 ga('create', { 44 trackingId: window.gaTrackerBasic, // gaTrackerBasic is initialized in cookie-consent.ftl 45 cookieDomain: 'auto' 46 }); 47 ga('set', 'anonymizeIp', true); 48 // PETSI-913: po predlogu Gal KoÄar dodan Å¡e 'page' objekt 49 // https://www.en.advertisercommunity.com/t5/Google-Analytics-Account-Access/Tracking-URLS-with-a-hashtag-fragment/td-p/1734982 50 ga('send', 'pageview', {'page': location.pathname + location.search + location.hash}); 51 } 52 if(window.gaTrackerKrovni != "") { 53 ga('create', { 54 trackingId: window.gaTrackerKrovni, // gaTrackerKrovni is initialized in cookie-consent.ftl 55 cookieDomain: 'auto', 56 name: 'krovniGA' 57 }); 58 ga('krovniGA.set', 'anonymizeIp', true); 59 ga('krovniGA.send', 'pageview', {'page': location.pathname + location.search + location.hash}); 60 } 61 })(window, document, 'script', window.gaUrl, 'ga'); // gaUrl is initialized in cookie-consent.ftl 62 } 63 }, 64 65 ccAddGoogleTagManager: function() { 66 if (window.googleTagMgrId && cookieConsentEnabled) { 67 (function (w, d, s, l, i) { 68 w[l] = w[l] || []; 69 w[l].push({ 70 'gtm.start': 71 new Date().getTime(), event: 'gtm.js' 72 }); 73 var f = d.getElementsByTagName(s)[0], 74 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; 75 j.async = true; 76 j.src = 77 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; 78 f.parentNode.insertBefore(j, f); 79 })(window, document, 'script', 'dataLayer', window.googleTagMgrId); 80 } 81 }, 82 83 initConsentMode: function() { 84 window.dataLayer = window.dataLayer || []; 85 function gtag() { dataLayer.push(arguments); } 86 gtag('consent', 'default', { 87 'ad_user_data': 'denied', 88 'ad_personalization': 'denied', 89 'ad_storage': 'denied', 90 'analytics_storage': 'denied' 91 }); 92 dataLayer.push({'gtm.start': new Date().getTime(), event: 'gtm.js'}); 93 }, 94 95 updateConsentMode: function() { 96 window.dataLayer = window.dataLayer || []; 97 function gtag() { dataLayer.push(arguments); } 98 gtag('consent', 'default', { 99 'ad_user_data': 'granted', 100 'ad_personalization': 'granted', 101 'ad_storage': 'granted',
102 'analytics_storage': 'granted' 103 }); 104 dataLayer.push({'gtm.start': new Date().getTime(), 'event': 'gtm.js'}); 105 }, 106 107 <!-- FUNCTIONS FOR COOKIE SETTINGS PAGE to manage cookie consent dropdowns --> 108 updateCookieSettingsPage: function() { 109 $(function() { 110 if(!$.ctCookieConsent._checkCookieExistance('__cookie_optout')){ 111 $.ctCookieConsent.setInitCookie(); 112 } 113 114 if ($("#group-2").length) { <!-- If toggle switch for cookie settings exist manage the settings --> 115 var toggleCookieConsent_Groups = [$('#group-2'), $('#group-3')]; 116 refreshCookieSettings(); 117 118 <!-- Add events to set cookie consent settings on toggle change --> 119 for (let i = 0; i < toggleCookieConsent_Groups.length; i++) { 120 toggleCookieConsent_Groups[i].on('change', function() { 121 let isChecked = toggleCookieConsent_Groups[i].prop('checked'); 122 $.ctCookieConsent.setCookieForGroup(i + 2, isChecked); 123 if (isChecked) { 124 $.ctCookieConsent.executeCookieScriptsForGroup(i + 2); 125 } 126 cookieHelpers.updateGa(isChecked); 127 }); 128 } 129 130 <!-- Dynamically change toggle values if cookies get accepted in the cookie consent panel --> 131 $($.ctCookieConsent).on("cookieConsentChange", function (event) { 132 refreshCookieSettings(); 133 }); 134 }; 135 136 function refreshCookieSettings() { 137 // Set the initial state of the toggle switch based on the cookie settings 138 for (let i = 0; i < toggleCookieConsent_Groups.length; i++) { 139 let cookieName = (i === 0) ? '__cookie_optout' : '__cookie' + (i + 2) + '_optout'; 140 let isChecked = cookieHelpers.getCookie(cookieName) === "false"; 141 toggleCookieConsent_Groups[i].prop('checked', isChecked); 142 } 143 } 144 }); 145 146 }, 147 148 updateGa: function(isChecked){ 149 if (!isChecked && !cookieHelpers.cookieGroupsEnabled()){ 150 cookieHelpers.deleteGa(); 151 } else if (isChecked && !cookieConsentEnabled){ 152 cookieHelpers.setGa(); 153 } 154 }, 155 156 cookieGroupsEnabled: function() { 157 let count = 0; 158 if (cookieHelpers.getCookie('__cookie_optout') === "false") count++; 159 if (cookieHelpers.getCookie('__cookie3_optout') === "false") count++; 160 161 return count > 0 ? true : false; 162 }, 163 164 setGa: function (){ 165 cookieConsentEnabled = true; 166 cookieHelpers.updateConsentMode(); 167 cookieHelpers.ccAddAnalytics(); 168 cookieHelpers.ccAddGoogleTagManager(); 169 }, 170 171 deleteGa: function() { 172 const googleCookies = cookieHelpers.getGoogleCookies(); 173 const domain = window.location.hostname.replace('www', ''); 174 175 for (let i=0; i<googleCookies.length; i++){ 176 if (this.getCookie(googleCookies[i])) { 177 document.cookie = `${googleCookies[i]}=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=${domain}; path=/;`; 178 } 179 } 180 181 ga('remove'); 182 cookieConsentEnabled = false; 183 }, 184 185 getGoogleCookies: function() { 186 const cookieArray = document.cookie.split(";"); 187 const googleCookies = []; 188 for (let i = 0; i < cookieArray.length; i++) { 189 const cookie = cookieArray[i].trim(); 190 if (cookie.startsWith("_ga") || cookie.startsWith("_gid")) { 191 googleCookies.push(cookie.split("=")[0]); 192 } 193 } 194 return googleCookies; 195 }, 196 197 /** 198 * doda class na html element 199 * @deprecated z novim dizajnom se ne rabi veÄ oz. se tepe z .cookies classo v style.css 200 */ 201 ccAddHtmlClass: function () { 202 cookieHelpers.productionMode || console.log('%cccAddHtmlClass', 'background: green; color: white'); 203 document.querySelector('html').classList.add('petrol-cookie
203s'); 204 }, 205 206 getCookie: function(cookieName) { 207 var value = "; " + document.cookie; 208 var parts = value.split("; " + cookieName + "="); 209 if (parts.length == 2) return parts.pop().split(";").shift(); 210 return ""; 211 }, 212 213 /** 214 * helper f. za setat cookie 215 */ 216 setCookie: function (c_name, value, exdays) { 217 if (exdays) { 218 var exdate = new Date(); 219 exdate.setDate(exdate.getDate() + exdays).toUTCString(); 220 } else { 221 var g = new Date(); 222 var d = 1000 * 60 * 60 * 24 * 90; 223 var c = new Date(g.getTime() + d); 224 var exdate = c.toGMTString(); 225 } 226 227 // za testiranje v lokalnem okolju je potrebno odstraniti: + "; secure" 228 var c_value = encodeURI(value) + ((exdate == null) ? "" : "; expires=" + exdate + "; path=/" + "; secure"); 229 document.cookie = c_name + "=" + c_value; 230 cookieHelpers.productionMode || console.log('%ccookieHelpers.setCookie: ' + document.cookie, 'background: red; color: white'); 231 }, 232 233 /** 234 * preveri Äe je {cookieName} setan z {cookieValue} 235 */ 236 checkCookie: function (cookieName, cookieValue) { 237 return this.getCookie(cookieName) == cookieValue; 238 } 239};
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.