MediaWiki:Common.js: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
(Use shared analytics consent banner and conditional GA4 load) |
(Add Privacy / Cookie link to consent banner) |
||
| Riga 43: | Riga 43: | ||
var style = document.createElement('style'); | var style = document.createElement('style'); | ||
style.id = 'gazzinet-consent-style'; | style.id = 'gazzinet-consent-style'; | ||
style.textContent = '#gazzinet-consent-banner{position:fixed;right:18px;bottom:18px;z-index:99999;max-width:360px;background:#f6f6f3;color:#1e3f16;border:1px solid #b7c4b0;border-radius:14px;box-shadow:0 14px 40px rgba(0,0,0,.14);padding:16px 16px 14px;font:400 .92rem/1.4 "Trebuchet MS","Segoe UI",Arial,sans-serif}#gazzinet-consent-banner[hidden]{display:none!important}#gazzinet-consent-banner strong{display:block;margin:0 0 6px;color:#1f4818;font-size:.96rem}#gazzinet-consent-banner p{margin:0 0 12px;color:#2f5d26}#gazzinet-consent-actions{display:flex;gap:10px;flex-wrap:wrap}#gazzinet-consent-actions button{appearance:none;border-radius:999px;padding:8px 14px;font:700 .84rem/1 "Trebuchet MS","Segoe UI",Arial,sans-serif;cursor:pointer}#gazzinet-consent-accept{background:#2f6f24;color:#fff;border:1px solid #2f6f24}#gazzinet-consent-deny{background:transparent;color:#2f6f24;border:1px solid #7c9774}@media (max-width:680px){#gazzinet-consent-banner{left:12px;right:12px;bottom:12px;max-width:none}}'; | style.textContent = '#gazzinet-consent-banner{position:fixed;right:18px;bottom:18px;z-index:99999;max-width:360px;background:#f6f6f3;color:#1e3f16;border:1px solid #b7c4b0;border-radius:14px;box-shadow:0 14px 40px rgba(0,0,0,.14);padding:16px 16px 14px;font:400 .92rem/1.4 "Trebuchet MS","Segoe UI",Arial,sans-serif}#gazzinet-consent-banner[hidden]{display:none!important}#gazzinet-consent-banner strong{display:block;margin:0 0 6px;color:#1f4818;font-size:.96rem}#gazzinet-consent-banner p{margin:0 0 12px;color:#2f5d26}#gazzinet-consent-banner a{color:#1f4818;text-decoration:underline;text-underline-offset:2px}#gazzinet-consent-banner a:hover{color:#2f6f24}#gazzinet-consent-actions{display:flex;gap:10px;flex-wrap:wrap}#gazzinet-consent-actions button{appearance:none;border-radius:999px;padding:8px 14px;font:700 .84rem/1 "Trebuchet MS","Segoe UI",Arial,sans-serif;cursor:pointer}#gazzinet-consent-accept{background:#2f6f24;color:#fff;border:1px solid #2f6f24}#gazzinet-consent-deny{background:transparent;color:#2f6f24;border:1px solid #7c9774}@media (max-width:680px){#gazzinet-consent-banner{left:12px;right:12px;bottom:12px;max-width:none}}'; | ||
document.head.appendChild(style); | document.head.appendChild(style); | ||
} | } | ||
| Riga 54: | Riga 54: | ||
var banner = document.createElement('div'); | var banner = document.createElement('div'); | ||
banner.id = 'gazzinet-consent-banner'; | banner.id = 'gazzinet-consent-banner'; | ||
banner.innerHTML = '<strong>Analytics</strong><p>Usiamo Google Analytics per misurare l\'uso del sito.</p><div id="gazzinet-consent-actions"><button id="gazzinet-consent-accept" type="button">Accetta</button><button id="gazzinet-consent-deny" type="button">Rifiuta</button></div>'; | banner.innerHTML = '<strong>Analytics</strong><p>Usiamo Google Analytics per misurare l\'uso del sito. <a href="https://www.gazzi.net/privacy-cookie/">Privacy / Cookie</a></p><div id="gazzinet-consent-actions"><button id="gazzinet-consent-accept" type="button">Accetta</button><button id="gazzinet-consent-deny" type="button">Rifiuta</button></div>'; | ||
document.body.appendChild(banner); | document.body.appendChild(banner); | ||
document.getElementById('gazzinet-consent-accept').addEventListener('click', function () { | document.getElementById('gazzinet-consent-accept').addEventListener('click', function () { | ||
Versione attuale delle 01:13, 13 mar 2026
(function () {
var measurementId = 'G-DFC284KHY7';
var consentKey = 'gazzi_consent_analytics';
function getCookie(name) {
var match = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/[.$?*|{}()\[\]\\/+^]/g, '\\$&') + '=([^;]*)'));
return match ? decodeURIComponent(match[1]) : '';
}
function setCookie(value) {
var secure = location.protocol === 'https:' ? '; Secure' : '';
document.cookie = consentKey + '=' + value + '; path=/; domain=.gazzi.net; max-age=' + (60 * 60 * 24 * 365) + '; SameSite=Lax' + secure;
}
function loadGa() {
if (window.gazzinetGa4Loaded) {
return;
}
window.gazzinetGa4Loaded = true;
window.dataLayer = window.dataLayer || [];
window.gtag = window.gtag || function () {
dataLayer.push(arguments);
};
var script = document.createElement('script');
script.async = true;
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + measurementId;
document.head.appendChild(script);
window.gtag('js', new Date());
window.gtag('config', measurementId);
}
function closeBanner() {
var banner = document.getElementById('gazzinet-consent-banner');
if (banner) {
banner.hidden = true;
}
}
function ensureStyle() {
if (document.getElementById('gazzinet-consent-style')) {
return;
}
var style = document.createElement('style');
style.id = 'gazzinet-consent-style';
style.textContent = '#gazzinet-consent-banner{position:fixed;right:18px;bottom:18px;z-index:99999;max-width:360px;background:#f6f6f3;color:#1e3f16;border:1px solid #b7c4b0;border-radius:14px;box-shadow:0 14px 40px rgba(0,0,0,.14);padding:16px 16px 14px;font:400 .92rem/1.4 "Trebuchet MS","Segoe UI",Arial,sans-serif}#gazzinet-consent-banner[hidden]{display:none!important}#gazzinet-consent-banner strong{display:block;margin:0 0 6px;color:#1f4818;font-size:.96rem}#gazzinet-consent-banner p{margin:0 0 12px;color:#2f5d26}#gazzinet-consent-banner a{color:#1f4818;text-decoration:underline;text-underline-offset:2px}#gazzinet-consent-banner a:hover{color:#2f6f24}#gazzinet-consent-actions{display:flex;gap:10px;flex-wrap:wrap}#gazzinet-consent-actions button{appearance:none;border-radius:999px;padding:8px 14px;font:700 .84rem/1 "Trebuchet MS","Segoe UI",Arial,sans-serif;cursor:pointer}#gazzinet-consent-accept{background:#2f6f24;color:#fff;border:1px solid #2f6f24}#gazzinet-consent-deny{background:transparent;color:#2f6f24;border:1px solid #7c9774}@media (max-width:680px){#gazzinet-consent-banner{left:12px;right:12px;bottom:12px;max-width:none}}';
document.head.appendChild(style);
}
function openBanner() {
if (document.getElementById('gazzinet-consent-banner')) {
return;
}
ensureStyle();
var banner = document.createElement('div');
banner.id = 'gazzinet-consent-banner';
banner.innerHTML = '<strong>Analytics</strong><p>Usiamo Google Analytics per misurare l\'uso del sito. <a href="https://www.gazzi.net/privacy-cookie/">Privacy / Cookie</a></p><div id="gazzinet-consent-actions"><button id="gazzinet-consent-accept" type="button">Accetta</button><button id="gazzinet-consent-deny" type="button">Rifiuta</button></div>';
document.body.appendChild(banner);
document.getElementById('gazzinet-consent-accept').addEventListener('click', function () {
setCookie('granted');
loadGa();
closeBanner();
});
document.getElementById('gazzinet-consent-deny').addEventListener('click', function () {
setCookie('denied');
closeBanner();
});
}
var consent = getCookie(consentKey);
if (consent === 'granted') {
loadGa();
return;
}
if (consent === 'denied') {
return;
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', openBanner);
} else {
openBanner();
}
}());