Skip to content

Commit

Permalink
Update _includes\cookie-consent.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Stamm committed Jul 14, 2023
1 parent 8c3900e commit e5c7451
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions _includes\cookie-consent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

<!-- Only add all this in production, why would I analyse myself when writing the post anyway. -->
{% if jekyll.environment == 'production' %}

<!-- Add cookie consent css & js -->
<link rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js"
data-cfasync="false"></script>

<!-- Add google analytics -->
<!--
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
-->

<script>
// Reads the value of a cookie by name or returns empty string
function getCookie(name) {
var b = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
}

// Actually starting analytics up
function addAnalytics() {
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}

gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
}

// Waiting for the load event
window.addEventListener("load", function () {
// Reading "cookieconsent_status" cookie
const cookieConsent = getCookie('cookieconsent_status');

// Start analytics if user consented or did not deny
if (cookieConsent === 'allow' || cookieConsent === '') {
addAnalytics();
}

// Initialise cookie consent banner
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#efefef",
"text": "#404040"
},
"button": {
"background": "#8ec760",
"text": "#ffffff"
}
},
"type": "opt-out",
"content": {
"allow": "Erlauben",
"dismiss": "Erlauben",
"deny": "Ablehnen"
},
// Reload the page on user choice to make sure cookie is set
onStatusChange: function (status, chosenBefore) {
location.reload();
}
})
});
</script>

{% endif %}

0 comments on commit e5c7451

Please sign in to comment.