Skip to content

Commit

Permalink
Merge pull request #315 from City-of-Helsinki/HEL-346-fix-cookieless-…
Browse files Browse the repository at this point in the history
…tracking

fix: matomo cookieless tracking
  • Loading branch information
jannetalvio authored Dec 20, 2023
2 parents eb73e77 + 10bba60 commit ce2b443
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
23 changes: 5 additions & 18 deletions hkm/static/hkm/js/cookie-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@
$rejectBtn = $("#consent_reject"),
$consentLink = $("#cookie-consent-link");

// always require on load
_paq.push(["requireCookieConsent"]);
_paq.push(["requireConsent"]);

// if rejected
if (cookie && cookie === "0") {
_paq.push(["forgetCookieConsentGiven"]);
_paq.push(["forgetConsentGiven"]);
}

// if accepted
if (cookie && cookie === "1") {
_paq.push(["rememberConsentGiven"]);
_paq.push(["rememberCookieConsentGiven"]);
_paq.push(['setCookieConsentGiven']);
}

if (!cookie) {
Expand All @@ -43,18 +32,16 @@

$acceptBtn.on("click", function (e) {
if (_paq) {
_paq.push(["rememberConsentGiven"]);
_paq.push(["rememberCookieConsentGiven"]);
$.cookie(cookieName, "1", { expires: 393 });
_paq.push(['setCookieConsentGiven']);
$.cookie(cookieName, "1", { expires: 393, path: '/' });
$cookieConsentContainer.fadeOut();
}
});

$rejectBtn.on("click", function (e) {
if (_paq) {
_paq.push(["forgetConsentGiven"]);
_paq.push(["forgetCookieConsentGiven"]);
$.cookie(cookieName, "0", { expires: 393 });
_paq.push(['forgetCookieConsentGiven']);
$.cookie(cookieName, "0", { expires: 393, path: '/' });
$cookieConsentContainer.fadeOut();
}
});
Expand Down
3 changes: 3 additions & 0 deletions hkm/templates/hkm/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ <h1 class="login-modal__body_title">{% trans 'Sign up' %}</h1>
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(["requireCookieConsent"]);

(function() {
var u="//webanalytics.digiaiiris.com/js/";
_paq.push(['setTrackerUrl', u+'tracker.php']);
_paq.push(['setSiteId', '1040']);

var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'piwik.min.js'; s.parentNode.insertBefore(g,s);
})();
Expand Down

0 comments on commit ce2b443

Please sign in to comment.