From 82718ebedf15ffc63a0ab82cf2e457eb7708d402 Mon Sep 17 00:00:00 2001 From: Henrik Oehmke Date: Fri, 11 Sep 2020 10:24:45 +0200 Subject: [PATCH] Task: #12 - Make consent logging configurable --- Configuration/Settings.yaml | 1 + README.md | 8 +++++ .../Renderers/Renderer.CookieSettings.fusion | 3 ++ Resources/Public/JavaScript/Main.js | 31 ++++++++++--------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 96d4a71..937aee2 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -25,6 +25,7 @@ KaufmannDigital: CookieConsent: siteCSSFilepath: null customCSSFilepath: null + consentLogEnabled: false siteStyles: [] # "rootNode name 1": # siteCSSFilepath: diff --git a/README.md b/README.md index 0aee177..0620a31 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,14 @@ KaufmannDigital: ``` *Hint: We are working on advanced styling options. Different style- and positioning presets will be available in future. If you have any wishes or created a cool design for this banner yourself, please contact us.* +### Consent Logging +The package provides the ability to track the users decisions by storing the chosen consent identifiers along with a random user id and the user agent in your database. This feature is disabled by default, you can enable it in your Settings.yaml: +```yaml +KaufmannDigital: + GDPR: + CookieConsent: + consentLogEnabled: true +``` ## Roadmap / Planned Features diff --git a/Resources/Private/Fusion/Renderers/Renderer.CookieSettings.fusion b/Resources/Private/Fusion/Renderers/Renderer.CookieSettings.fusion index dab96a5..706b774 100644 --- a/Resources/Private/Fusion/Renderers/Renderer.CookieSettings.fusion +++ b/Resources/Private/Fusion/Renderers/Renderer.CookieSettings.fusion @@ -120,6 +120,8 @@ prototype(KaufmannDigital.GDPR.CookieConsent:Content.CookieSettings.Renderer) < jsVariables = Neos.Fusion:Tag { tagName = 'script' + consentLogEnabled = ${Configuration.Setting('KaufmannDigital.GDPR.CookieConsent.consentLogEnabled') ? 'true' : 'false'} + trackChoiceUrl = Neos.Fusion:UriBuilder { package = 'KaufmannDigital.GDPR.CookieConsent' controller = 'Api' @@ -136,6 +138,7 @@ prototype(KaufmannDigital.GDPR.CookieConsent:Content.CookieSettings.Renderer) < content = ${' var trackChoiceUrl = "' + this.trackChoiceUrl + '"; var generatedJsUrl = "' + this.generatedJsUrl + '"; + var consentLogEnabled = ' + this.consentLogEnabled + '; '} } diff --git a/Resources/Public/JavaScript/Main.js b/Resources/Public/JavaScript/Main.js index 94b03da..fcadd67 100644 --- a/Resources/Public/JavaScript/Main.js +++ b/Resources/Public/JavaScript/Main.js @@ -38,16 +38,17 @@ function initializeCookieConsent() { var btnAcceptNecessaryCookies = document.querySelector('#gdpr-cc-btn-accept-necessary'); //Create log in BE and store userID - var xhr = new XMLHttpRequest(); - xhr.open('POST', trackChoiceUrl); - xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); - xhr.onreadystatechange = function() { - if(xhr.readyState === 4) { - kd_gdpr_cc_userid = JSON.parse(xhr.response).userId; - } - }; - xhr.send(); - + if (consentLogEnabled) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', trackChoiceUrl); + xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); + xhr.onreadystatechange = function() { + if(xhr.readyState === 4) { + kd_gdpr_cc_userid = JSON.parse(xhr.response).userId; + } + }; + xhr.send(); + } btnIndividualSettingsEnable.addEventListener('click', function() { individualSettingsContainer.style.display = 'block'; @@ -222,10 +223,12 @@ function saveConsentToCookie(inputs, userId) { } }); - var xhr = new XMLHttpRequest(); - xhr.open('POST', trackChoiceUrl, false); - xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); - xhr.send(JSON.stringify({'choice': cookieData})); + if (consentLogEnabled) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', trackChoiceUrl, false); + xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); + xhr.send(JSON.stringify({'choice': cookieData})); + } }