uMarketingSuite is a powerful Umbraco Package offering features like web analytics, personalization and A/B testing. How can we make sure we meet the cookie requirements enforced on us by, for example, the GDPR? Cookiebot is one of the possible and popular Consent Management Platforms to offer control and transparency on our website's cookie usage! Let's take a look at how we can combine uMarketingSuite with Cookiebot Consent! 🍪
Before we get started today, I will be making the assumption that you already have uMarketingSuite installed on your Umbraco 9 application, and that you have Cookiebot added to the script tags of your website. For more information on uMarketingSuite, click here, and for more information on Cookiebot, click here.
DISCLAIMER: The code snippets & instructions given below are examples of possible implementations. Do not take these examples as legal advice, as I am not responsible for any consequences that may follow!
We will get started by configuring the Permissions of uMarketingSuite. As of version 1.13.0 of said package we can disable the individual modules (A/B Testing, Analytics & Personalization) from within our code base! Instead of hard-coding these permissions to be either true or false, we will be checking whether the website user has accepted or declined the proper cookie permissions using Cookiebot's consent dialog!
To configure the permissions, we will start off with creating a new class that inherits from the IModulePermissions interface (uMarketingSuite.Business.Permissions.ModulePermissions.IModulePermissions). Doing so implements the following methods:
We will name our class MarketingPermissions! In this class we will be implementing our business logic that checks the Cookie Permissions given by the current user request, and determine what uMarketingSuite is and isn't allowed to do! We are using a refactored version of the example given by Cookiebot, to follow the Umbraco 9 & .NET 5 conventions!
Our snippet below will disable the Analytics part of uMarketingSuite if the user hasn't given explicit permissions for the 'statistics' use-case of our website! We do this by checking whether the user has given any permissions to begin with, by checking if the user is within a region that requires consent, and by checking whether the user opted out of any and all cookies. When that's done, we can check the specific 'statistics' key!
Now that we have our Cookie Consent implementation configured, all we have to do is register our permissions class as an Unique service, as per documentation of uMarketingSuite, to override the default behavior. We do this by creating a new instance of IComposer, and registering our permissions as an Unique service! For more information on Dependency Injection with Umbraco 9, check out the Umbraco 8 versus 9 - Dependency Injection Blog Post!
Don't forget to add the [ComposeAfter] attribute so that our composer runs after the internal uMarketingSuite composers!
And that's it! If we head over to any page of our Umbraco site, and we attach our Debugger to our MarketingPermissions class, we should see that with every request that comes in, we will be checking the users current Cookie Consent, and act accordingly with uMarketingSuite! 🔥🍪
DISCLAIMER: The code snippets & instructions given in this article are examples of possible implementations. Do not take these examples as legal advice, as I am not responsible for any consequences that may follow!
If you have any further questions, feel free to contact me over at my socials available at the Contact page, and I'd love to hear about the amazing creations you're able to come up with! 😄
Sources used in this article:
uMarketingSuite Documentation, https://documentation.umarketingsuite.com/the-umarketingsuite-broad-overview/the-umarketingsuite-cookie/module-permissions/
Cookiebot Documentation, https://www.cookiebot.com/en/developer/
Umbraco 8 versus 9 - Dependency Injection, https://cornehoskam.com/posts/umbraco-8-versus-9-dependency-injection