fix matomo

This commit is contained in:
LWinterberg
2023-10-13 10:29:02 +02:00
parent 6979a89c73
commit 298dbbf647
2 changed files with 29 additions and 6 deletions

View File

@@ -22,9 +22,6 @@ const saveAcceptToStorage = () =>
const saveRejectToStorage = () =>
storageType.setItem(consentPropertyName, false);
const applyMatomoTrackingCode = () => {
console.log(
"audacity-consent cookie created, running Matomo tracking code..."
);
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["trackPageView"]);
@@ -42,6 +39,21 @@ const applyMatomoTrackingCode = () => {
})();
};
const applyMatomoTrackingCodeWithoutCookies = () => {
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.audacityteam.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '2']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
};
window.onload = () => {
const consentPopup = document.getElementById("consent-popup");
const acceptBtn = document.getElementById("accept");
@@ -56,6 +68,7 @@ window.onload = () => {
const rejectCookie = (event) => {
saveRejectToStorage(storageType);
consentPopup.classList.add("hide");
applyMatomoTrackingCodeWithoutCookies();
};
acceptBtn.addEventListener("click", acceptCookie);

View File

@@ -5,9 +5,6 @@ const getCookie = (name) => {
}
if (getCookie("audacity_consent") === "true") {
console.log(
"audacity_consent cookie found, loading Matomo tracking code..."
);
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["trackPageView"]);
@@ -23,4 +20,17 @@ const getCookie = (name) => {
g.src = u + "matomo.js";
s.parentNode.insertBefore(g, s);
})();
} else {
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.audacityteam.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '2']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
}