Skip to content

Commit

Permalink
Merge pull request #22 from heoehmke/issues/12-configurable-logging
Browse files Browse the repository at this point in the history
Task: #12 - Make consent logging configurable
  • Loading branch information
Nikdro authored Sep 28, 2020
2 parents 11fabc0 + 82718eb commit cca9abf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ KaufmannDigital:
CookieConsent:
siteCSSFilepath: null
customCSSFilepath: null
consentLogEnabled: false
siteStyles: []
# "rootNode name 1":
# siteCSSFilepath: <link to css>
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -136,6 +138,7 @@ prototype(KaufmannDigital.GDPR.CookieConsent:Content.CookieSettings.Renderer) <
content = ${'
var trackChoiceUrl = "' + this.trackChoiceUrl + '";
var generatedJsUrl = "' + this.generatedJsUrl + '";
var consentLogEnabled = ' + this.consentLogEnabled + ';
'}
}

Expand Down
31 changes: 17 additions & 14 deletions Resources/Public/JavaScript/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}));
}
}


Expand Down

0 comments on commit cca9abf

Please sign in to comment.