Tilbage til bloggen
Technical

Umbraco Cookie Consent: NuGet Package for .NET Developers

GetCookies TeamJanuary 13, 202513 min læsning
Umbraco.NETNuGetCMSIntegration

TLDR: GetCookies for Umbraco is a NuGet package for .NET 6/7/8 that adds GDPR-compliant consent management to Umbraco 10-13. One package install, three lines of config, and your Umbraco site has IAB TCF 2.2, Google Consent Mode v2, and a backoffice dashboard.

Read full summary Complete guide to implementing cookie consent on Umbraco CMS using the GetCookies NuGet package. Covers installation, configuration, Tag Helpers, script blocking, and the Umbraco backoffice integration for viewing consent analytics and scan results—all compliant with GDPR, CCPA, and other privacy regulations. *Summary by Claude AI*
## The .NET Developer's Compliance Challenge A government agency in the Netherlands was running 23 public websites on Umbraco. When the Dutch DPA announced stricter enforcement of cookie consent requirements, their development team faced a problem: most cookie consent solutions were built for WordPress or JavaScript-first stacks. The available options required extensive custom integration, didn't follow .NET conventions, and lacked proper NuGet packaging. Their team spent three months building a custom solution—only to discover it didn't support the new Google Consent Mode v2 requirements. Umbraco developers deserve a consent solution built for .NET, not adapted from WordPress plugins. ## Why Umbraco Needs Native Consent Management Umbraco powers enterprise websites, government portals, and high-traffic applications. These sites have specific requirements: - **.NET ecosystem integration**: DI, configuration, middleware patterns - **Backoffice administration**: Content editors need to manage settings without developer involvement - **Multi-site deployments**: Many Umbraco installations host multiple domains - **Performance requirements**: Enterprise sites can't afford blocking JavaScript loads Generic JavaScript-only consent tools create friction. A native NuGet package integrates properly. ## GetCookies for Umbraco The GetCookies Umbraco package provides full consent management built for .NET developers: ### Key Features | Feature | Description | |---------|-------------| | **NuGet Installation** | Standard .NET package management | | **Umbraco 10-13 Support** | Works with current LTS and latest versions | | **.NET 6/7/8** | Full modern .NET support | | **IAB TCF 2.2** | Certified for programmatic advertising | | **Google Consent Mode v2** | Native integration with proper signal timing | | **Backoffice Dashboard** | Consent analytics in Umbraco admin | | **Tag Helpers** | Razor-native components | ## Installation ### Via .NET CLI ```bash dotnet add package GetCookie.Umbraco ``` ### Via Package Manager Console ```powershell Install-Package GetCookie.Umbraco ``` ### Via NuGet Package Manager Search for "GetCookie.Umbraco" in Visual Studio's NuGet Package Manager. ## Configuration ### Step 1: Add Settings to appsettings.json ```json { "GetCookie": { "DomainId": "your-domain-id", "ApiKey": "your-api-key", "ApiUrl": "https://getcookies.co" } } ``` Get your Domain ID and API key from your [GetCookies Dashboard](https://app.getcookies.co). ### Step 2: Register Services In your `Program.cs`: ```csharp using GetCookie.Umbraco; var builder = WebApplication.CreateBuilder(args); // Add GetCookie services builder.Services.AddGetCookie(builder.Configuration); // Add to Umbraco pipeline builder.CreateUmbracoBuilder() .AddBackOffice() .AddWebsite() .AddGetCookieIntegration() // GetCookie integration .Build(); var app = builder.Build(); ``` ### Step 3: Add to Layout In your `_Layout.cshtml`: ```html @using GetCookie.Umbraco @* GetCookie head scripts (consent defaults, early initialization) *@ @await Html.PartialAsync("_GetCookieHead") @RenderBody() @* GetCookie widget (banner, privacy trigger) *@ @await Html.PartialAsync("_GetCookieWidget") ``` That's it. Your site now has compliant cookie consent. ## Using Tag Helpers The package includes Razor Tag Helpers for cleaner markup: ### Cookie Declaration Add a cookie declaration to your privacy policy page: ```html ``` This renders an auto-updating list of all cookies detected on your site. ### Script Blocking Mark scripts that should only load after consent: ```html @* Analytics scripts - blocked until analytics consent *@ @* Marketing scripts - blocked until marketing consent *@ ``` The `type="text/plain"` prevents execution. GetCookie activates the scripts when the user consents to the specified category. ### Conditional Rendering Use the consent service in Razor: ```csharp @inject IGetCookieService CookieService @if (await CookieService.HasConsentAsync("analytics")) { } ``` ## Umbraco Backoffice Integration The package adds a "GetCookie" section to the Umbraco backoffice: ### Dashboard Tab View consent analytics directly in Umbraco: - Daily consent rate trends - Category breakdown (what users accept/reject) - Geographic distribution - Device type analysis ### Settings Tab Configure consent behavior without deploying code: - Banner style selection - Category customization - Region-specific rules - Language settings ### Scan Results Tab Review cookies detected on your site: - Cookie inventory with sources - Classification status - Compliance warnings - Missing cookies alerts ### Cookie Declaration Preview See exactly what your privacy policy will display: - Cookie list by category - Duration and purpose - Provider information - Declaration history ## Multi-Site Configuration For Umbraco installations hosting multiple domains, configure per-domain settings: ```json { "GetCookie": { "Domains": { "example.com": { "DomainId": "domain-id-1", "ApiKey": "api-key-1" }, "example.de": { "DomainId": "domain-id-2", "ApiKey": "api-key-2" } } } } ``` The package automatically selects the correct configuration based on the request host. ## Google Consent Mode v2 Integration GetCookie handles Google Consent Mode automatically: ```csharp // This happens automatically in _GetCookieHead partial: // 1. dataLayer initialized window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} // 2. Consent defaults set BEFORE Google tags gtag('consent', 'default', { 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied', 'analytics_storage': 'denied', 'wait_for_update': 500 }); // 3. After user consent, signals are updated gtag('consent', 'update', { 'analytics_storage': 'granted' // ... other categories based on user choice }); ``` Your Google Analytics and Google Ads tags receive proper consent signals with correct timing. ## Microsoft UET Consent Mode For sites using Microsoft Advertising (Bing Ads), GetCookie also supports UET Consent Mode: ```javascript // Automatic integration: window.uetq = window.uetq || []; window.uetq.push('consent', 'default', { 'ad_storage': 'denied' }); // After marketing consent: window.uetq.push('consent', 'update', { 'ad_storage': 'granted' }); ``` ## Common Integration Patterns ### With Umbraco Commerce Block e-commerce tracking until consent: ```html ``` ### With Examine Search If you're tracking search analytics: ```csharp public class SearchController : SurfaceController { private readonly IGetCookieService _cookieService; public async Task Search(string query) { // Only track search analytics if consent given if (await _cookieService.HasConsentAsync("analytics")) { _analyticsService.TrackSearch(query); } return View(results); } } ``` ### With Form Submissions Gate form tracking behind consent: ```csharp public class ContactFormController : SurfaceController { [HttpPost] public async Task Submit(ContactForm form) { // Always process the form await _formService.ProcessAsync(form); // Only track conversion if consent given if (await _cookieService.HasConsentAsync("marketing")) { await _conversionService.TrackFormSubmissionAsync(); } return Redirect("/thank-you"); } } ``` ## Troubleshooting ### Banner Not Appearing 1. Verify Domain ID is correct in appsettings.json 2. Check `_GetCookieWidget` partial is in the layout 3. Ensure no JavaScript errors in browser console 4. Verify domain is active in GetCookies dashboard ### Backoffice Section Missing 1. Clear Umbraco runtime cache 2. Restart the application 3. Verify user has access to the GetCookie section ### Script Blocking Not Working 1. Ensure `type="text/plain"` attribute is set 2. Verify `data-olc-category` matches your category ID 3. Check that `_GetCookieHead` partial loads before the blocked script ## Getting Started 1. **Install package** via NuGet 2. **Add configuration** to appsettings.json 3. **Register services** in Program.cs 4. **Add partials** to your layout 5. **Configure banner** in GetCookies dashboard Umbraco developers shouldn't have to build consent management from scratch. GetCookie brings enterprise compliance to .NET with native tooling.

Ofte stillede spørgsmål

Which Umbraco versions are supported?
GetCookie supports Umbraco 10, 11, 12, and 13, running on .NET 6, 7, or 8. Install via NuGet with standard package management.
Does the Umbraco package include a backoffice dashboard?
Yes, the package adds a consent analytics dashboard to your Umbraco backoffice where editors can view consent rates and scan results without developer involvement.
How do I install GetCookie on Umbraco?
Run `dotnet add package GetCookie.Umbraco`, add the configuration to appsettings.json, and add the Tag Helper to your layout. Full integration in under 10 minutes.
G

GetCookies Team

Skribent hos GetCookies, specialiseret i privatlivsoverholdelse, samtykkeadministration og optimering af digital markedsføring.

Klar til at forenkle cookiesamtykke?

GetCookies gør GDPR, CCPA og global privatlivsoverholdelse ubesværet. Kom i gang i dag.