var htmlContent = "<div class="alfasoft-cookie-dialog-container"> <div class="dialog" id="cookie-dialog-main"> <div class="dialog-centered"> <div id="cookie-dialog" class="dialog-content"> <div class="dialog-header"> <h2>We Value Your Privacy</h2> </div> <div class="dialog-body"> <div> <div class="content"> <p>We use cookies and similar technologies to improve your experience on our site, personalize content, and analyze website traffic. By clicking "Accept All", you consent to the use of these technologies.</p><p>You can manage your cookie preferences by clicking "Settings". For more information, please review our <a href="/privacy-notice">Privacy Policy</a>.</p> </div> <div class="buttons"> <button id="btn-cookies-settings">Settings</button> <div> <button id="btn-alfasoft-ccm-reject">Reject Non-Essential</button> <button id="btn-alfasoft-ccm-acceptall" class="accept">Accept All</button> </div> </div> </div> </div> </div> </div> </div> <div class="dialog" id="cookie-dialog-settings"> <div class="dialog-centered"> <div id="cookie-dialog" class="dialog-content"> <div class="dialog-header"> <h2>We Value Your Privacy</h2> </div> <div class="dialog-body"> <div class="content"> <h2>Settings Menu</h2> <div class="cookies-list"> <div class="cookie-item"> <p><strong>Necessary Cookies</strong> <span>Required for basic website functionality and cannot be turned off.</span></p> <label class="switch"> <input type="checkbox" checked="checked" id='chk-required-cookies' disabled> <span class="slider round"></span> </label> </div> <div class="cookie-item"> <p><strong>Performance and Analytics</strong> <span>Helps us understand how visitors interact with our website.</span></p> <label class="switch"> <input type="checkbox" id='chk-optional-cookies'> <span class="slider round"></span> </label> </div> <div class="cookie-item"> <p><strong>Save Selection</strong></p> <label class="switch"> <input type="checkbox"> <span class="slider round"></span> </label> </div> </div> </div> <div class="buttons"> <button id="btn-alfasoft-ccm-acceptall-config">Accept All</button> <div> <button class="save" id="btn-alfasoft-save-preferences">Save Selection</button> </div> </div> </div> </div> </div> </div></div>"; var cssContent = ".alfasoft-cookie-dialog-container {\n position: fixed; \/* Stay in place even when scrolling *\/\n top: 0;\n left: 0;\n width: 100vw; \/* Full width of the viewport *\/\n height: 100vh; \/* Full height of the viewport *\/\n background-color: rgba(0, 0, 0, 0.5); \/* Semi-transparent grey background *\/\n z-index: 999999; \/* Ensure it is above all other content *\/\n display: flex; \/* Flexbox to center the content *\/\n justify-content: center; \/* Horizontally center *\/\n align-items: center; \/* Vertically center *\/\n display: none;\n font-family: \"Lato\", sans-serif;\n margin: 0;\n}\n\n\n#cookie-dialog-main,\n#cookie-dialog-settings {\n display: none;\n}\n\n.alfasoft-cookie-dialog-container .dialog {\n width: 100%;\n max-width: 100%;\n padding: 0;\n margin: 0;\n height: 100vh;\n background-color: #00000050;\n}\n\n.alfasoft-cookie-dialog-container .dialog a {\n word-break: normal;\n}\n\n.alfasoft-cookie-dialog-container .dialog-centered {\n display: flex;\n align-items: center;\n height: inherit;\n width: 80vw;\n transform: none;\n margin-right: auto;\n margin-left: auto;\n}\n\n.alfasoft-cookie-dialog-container .dialog-content {\n position: relative;\n display: flex;\n flex-direction: column;\n justify-content: center;\n min-height: 400px;\n max-height: 70%;\n width: 100%;\n}\n\n.alfasoft-cookie-dialog-container .dialog-header,\n.alfasoft-cookie-dialog-container .buttons button {\n padding: 0.75rem 1.5rem;\n}\n\n.alfasoft-cookie-dialog-container .dialog-header,\n.alfasoft-cookie-dialog-container .dialog-header h2,\n.alfasoft-cookie-dialog-container .buttons button.accept,\n.alfasoft-cookie-dialog-container button:not(.accept):hover,\n.alfasoft-cookie-dialog-container .buttons button.save {\n background-color: #2497d0;\n color: #ffffff;\n}\n\n.alfasoft-cookie-dialog-container .dialog-body,\n.alfasoft-cookie-dialog-container .content {\n display: flex;\n flex-direction: column;\n}\n\n.alfasoft-cookie-dialog-container .content a,\n.alfasoft-cookie-dialog-container .buttons button {\n color: #2497d0;\n}\n\n.alfasoft-cookie-dialog-container .buttons,\n.alfasoft-cookie-dialog-container .buttons div {\n gap: 1rem;\n}\n\n.alfasoft-cookie-dialog-container .dialog-header h2 {\n margin: 0;\n font-size: 1.5rem;\n font-weight: 400;\n text-align: left;\n}\n\n.alfasoft-cookie-dialog-container .dialog-body {\n background-color: #ffffff;\n}\n\n.alfasoft-cookie-dialog-container .content {\n padding: 2.25rem 2rem;\n margin-bottom: 2.25rem;\n gap: 1rem;\n}\n\n.alfasoft-cookie-dialog-container .content p {\n margin: 0;\n font-size: 1rem;\n font-weight: 500;\n}\n\n.alfasoft-cookie-dialog-container .buttons {\n padding-left: 2rem;\n padding-right: 2rem;\n padding-top: 0;\n padding-bottom: 1.5rem;\n display: flex;\n justify-content: space-between;\n flex-wrap: wrap-reverse;\n}\n\n.alfasoft-cookie-dialog-container .buttons div {\n display: inherit;\n}\n\n.alfasoft-cookie-dialog-container button {\n font-size: 1.25rem;\n text-wrap: nowrap;\n cursor: pointer;\n -webkit-transition: all 100ms ease-in-out;\n -moz-transition: all 100ms ease-in-out;\n transition: all 100ms ease-in-out;\n}\n\n.alfasoft-cookie-dialog-container .buttons button.accept:hover,\n.alfasoft-cookie-dialog-container .buttons button,\n.alfasoft-cookie-dialog-container .buttons button.save:hover {\n background-color: #ffffff;\n border: 1px solid #2497d0;\n color: #2497d0;\n}\n\n#cookie-dialog-settings .content {\n margin-bottom: 0;\n padding-bottom: 0;\n padding-top: 1.5rem;\n gap: 0.25rem;\n}\n\n.alfasoft-cookie-dialog-container .dialog-body h2 {\n margin: 0;\n font-weight: 800;\n color: #086fa6;\n font-size: 32px;\n}\n\n.alfasoft-cookie-dialog-container .cookies-list {\n margin-left: -2rem;\n margin-right: -2rem;\n margin-bottom: 20px;\n}\n\n.alfasoft-cookie-dialog-container .cookie-item {\n padding: 1.5rem 2rem;\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n border-bottom: 1px solid #2497d0;\n\n}\n\n.alfasoft-cookie-dialog-container .cookie-item p>* {\n font-size: 1.15rem;\n}\n\n.alfasoft-cookie-dialog-container .cookie-item p {\n display: flex;\n flex-direction: column;\n max-width: 75%;\n}\n\n@media only screen and (max-width: 991.99px) {\n .alfasoft-cookie-dialog-container .buttons button {\n font-size: 1rem;\n }\n}\n\n@media only screen and (max-width: 767.99px) {\n\n .alfasoft-cookie-dialog-container .buttons,\n .alfasoft-cookie-dialog-container .buttons div {\n flex-direction: column;\n }\n\n .alfasoft-cookie-dialog-container .content {\n margin-bottom: 0!important;\n }\n\n .alfasoft-cookie-dialog-container .dialog-body {\n overflow-y:scroll\n }\n}\n\n\/** Slider begin **\/\n.alfasoft-cookie-dialog-container .switch {\n position: relative;\n display: inline-block;\n width: 60px;\n height: 34px;\n}\n\n.alfasoft-cookie-dialog-container .switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n.alfasoft-cookie-dialog-container .slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ffffff;\n border: 1px solid #2497d0;\n -webkit-transition: .4s;\n transition: .4s;\n min-width: 60px;\n}\n\n.alfasoft-cookie-dialog-container .slider:before {\n position: absolute;\n content: \"\";\n height: 26px;\n width: 26px;\n left: 4px;\n bottom: 3px;\n background-color: #2497d0;\n -webkit-transition: .4s;\n transition: .4s;\n}\n\n.alfasoft-cookie-dialog-container input:checked+.slider {\n background-color: #2497d0;\n}\n\n.alfasoft-cookie-dialog-container input:focus+.slider {\n box-shadow: 0 0 1px #2497d0;\n}\n\n.alfasoft-cookie-dialog-container input:checked+.slider:before {\n -webkit-transform: translateX(26px);\n -ms-transform: translateX(26px);\n transform: translateX(26px);\n background-color: #ffffff;\n}\n\n\/* Rounded sliders *\/\n.alfasoft-cookie-dialog-container .slider.round {\n border-radius: 34px;\n}\n\n.alfasoft-cookie-dialog-container .slider.round:before {\n border-radius: 50%;\n}\n\n\/** Slider end **\/"; // anything above this will be added from the html file console.log("Starting to process consent mode js"); //var property = "YOUR_GA_MEASUREMENT_ID"; // Replace this with your actual GA Measurement ID var property = "UA-41084727-1"; var cookieName = "alfasoft-cookie-consent"; // Define gtag globally so it can be used anywhere in the script window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } function initializeConsentMode() { console.log("Initializing Consent Mode"); // Check if jQuery is already loaded if (typeof window.jQuery === 'undefined') { console.log("jQuery not found, loading jQuery..."); // Dynamically load jQuery var jqueryScript = document.createElement('script'); jqueryScript.src = "https://code.jquery.com/jquery-1.8.3.min.js"; jqueryScript.async = true; document.head.appendChild(jqueryScript); // Wait for jQuery to load before proceeding jqueryScript.onload = function () { console.log("jQuery loaded!"); proceedAfterjQueryLoaded(); // Proceed only after jQuery is loaded }; } else { console.log("jQuery already loaded"); proceedAfterjQueryLoaded(); } } function proceedAfterjQueryLoaded() { // Initialize Google Analytics script after jQuery is available initializeGoogleAnalytics(); } function initializeGoogleAnalytics() { console.log("initializeGoogleAnalytics start"); // Check if the property ID is defined if (!property) { console.error("Google Analytics property ID is not defined."); return; } // Dynamically inject the Google Tag Manager or Analytics script var script = document.createElement('script'); script.src = "https://www.googletagmanager.com/gtag/js?id=" + property; script.async = true; // Append the script to the head element document.head.appendChild(script); // Add load event listener to confirm loading script.onload = function () { console.log("Google Analytics script successfully loaded!"); // Ensure gtag is defined if (typeof gtag === 'function') { // Initialize Google Consent Mode and set the default consent state gtag('consent', 'default', { 'analytics_storage': 'denied', 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied' }); // Initialize Google Analytics with the property ID gtag('js', new Date()); gtag('config', property); addBannerToBody(); // After everything is loaded, display the consent popup if necessary displayConsentPopup(); } else { console.error("Google Analytics script loaded but gtag is not defined."); } }; // Error handling for script loading script.onerror = function () { console.error("Failed to load Google Analytics script."); }; console.log("initializeGoogleAnalytics finish"); } // Handle cookie consent buttons with jQuery after jQuery is loaded function setUpConsentButtons() { console.log("Settings up button event handlers"); // Handle "Accept All" buttons $('#btn-alfasoft-ccm-acceptall, #btn-alfasoft-ccm-acceptall-config').on('click', function () { acceptClick(); }); $('#btn-alfasoft-ccm-acceptall').on('click', function () { acceptAllCookies(); setCookie(cookieName, 'accepted', 365); // Store consent in a cookie hideBanner(); }); $('#btn-alfasoft-ccm-reject').on('click', function () { acceptRequiredCookies(); setCookie(cookieName, 'rejected', 365); // Store rejection in a cookie hideBanner(); }); $('#btn-alfasoft-save-preferences').on('click', function () { acceptSelectedCookies(); setCookie(cookieName, 'accepted', 365); // Store rejection in a cookie hideBanner(); }); // Show settings on "Settings" button click $('#btn-cookies-settings').on('click', function () { console.log("Clicked settings button"); $('#cookie-dialog-main').hide(); $('#cookie-dialog-settings').show(); }); } function acceptClick() { // ignore the disabled switches as those ones are required let $switches = $('#cookie-dialog-settings input[type="checkbox"]:not(:disabled)'); var allChecked = $switches.first().is(':checked'); $switches.each(function () { $(this).prop('checked', !allChecked); }); } function acceptAllCookies() { console.log("Accepting all cookies"); gtag('consent', 'update', { 'analytics_storage': 'granted', 'ad_storage': 'granted', 'ad_user_data': 'granted', 'ad_personalization': 'granted' }); } function acceptSelectedCookies() { console.log("Accepting selected cookies"); var requiredValue = 'granted'; var optionalValue = $('#chk-required-cookies').is(':checked') ? 'granted' : 'denied'; gtag('consent', 'update', { 'analytics_storage': requiredValue, 'ad_storage': optionalValue, 'ad_user_data': optionalValue, 'ad_personalization': optionalValue }); } // same thing as rejecting non required function acceptRequiredCookies() { console.log("Accepting only required cookies"); gtag('consent', 'update', { 'analytics_storage': 'grant', 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied' }); } function displayConsentPopup() { console.log("displayConsentPopup"); // Check if the user has already given or denied consent if (getCookie(cookieName) === 'accepted') { console.log("accepted"); hideBanner(); //acceptAllCookies(); } else if (getCookie(cookieName) === 'rejected') { console.log("rejected"); acceptRequiredCookies(); //hideBanner(); } else { console.log("Showing banner"); // If consent is not given or rejected, display the consent banner $('.alfasoft-cookie-dialog-container').show(); // Show the consent popup only after everything is loaded $('#cookie-dialog-main').show(); // Show the consent popup only after everything is loaded } } // Function to decode Base64 and convert it back to UTF-8 function decodeBase64ToUtf8(base64String) { // Decode Base64 into a binary string var binaryString = atob(base64String); // Convert binary string to a Uint8Array (for UTF-8 interpretation) var bytes = new Uint8Array(binaryString.length); for (var i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } // Decode the bytes as UTF-8 var decodedString = new TextDecoder('utf-8').decode(bytes); return decodedString; } // Function to inject Base64 encoded CSS into the head function loadBase64CSS(base64CSS) { // Decode the base64 string to plain CSS //var decodedCSS = decodeBase64ToUtf8(base64CSS); var decodedCSS = base64CSS; // Create a style tag var styleTag = document.createElement('style'); // Add the decoded CSS to the style tag if (styleTag.styleSheet) { styleTag.styleSheet.cssText = decodedCSS; // For IE8 and earlier } else { styleTag.appendChild(document.createTextNode(decodedCSS)); // Others } // Append the style tag to the head document.head.appendChild(styleTag); } function decodeHtml(html) { var txt = document.createElement('textarea'); txt.innerHTML = html; return txt.value; } // Function to inject Base64 encoded HTML into the body function loadBase64HTML(base64HTML) { // Decode the base64 string to plain HTML //var decodedHTML = decodeBase64ToUtf8(base64HTML); var decodedHTML = decodeHtml(base64HTML); // Append the decoded HTML directly to the body document.body.insertAdjacentHTML('beforeend', decodedHTML); } function addBannerToBody() { loadBase64CSS(cssContent); loadBase64HTML(htmlContent); setUpConsentButtons(); } function hideBanner() { console.log("Hiding banner"); $('.alfasoft-cookie-dialog-container').hide(); } // Functions to handle cookies function setCookie(name, value, days) { console.log("Setting cookie"); var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); } return null; } // Check if DOM is already loaded, otherwise attach the event listener if (document.readyState === 'complete' || document.readyState === 'interactive') { // DOM is already ready, so initialize immediately initializeConsentMode(); } else { // Attach event listener for when the DOM is ready document.addEventListener('DOMContentLoaded', initializeConsentMode); } console.log("Finished processing consent mode js");