Skip to content

Commit 3807dac

Browse files
cornehoskamgitbook-bot
authored andcommitted
GITBOOK-6: Updated cookiebot documentation v16
1 parent 2004eb7 commit 3807dac

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

16/umbraco-engage/security-and-privacy/gdpr/how-to-become-gdpr-compliant-using-cookiebot.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ This article gives you a working implementation to use with [CookieBot](https://
1414

1515
## Code Example
1616

17-
The code example below shows how to create the backend code to read the CookieBot consent cookie from the end user. Based on that, decide which features of Umbraco Engageit should enable or disable.
17+
The code example below shows how to create the backend code to read the CookieBot consent cookie from the end user. Based on that, decide which features of Umbraco Engage it should enable or disable.
1818

19-
1. Create a class that implements the `Umbraco.Engage.Business.Permissions.ModulePermissions.IModulePermissions` interface.
20-
2. Check the current HTTPContext Request Cookies for the CookieBot cookie which is named **CookieConsent.**
19+
1. Create a class that implements the `Umbraco.Engage.Infrastructure.Permissions.ModulePermissions.IModulePermissions` interface.
20+
2. Check the current HTTPContext Request Cookies for the CookieBot cookie, which is named **CookieConsent.**
2121

2222
From some of the [documentation from CookieBot](https://www.cookiebot.com/en/developer/), implement the same logic to check if the value of the cookie is -1 or another value. If it is set to -1, CookieBot is indicating to us that this is a user within a region that does not require consent.
2323

@@ -26,10 +26,10 @@ The rest of the code is deserializing the JSON string stored inside the cookie f
2626
**CookieBotModulePermissions.cs**
2727

2828
```cs
29-
using Microsoft.AspNetCore.Http;
30-
using Newtonsoft.Json;
29+
using System.Text.Json;
30+
using System.Text.Json.Serialization;
3131
using System.Web;
32-
using Umbraco.Engage.Business.Permissions.ModulePermissions;
32+
using Umbraco.Engage.Infrastructure.Permissions.ModulePermissions;
3333

3434
namespace Umbraco.Engage.StarterKit.CookieBot
3535
{
@@ -56,12 +56,12 @@ namespace Umbraco.Engage.StarterKit.CookieBot
5656
return IsAllowed(context, "preferences");
5757
}
5858

59-
public bool IsAllowed(HttpContext context, string cookiePermission)
59+
private bool IsAllowed(HttpContext context, string cookiePermission)
6060
{
6161
// C# Code from CookieBot to check for their cookie
6262
// https://www.cookiebot.com/en/developer/#h-server-side-usage
6363
var rawCookieBotConsentValues = context.Request.Cookies["CookieConsent"];
64-
64+
6565
if (rawCookieBotConsentValues != null)
6666
{
6767
switch (rawCookieBotConsentValues)
@@ -81,22 +81,22 @@ namespace Umbraco.Engage.StarterKit.CookieBot
8181
return false;
8282
}
8383

84-
public bool CheckCookieBotValue(string rawCookieBotConsentValues, string cookiePermissionToCheck)
84+
private bool CheckCookieBotValue(string rawCookieBotConsentValues, string cookiePermissionToCheck)
8585
{
8686
// Read current user consent in encoded JSON
8787
// Sample JSON cookie payload
8888
/*
89-
* {
90-
* stamp:'Ov4gD1JVnDnBaJv8K2wYQlyWlnNlT/AKO768tibZYdQGNj/EolraLw==',
91-
* necessary:true,
92-
* preferences:false,
93-
* statistics:true,
94-
* marketing:false,
95-
* method:'explicit',
96-
* ver:1,
97-
* utc:1698057791350,
98-
* region:'gb'
99-
* }
89+
{
90+
"stamp": "Ov4gD1JVnDnBaJv8K2wYQlyWlnNlT/AKO768tibZYdQGNj/EolraLw==",
91+
"necessary": true,
92+
"preferences": true,
93+
"statistics": true,
94+
"marketing": true,
95+
"method": "explicit",
96+
"ver": 1,
97+
"utc": 1698057791350,
98+
"region": "gb"
99+
}
100100
*/
101101

102102
// Decode the consent string
@@ -108,7 +108,7 @@ namespace Umbraco.Engage.StarterKit.CookieBot
108108
}
109109

110110
// Deserialize the consent to a dynamic object
111-
var cookieBotConsentValues = JsonConvert.DeserializeObject(decodedConsent);
111+
var cookieBotConsentValues = JsonSerializer.Deserialize<CookieBotConsent>(decodedConsent);
112112
if (cookieBotConsentValues == null)
113113
{
114114
// Something went wrong with the cookieConsent deserialization
@@ -138,16 +138,16 @@ namespace Umbraco.Engage.StarterKit.CookieBot
138138

139139
public class CookieBotConsent
140140
{
141-
[JsonProperty("necessary")]
141+
[JsonPropertyName("necessary")]
142142
public bool Necessary { get; set; }
143143

144-
[JsonProperty("preferences")]
144+
[JsonPropertyName("preferences")]
145145
public bool Preferences { get; set; }
146146

147-
[JsonProperty("statistics")]
147+
[JsonPropertyName("statistics")]
148148
public bool Statistics { get; set; }
149149

150-
[JsonProperty("marketing")]
150+
[JsonPropertyName("marketing")]
151151
public bool Marketing { get; set; }
152152
}
153153
}
@@ -157,15 +157,13 @@ namespace Umbraco.Engage.StarterKit.CookieBot
157157

158158
{% code overflow="wrap" lineNumbers="true" %}
159159
```cs
160-
using Umbraco.Engage.Business.Permissions.ModulePermissions;
161-
using Umbraco.Engage.Common.Composing;
162160
using Umbraco.Cms.Core.Composing;
163-
using Umbraco.Cms.Core.DependencyInjection;
164-
using Umbraco.Extensions;
161+
using Umbraco.Engage.Common.Composing;
162+
using Umbraco.Engage.Infrastructure.Permissions.ModulePermissions;
165163

166164
namespace Umbraco.Engage.StarterKit.CookieBot
167165
{
168-
[ComposeAfter(typeof(AttributeBasedComposer))]
166+
[ComposeAfter(typeof(UmbracoEngageApplicationComposer))]
169167
public class CookieBotComposer : IComposer
170168
{
171169
public void Compose(IUmbracoBuilder builder)
@@ -204,7 +202,7 @@ To install CookieBot, insert the JavaScript tag provided by CookieBot into the `
204202

205203
### Tracking a Visitor's Initial Pageview
206204

207-
Umbraco Engage does not actively track visitors until they have given their consent to the Cookiebot configuration. After the visitor consents, you need to **reload** the page to track the visit. If no reload is performed the visitor's referrer and/or campaign information will not be tracked.
205+
Umbraco Engage does not actively track visitors until they have given their consent to the Cookiebot configuration. After the visitor consents, you need to **reload** the page to track the visit. If no reload is performed, the visitor's referrer and/or campaign information will not be tracked.
208206

209207
Use JavaScript to reload the page when consent is given by handling the **CookiebotOnAccept** event:
210208

@@ -214,4 +212,4 @@ Use JavaScript to reload the page when consent is given by handling the **Cookie
214212

215213
Calling the above method will preserve any referrers and query strings supplied in the current request. It results in Umbraco Engage processing the current page visit and visitor correctly.
216214

217-
For more details, see [Cookiebot Documentation](https://www.cookiebot.com/en/developer/#h-event-handling).
215+
For more details, see the [Cookiebot Documentation](https://www.cookiebot.com/en/developer/#h-event-handling).

0 commit comments

Comments
 (0)