Gitlab is now using https://gitlab.lcsb.uni.lu as it's primary address. Please update your bookmarks. FAQ.

Commit 27ed6dfe authored by Jacek Lebioda's avatar Jacek Lebioda
Browse files

Merge branch 'update-banner' into 'latest'

Change links / centralize lap

See merge request core-services/jekyll-theme-lcsb-default!49
parents 5cd50800 b734f533
...@@ -96,13 +96,14 @@ banner_more_text: >- ...@@ -96,13 +96,14 @@ banner_more_text: >-
More information More information
cookies_expire: 180 # days cookies_expire: 180 # days
analyticsurl: https://analytics.lcsb.uni.lu/hub/ analyticsurl: https://analytics.lcsb.uni.lu/hub/
siteID: -1 # you get this siteID by sending an email to lcsb-r3@uni.lu lapurl: https://analytics.lcsb.uni.lu/lap/
siteID: 4 # you get this siteID by sending an email to lcsb-r3@uni.lu
cookieName: lap cookieName: lap
accept_all_text: >- accept_all_text: >-
Aggregate statistics cookies accepted Aggregate statistics cookies accepted
only_necessary_text: >- only_necessary_text: >-
Only necessary cookies accepted Only necessary cookies accepted
path_policy: privacy-policy path_policy: privacy-policy
logo_policy: /assets/banners/r3-logo.svg logo_policy: https://analytics.lcsb.uni.lu/lap/static/logos/r3-logo.svg
timeout_hidebanner: 500 # milliseconds timeout_hidebanner: 500 # milliseconds
cookieDomain: '*' # track visitors across all subdomains of a given domain; set to * to ignore cookieDomain: '*' # track visitors across all subdomains of a given domain; set to * to ignore
...@@ -13,23 +13,26 @@ ...@@ -13,23 +13,26 @@
<link rel="shortcut icon" href="{{ '/assets/favicon/favicon.ico' | relative_url }}"> <link rel="shortcut icon" href="{{ '/assets/favicon/favicon.ico' | relative_url }}">
<meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="{{ '/assets/favicon/browserconfig.xml' | relative_url }}"> <meta name="msapplication-config" content="{{ '/assets/favicon/browserconfig.xml' | relative_url }}">
<meta name="theme-color" content="#ffffff"> {%- include css-imports.html -%} {% if site.siteID > 0 %} <meta name="theme-color" content="#ffffff"> {%- include css-imports.html -%}
{% if site.siteID > 0 %}
<script> <script>
var settings = []; const settings = {
settings.expires = "{{ site.cookies_expire }}"; expires: "{{ site.cookies_expire }}",
settings.matomoURL = "{{ site.analyticsurl }}"; matomoURL: "{{ site.analyticsurl }}",
settings.siteID = "{{ site.siteID }}"; siteID: "{{ site.siteID }}",
settings.accept_all_text = "{{ site.accept_all_text }}"; accept_all_text: "{{ site.accept_all_text }}",
settings.only_necessary_text = "{{ site.only_necessary_text }}"; only_necessary_text: "{{ site.only_necessary_text }}",
settings.cookieName = "{{ site.cookieName }}"; cookieName: "{{ site.cookieName }}",
settings.bots = /bot|crawler|spider|crawling/i; bots: /bot|crawler|spider|crawling/i,
settings.timeout_hidebanner = "{{ site.timeout_hidebanner }}"; timeout_hidebanner: "{{ site.timeout_hidebanner }}",
settings.cookieDomain = "{{ site.cookieDomain }}"; cookieDomain: "{{ site.cookieDomain }}",
}
</script> </script>
<script src="{{ '/assets/js/jquery.min.js' | relative_url }}"></script> <script src="https://analytics.lcsb.uni.lu/lap/static/js/jquery.min.js"></script>
<script src="{{ '/assets/js/gdpr.js' | relative_url }}"></script> <script src="https://analytics.lcsb.uni.lu/lap/static/js/lap.js"></script>
{%- endif -%}
{%- endif -%} {%- if jekyll.environment == "review" -%} {%- if jekyll.environment == "review" -%}
<script defer data-project-id='{{site.project_id}}' data-project-path='{{site.project_namespace}}' data-merge-request-id='{{site.mr_id}}' data-mr-url='{{site.gitlab_host}}' id='review-app-toolbar-script' src='{{site.gitlab_host}}/assets/webpack/visual_review_toolbar.js'></script> <script defer data-project-id='{{site.project_id}}' data-project-path='{{site.project_namespace}}' data-merge-request-id='{{site.mr_id}}' data-mr-url='{{site.gitlab_host}}' id='review-app-toolbar-script' src='{{site.gitlab_host}}/assets/webpack/visual_review_toolbar.js'></script>
{%- endif -%} {%- endif -%}
......
var _paq = window._paq || _paq || [];
// convert days to milliseconds
settings.cookieTimeout = settings.expires * 86400 * 1000;
/*
* loadMatomo: load the tracking code of the analytics instance
*/
function loadMatomo() {
if (settings.siteID > 0) {
var u = settings.matomoURL;
_paq.push(['setSiteId', settings.siteID]);
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setDoNotTrack', 1]);
_paq.push(['trackPageView']);
_paq.push(['setIgnoreClasses', ['no-tracking', 'colorbox']]);
_paq.push(['enableLinkTracking']);
// set the cookie domain an
if(!(settings.cookieDomain == "*")) {
_paq.push(["setCookieDomain", settings.cookieDomain]);
}
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.defer = true;
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
setResultText(true);
}
}
/*
* setResultText: change the text in the footer
*/
function setResultText(acceptCookies) {
if (acceptCookies === true) {
$('#gdpr-result-text').html(settings.accept_all_text);
} else {
$('#gdpr-result-text').html(settings.only_necessary_text);
}
}
/*
* showBanner: show the banner
*/
function showBanner() {
var popup = $('#lap-cookies-banner');
popup.hide();
popup.slideDown('slow');
}
/*
* hideBanner: show the banner
*/
function hideBanner() {
var popup = $('#lap-cookies-banner');
setTimeout(() => { popup.slideUp('slow'); }, settings.timeout_hidebanner);
}
/*
* clearCookies: clear all cookies
*/
function clearCookies() {
var originOfTime = new Date(0);
var hostname = document.location.hostname.replace(/^www\./, ''),
commonSuffix = '; expires= ' + originOfTime + '; path=/';
// remove the analytics cookies
var cookies = document.cookie.split('; ');
for (var i in cookies) {
var name = cookies[i].split('=')[0];
if (name.startsWith('_pk_') || name.startsWith('MATOMO_SESSID')) {
document.cookie = name + '=; ' + commonSuffix;
}
}
setResultText(false);
}
/*
* setCookie: create/update cookie
*/
function setCookie(name, value) {
var date = new Date();
date.setTime(date.getTime() + settings.cookieTimeout);
document.cookie = name + '=' + value + ';expires=' + date.toGMTString() + ';path=/';
}
function isCookieSetTo(val) {
return document.cookie.indexOf(settings.cookieName + '=' + val) > -1;
}
/*
* hasConsent: check if user gave consent
*/
function hasConsent() {
if (isCookieSetTo(1)) {
setResultText(true);
return true;
} else if (isCookieSetTo(0)) {
setResultText(false);
return false;
}
return null;
}
/*
* accept: accept the cookies
*/
function accept() {
// action
loadMatomo();
// cookie management
setCookie(settings.cookieName, 1);
// feedback
setResultText(true);
// style
$('.lap-accept').addClass('selected');
$('.lap-refuse').removeClass('selected');
// hide banner
hideBanner();
}
/*
* accept: refuse the cookies
*/
function refuse(doNotTrack) {
// action
clearCookies();
// cookie management
// only set the refusal cookie if actually allowed (i.e. doNotTrack = false)
if (doNotTrack === false) {
setCookie(settings.cookieName, 0);
}
// feedback
setResultText(false);
// style
$('.lap-refuse').addClass('selected');
$('.lap-accept').removeClass('selected');
// hide banner
hideBanner();
}
/*
* main function
*/
$(document).ready(function() {
// accept
$('.lap-accept').click(function(e) {
e.preventDefault(true);
accept();
});
// refuse
$('.lap-refuse').click(function(e) {
e.preventDefault(true);
refuse(false);
});
// detect if the visitor is a bot or not
// prevent search engine t otake the cookie alert message as main content
var isBot = settings.bots.test(navigator.userAgent);
// check if DoNotTrack is active
var dnt = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack;
var isToTrack = (dnt !== null && dnt !== undefined) ? (dnt && dnt !== 'yes' && dnt !== 1 && dnt !== '1') : true;
var doNotTrack = false;
// do nothing if it is a bot or if DoNotTrack is active
if (isBot || !isToTrack || hasConsent() === false) {
doNotTrack = true;
refuse(doNotTrack);
}
if (doNotTrack === false) {
if (hasConsent() === true) {
// user has already given consent to use cookies to tracking
accept();
} else if (hasConsent() === false || hasConsent() === null) {
// all other cases considered, show banner
showBanner();
}
}
});
\ No newline at end of file
This diff is collapsed.
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