document.addEventListener("DOMContentLoaded", function (){
const consent=Cookies.get("gdpr-consent");
if(!consent){
displayCookieBanner();
}else{
updateGoogleConsent(consent);
}});
function displayCookieBanner(){
const banner=document.createElement("div");
banner.id="gdpr-cookie-banner";
banner.innerHTML=`
<div>
${gdprData.textGdpr}
<button id="accept-necessary">Sprejmi samo nujne</button>
<button id="accept-all">Sprejmi vse</button>
</div>
`;
document.body.appendChild(banner);
document.getElementById("accept-necessary").addEventListener("click", ()=> {
setConsent("necessary");
});
document.getElementById("accept-all").addEventListener("click", ()=> {
setConsent("all");
});
}
function setConsent(consentType){
Cookies.set("gdpr-consent", consentType, { expires: 365 });
updateGoogleConsent(consentType);
const banner=document.getElementById("gdpr-cookie-banner");
if(banner){
banner.remove();
}}
function updateGoogleConsent(consentType){
if(typeof gtag!=="function"){
console.warn("gtag function not found. Google Site Kit may not be active or loaded yet.");
return;
}
const consentSettings={
'analytics_storage': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied'
};
if(consentType==="all"){
consentSettings.analytics_storage='granted';
consentSettings.ad_storage='granted';
consentSettings.ad_user_data='granted';
consentSettings.ad_personalization='granted';
}
gtag('consent', 'update', consentSettings);
};