Hugo theme component to add support for Matomo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
hugo-matomo/static/assets/hugo-matomo.js

45 lines
1.4 KiB

function shouldShowPopup() {
dismissed = localStorage.getItem('popupDismissed');
banner = document.getElementsByClassName("cookie-banner")[0];
if (dismissed == null || dismissed === "no") {
banner.style.display = 'block';
}
}
function dismissPopup() {
localStorage.setItem('popupDismissed', 'yes');
banner = document.getElementsByClassName("cookie-banner")[0];
banner.style.display = 'none';
}
function updateCookieConsent() {
t=Matomo.getTracker(matomoHostURL, matomoSiteId);
when = t.getRememberedCookieConsent();
button = document.getElementById("cookiesaction");
text = button.parentNode.getElementsByTagName('span')[0]
if (when == 0) {
text.innerHTML = "You haven't allowed cookies to be used"
button.innerHTML = "Allow"
button.style.visibility = ""
button.onclick = function() { startCookieConsent(); }
} else {
text.innerHTML = "Using cookies to track your usage of the site"
button.innerHTML = "Stop"
button.style.visibility = ""
button.onclick = function() { stopCookieConsent(); }
}
}
function stopCookieConsent() {
t=Matomo.getTracker(matomoHostURL, matomoSiteId);
t.forgetCookieConsentGiven();
updateCookieConsent();
}
function startCookieConsent() {
t=Matomo.getTracker(matomoHostURL, matomoSiteId);
t.rememberCookieConsentGiven();
updateCookieConsent();
}