Skip to content

Commit

Permalink
Esy 5740 clarity cookie consent (#813)
Browse files Browse the repository at this point in the history
* Create cookie-consent.js

* Update default.html

* Update cookie-consent.js

Codacy comments

* Update cookie-consent.js

Codacy comments
  • Loading branch information
m-lilja authored Jan 4, 2024
1 parent 7da6899 commit 8266c31
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<script src="{{ "/assets/tipuesearch/tipuesearch_set.js" | relative_url }}"></script>
<script src="{{ "/assets/tipuesearch/tipuesearch.min.js" | relative_url }}"></script>
{%- endif %}
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8" data-domain-script="77c777e5-115a-4e3d-81ec-cc857a4ac846"></script>
</head>

<body>
Expand Down Expand Up @@ -111,6 +112,7 @@
</div>
<script src="{{ design_guide_url }}/scripts/dg.js" global="true" autoload="true"></script>
<script src="{{ '/assets/js/swedbank-pay-design-guide-theme.js' | relative_url }}"></script>
<script src="{{ '/assets/js/cookie-consent.js' | relative_url }}"></script>
{%- if site.google_analytics.tracking_id %}
{% include google_analytics.html %}
{%- endif %}
Expand Down
40 changes: 40 additions & 0 deletions assets/js/cookie-consent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function OptanonWrapper() { }

function activateClarity() {
// Clarity script - do not change
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "jd3awxna38");
// End of Clarity script
}

function getCookie(name) {
if (document.cookie.split(";").some((c) => c.trim().startsWith(name + "="))) {
return document.cookie.split(";").find((c) => c.trim().startsWith(name + "="));
}
else {
return false;
}
}

function deleteCookie(name) {
if (getCookie(name)) {
document.cookie = name + "=;domain=.swedbankpay.com;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT";
}
}

function inactivateClarityCookies() {
deleteCookie("_clck");
deleteCookie("_clsk");
}

window.addEventListener("OneTrustGroupsUpdated", (event) => {
if (event.detail.indexOf("C0002") !== -1) {
activateClarity();
}
else {
inactivateClarityCookies();
}
});

0 comments on commit 8266c31

Please sign in to comment.