Verified Commit 2755e85c authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

changes to logic

parent 0e654a5a
......@@ -96,6 +96,7 @@ banner_more_text: >-
cookies_expire: 180 # days
analyticsurl: https://analytics.lcsb.uni.lu/hub/
siteID: 4 # you get this siteID by sending an email to lcsb-r3@uni.lu
cookieName: lap
accept_all_text: >-
Aggregate statistics cookies accepted
only_necessary_text: >-
......
......@@ -26,10 +26,12 @@
settings.siteID = "{{ site.siteID }}";
settings.accept_all_text = "{{ site.accept_all_text }}"
settings.only_necessary_text = "{{ site.only_necessary_text }}"
settings.cookieName = "{{ site.cookieName }}"
settings.bots = /bot|crawler|spider|crawling/i;
</script>
<script src="{{ '/assets/js/jquery.min.js' | relative_url }}"></script>
<script src="{{ '/assets/js/js.cookie.min.js' | relative_url }}"></script>
<script src="{{ '/assets/js/gdpr.js' | relative_url }}"></script>
{%- endif -%}
{%- if jekyll.environment == "review" -%}
......@@ -42,4 +44,4 @@
src='{{site.gitlab_host}}/assets/webpack/visual_review_toolbar.js'></script>
{%- endif -%}
</head>
</head>
\ No newline at end of file
var _paq = window._paq || _paq || [];
// convert days to milliseconds
settings.cookieTimeout = settings.expires * 86400 * 1000;
/* loadMatomo: load the tracking code of the matomo instance */
function loadMatomo() {
if (settings.siteID > 0) {
......@@ -59,7 +62,7 @@ function clearCookies() {
setResultText(false);
}
/* Create/update cookie */
/* setCookie: create/update cookie */
function setCookie(name, value) {
var date = new Date();
date.setTime(date.getTime() + settings.cookieTimeout);
......@@ -67,26 +70,20 @@ function setCookie(name, value) {
document.cookie = name + '=' + value + ';expires=' + date.toGMTString() + ';path=/';
}
/*
* Set consent cookie or localStorage
*/
function setConsent(consent) {
setCookie(settings.cookieName, consent);
setResultText(consent);
function isCookieSetTo(val){
return document.cookie.indexOf(settings.cookieName + '=1' ) > -1;
}
/*
* Check if user gave consent
*/
/* hasConsent: check if user gave consent */
function hasConsent() {
var isCookieSet = document.cookie.indexOf(settings.cookieName + '=1' ) > -1;
if (isCookieSet) {
setResultText(true);
return true;
if (isCookieSetTo(1)) {
setResultText(true);
return true;
} else if (isCookieSetTo(0)) {
setResultText(false);
return false;
} else {
setResultText(false);
return false;
return null
}
}
......@@ -127,7 +124,7 @@ $( document ).ready(function() {
var doNotTrack = false;
// Do nothing if it is a bot
// If DoNotTrack is activated, do nothing too
if (isBot || !isToTrack || hasConsent() === false) {
if (isBot || !isToTrack || !hasConsent()) {
hideCookieBanner();
$('.lap-cookies-refuse').addClass('disabled');
clearCookies();
......@@ -139,7 +136,7 @@ $( document ).ready(function() {
if (hasConsent() === true) {
$('.lap-cookies-accept').addClass('disabled');
loadMatomo();
} else {
} else if (hasConsent() === false) {
// If it's not a bot, no DoNotTrack and not already accept, so show banner
showCookieBanner();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment