MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
(function () { | (function () { | ||
const KEY = " | const KEY = "alphax_entry_consent"; | ||
const ANALYTICS_KEY = "alphax_analytics_consent"; | |||
const MAX_AGE = 30 * 24 * 60 * 60 * 1000; | const MAX_AGE = 30 * 24 * 60 * 60 * 1000; | ||
const GA_ID = "G-XXXXXXXXXX"; | |||
const saved = localStorage.getItem(KEY); | const saved = localStorage.getItem(KEY); | ||
if (saved && (Date.now() - saved < MAX_AGE)) { | if (saved && (Date.now() - Number(saved) < MAX_AGE)) { | ||
const analyticsConsent = localStorage.getItem(ANALYTICS_KEY); | |||
if (analyticsConsent === "granted") { | |||
loadGoogleAnalytics(); | |||
} | |||
return; | return; | ||
} | } | ||
| Line 60: | Line 66: | ||
color:#e4e4ea; | color:#e4e4ea; | ||
cursor:pointer; | cursor:pointer; | ||
line-height:1.5; | |||
} | } | ||
#checks input{ | #checks input{ | ||
margin-right:10px; | margin-right:10px; | ||
} | |||
#optional-title{ | |||
margin-top:22px; | |||
margin-bottom:8px; | |||
font-size:13px; | |||
font-weight:700; | |||
letter-spacing:0.04em; | |||
text-transform:uppercase; | |||
color:#9ca3af; | |||
} | } | ||
| Line 146: | Line 163: | ||
<input type="checkbox" id="c3"> | <input type="checkbox" id="c3"> | ||
I agree to the Privacy Policy | I agree to the Privacy Policy | ||
</label> | |||
<div id="optional-title">Optional</div> | |||
<label> | |||
<input type="checkbox" id="c4"> | |||
Allow anonymous analytics to help improve the website | |||
</label> | </label> | ||
| Line 151: | Line 175: | ||
<div id="buttons"> | <div id="buttons"> | ||
<button id="enter">Enter</button> | <button id="enter">Enter</button> | ||
<button id="exit">Exit</button> | <button id="exit">Exit</button> | ||
</div> | </div> | ||
<div id="links"> | <div id="links"> | ||
<a href="/index.php?title=Terms_and_Conditions">T&C</a> | <a href="/index.php?title=Terms_and_Conditions">T&C</a> | ||
<a href="/index.php?title=Datenschutz">Privacy Policy</a> | <a href="/index.php?title=Datenschutz">Privacy Policy</a> | ||
</div> | </div> | ||
| Line 170: | Line 192: | ||
const c2 = document.getElementById("c2"); | const c2 = document.getElementById("c2"); | ||
const c3 = document.getElementById("c3"); | const c3 = document.getElementById("c3"); | ||
const c4 = document.getElementById("c4"); | |||
const enter = document.getElementById("enter"); | const enter = document.getElementById("enter"); | ||
function checkAll(){ | function checkAll(){ | ||
if(c1.checked && c2.checked && c3.checked){ | if (c1.checked && c2.checked && c3.checked) { | ||
enter.classList.add("active"); | enter.classList.add("active"); | ||
enter.disabled=false; | enter.disabled = false; | ||
}else{ | } else { | ||
enter.classList.remove("active"); | enter.classList.remove("active"); | ||
enter.disabled=true; | enter.disabled = true; | ||
} | |||
} | } | ||
c1.onchange = checkAll; | |||
c2.onchange = checkAll; | |||
c3.onchange = checkAll; | |||
enter.disabled = true; | |||
function loadGoogleAnalytics() { | |||
if (window.__gaLoaded) return; | |||
window.__gaLoaded = true; | |||
window.dataLayer = window.dataLayer || []; | |||
function gtag() { | |||
dataLayer.push(arguments); | |||
} | |||
window.gtag = gtag; | |||
gtag("consent", "default", { | |||
analytics_storage: "granted" | |||
}); | |||
const script = document.createElement("script"); | |||
script.async = true; | |||
script.src = "https://www.googletagmanager.com/gtag/js?id=" + encodeURIComponent(GA_ID); | |||
document.head.appendChild(script); | |||
gtag("js", new Date()); | |||
gtag("config", GA_ID, { | |||
anonymize_ip: true | |||
}); | |||
} | } | ||
enter.onclick = function(){ | |||
localStorage.setItem(KEY, String(Date.now())); | |||
if (c4.checked) { | |||
localStorage.setItem(ANALYTICS_KEY, "granted"); | |||
loadGoogleAnalytics(); | |||
} else { | |||
localStorage.setItem(ANALYTICS_KEY, "denied"); | |||
} | |||
overlay.remove(); | |||
overlay.remove(); | |||
}; | }; | ||
document.getElementById("exit").onclick=function(){ | document.getElementById("exit").onclick = function(){ | ||
window.location.href="https://google.com"; | window.location.href = "https://google.com"; | ||
}; | }; | ||
})(); | })(); | ||