Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

PV.GoogleConsent2Module for Orchard Core

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.


Key Features (For Users)

  • Google Consent Mode v2 Ready: Full support for the new signals ad_user_data and ad_personalization.
  • Automatic GTM Detection: If you use the built-in OrchardCore.Google.TagManager module, the system automatically loads its ContainerID and 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.

Administration Configuration

After installing and enabling the module, navigate to Configuration -> Integrations -> Google Consent Mode v2.

  1. Basic Settings: Activate the module and (optionally) enter your Google Tag ID (G-XXXXXX or AW-XXXXXX). If you are using the OrchardCore Google Tag Manager module, leave this field empty.
  2. Default Consent State: To achieve full legislative compliance with EU rules, leave the default states for analytics and advertising as Denied (unchecked).
  3. 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).

Technical Documentation (For Developers)

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.

Theme Integration (Layout.cshtml)

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>

Injection Architecture (Emergency Fallback)

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.

JavaScript API (window.ConsentManager)

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>

Template Overriding

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).

About

Enterprise-grade Orchard Core module implementing Google Consent Mode v2. Features robust cookie consent management, GDPR compliance, and automatic Google Tag Manager integration.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors