An enterprise-grade module for Orchard Core that implements advanced cookie consent management, fully compliant with the Google Consent Mode v2 standard and European legislation (GDPR, ePrivacy, DMA).
The module ensures seamless integration of analytical and advertising tools with user preferences, automatically detects existing Google Tag Manager settings, and utilizes a robust fallback rendering system (Middleware Fallback) to work with any frontend theme.
- Google Consent Mode v2 Ready: Full support for the new signals
ad_user_dataandad_personalization. - Automatic GTM Detection: If you use the built-in
OrchardCore.Google.TagManagermodule, the system automatically loads itsContainerIDand prevents duplicate script loading. - Privacy by Default: The module's architecture is designed for an opt-in approach. Before the user interacts with the banner, only anonymous "cookieless pings" are sent.
- Floating Button: Visitors can change their preferences or revoke consent at any time by clicking a discreet icon in the corner of the screen.
- Localization: The module is fully localized into Czech and English using standard PO files.
After installing and enabling the module, navigate to Configuration -> Integrations -> Google Consent Mode v2.
- Basic Settings: Activate the module and (optionally) enter your Google Tag ID (
G-XXXXXXorAW-XXXXXX). If you are using the OrchardCore Google Tag Manager module, leave this field empty. - Default Consent State: To achieve full legislative compliance with EU rules, leave the default states for analytics and advertising as
Denied(unchecked). - Appearance and Behavior:
- Customize the banner and button texts.
- Set the banner position (Top/Bottom).
- Enable the display of the floating icon for recalling settings and choose its position (Bottom Left / Bottom Right).
The module is written with an emphasis on clean architecture, .NET 10, and Orchard Core 3.0.1. It utilizes OC conventions (Convention over Configuration) and strictly separates the presentation layer from the application logic.
The module is automatically integrated into your theme using ViewComponents. This approach ensures that the code is injected exactly where it should be, without disrupting styles or functionality.
We recommend implementing these components in Layout.cshtml with a try-catch safeguard, so they work regardless of whether the module is enabled or disabled:
1. Insertion into the <head> section (DataLayer and GTAG Initialization):
<head>
<!-- Here are your standard meta tags, styles, etc. -->
@* PV.GoogleConsent2Module: Consent Mode Scripts *@
@try { @await Component.InvokeAsync("ConsentScripts") } catch { }
</head>2. Insertion before (HTML Banner and Modal):
<body>
<!-- Here is the main content of your website -->
@* PV.GoogleConsent2Module: UI Components (Banner, Modal, Floating Button) *@
@try { @await Component.InvokeAsync("ConsentBanner") } catch { }
</body>If you do not add the aforementioned ViewComponents to your template (or if you are using a third-party theme that you cannot access), the module includes a defensive fallback layer:
ConsentInjectionMiddleware: If the standard components are not rendered, the middleware intercepts the HTTP Response Stream, parses the HTML, and hardcodes the necessary DOM elements and scripts right before </head> and </body>.
Both layers (components and middleware) strictly respect the AdminAttribute – the banner is never rendered in the Orchard Core admin interface.
The module exposes a global, safely initialized object for client-side manipulation. You can use it to integrate custom buttons (e.g., a custom link in the theme footer):
// Displays the primary informational banner
window.ConsentManager.showConsentBanner();
// Displays the detailed modal window with category toggles
window.ConsentManager.showConsentModal();
// Completely clears the user's cookie, resets GTM signals via dataLayer, and re-displays the banner
window.ConsentManager.revokeConsent();Example of a custom button in a Liquid template (Footer.liquid):
<a href="#" onclick="if(window.ConsentManager) { window.ConsentManager.revokeConsent(); return false; }">
Modify cookie settings
</a>If you want to change the DOM structure of the banner, simply create the file Views/Shared/Components/ConsentBanner/Default.cshtml in your main project (Theme). The Orchard Core Resource Manager will automatically prioritize your template over the default one in the module. Styles are injected independently and do not interfere with global CSS frameworks (Bootstrap, Tailwind).