Skip to content

Commit

Permalink
cookie banner added
Browse files Browse the repository at this point in the history
  • Loading branch information
MeikeSteinhilber committed Dec 22, 2023
1 parent 8fee61c commit b09a4cb
Show file tree
Hide file tree
Showing 3 changed files with 468 additions and 75 deletions.
227 changes: 210 additions & 17 deletions inst/tutorials/Grundlagen/Grundlagen.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,216 @@ $(document).ready(function() {

});

var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setRequestMethod", "POST"]);
_paq.push(['enableHeartBeatTimer', 5]);
_paq.push(['disableAlwaysUseSendBeacon']);
_paq.push(["setDoNotTrack", false]);
_paq.push(["setDomains", ["*.otter.uni-frankfurt.de", "*.otter-test.uni-frankfurt.de", "127.0.0.1"]]);
//_paq.push(["setCookieDomain", "*.otter.uni-frankfurt.de"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://otter.uni-frankfurt.de/otterusers/";
_paq.push(['setTrackerUrl', u+'m.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'m.js'; s.parentNode.insertBefore(g,s);
})();

/*! js-cookie v3.0.1 | MIT */
;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, (function () {
var current = global.Cookies;
var exports = global.Cookies = factory();
exports.noConflict = function () { global.Cookies = current; return exports; };
}()));
}(this, (function () { 'use strict';

/* eslint-disable no-var */
function assign (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
}
}
return target
}
/* eslint-enable no-var */

/* eslint-disable no-var */
var defaultConverter = {
read: function (value) {
if (value[0] === '"') {
value = value.slice(1, -1);
}
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
/* eslint-enable no-var */

/* eslint-disable no-var */

function init (converter, defaultAttributes) {
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return
}

attributes = assign({}, defaultAttributes, attributes);

if (typeof attributes.expires === 'number') {
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}
if (attributes.expires) {
attributes.expires = attributes.expires.toUTCString();
}

key = encodeURIComponent(key)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);

var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue
}

stringifiedAttributes += '; ' + attributeName;

if (attributes[attributeName] === true) {
continue
}

// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}

return (document.cookie =
key + '=' + converter.write(value, key) + stringifiedAttributes)
}

function get (key) {
if (typeof document === 'undefined' || (arguments.length && !key)) {
return
}

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var jar = {};
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var value = parts.slice(1).join('=');

try {
var foundKey = decodeURIComponent(parts[0]);
jar[foundKey] = converter.read(value, foundKey);

if (key === foundKey) {
break
}
} catch (e) {}
}

return key ? jar[key] : jar
}

return Object.create(
{
set: set,
get: get,
remove: function (key, attributes) {
set(
key,
'',
assign({}, attributes, {
expires: -1
})
);
},
withAttributes: function (attributes) {
return init(this.converter, assign({}, this.attributes, attributes))
},
withConverter: function (converter) {
return init(assign({}, this.converter, converter), this.attributes)
}
},
{
attributes: { value: Object.freeze(defaultAttributes) },
converter: { value: Object.freeze(converter) }
}
)
}

var api = init(defaultConverter, { path: '/' });
/* eslint-enable no-var */

return api;

})));

var _paq = window._paq = window._paq || [];
jQuery(document).ready(function() {
const cookiebanner = `<div class="modal modal-dialog-scrollable modal-dialog-centered modal-dialog-scrollable fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true" style="justify-content: end; margin: unset !important;">
<div class="modal-dialog" style="display: flex; align-self: end; margin: unset !important;">
<div class="modal-content">
<div class="modal-body">
<p>Wir ben&ouml;tigen Ihre Zustimmung, bevor Sie unsere Website weiter besuchen k&ouml;nnen.</p>
<p>Wir verwenden Cookies und andere Technologien auf unserer Webseite. Einige von ihnen sind essenziell, w&auml;hrend andere uns helfen, diese Webseite und Ihr Benutzungserlebnis zu verbessern. Personenbezogene Daten k&ouml;nnen verarbeitet werden (z.B. IP-Adressen), z.B. Anzeigen- und Inhaltsmessung (Tracking). Weitere Informationen &uuml;ber die Verwendung Ihrer Daten finden Sie in unserer Datenschutzerkl&auml;rung. Sie k&ouml;nnen Ihre Auswahl jederzeit unter Einstellungen widerrufen oder anpassen.</p>
</div>
<div class="modal-footer">
<a type="button" class="btn btn-light" href="https://meikesteinhilber.github.io/otter/">Ich m&ouml;chte Otter nicht nutzen.</a>
<button type="button" class="btn btn-success" id="cookie-okay">Ich bin einverstanden.</button>
</div>
</div>
</div>
</div>`;

const loadScripts = function() {
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setRequestMethod", "POST"]);
_paq.push(['enableHeartBeatTimer', 5]);
_paq.push(['disableAlwaysUseSendBeacon']);
_paq.push(["setDoNotTrack", false]);
_paq.push(["setDomains", ["*.otter.uni-frankfurt.de", "*.otter-test.uni-frankfurt.de", "127.0.0.1"]]);
//_paq.push(["setCookieDomain", "*.otter.uni-frankfurt.de"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://otter.uni-frankfurt.de/otterusers/";
_paq.push(['setTrackerUrl', u+'m.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'m.js'; s.parentNode.insertBefore(g,s);
})();
};

const consent = Cookies.get('cnsnt');
if(consent == undefined || consent == "0") {
jQuery("body").append(jQuery(cookiebanner));
jQuery('#cookie-okay').on("click", function() {
Cookies.set('cnsnt', '1', { expires: 180, sameSite: 'strict' });
loadScripts();

jQuery('#staticBackdrop').modal("hide");
});

jQuery('#cookie-nokay').on("click", function() {
Cookies.set('cnsnt', '0', { expires: 30, sameSite: 'strict' });
});

jQuery('#staticBackdrop').on('hidden.bs.show', function (event) {
jQuery(this).css('display', 'flex');
});

jQuery('#staticBackdrop').modal({backdrop: false, show: true, keyboard: false});
} else if(consent == "1" || consent === 1) {
loadScripts();
}
});



</script>

Expand Down
Loading

0 comments on commit b09a4cb

Please sign in to comment.