Custom Cookie Manager Plugin With Google Consent Mode v2 Integration

Overview

To prepare multiple client websites for Google Consent Mode v2 and the evolving privacy landscape, we developed a custom WordPress Cookie Manager plugin. This solution replaces scattered third-party scripts with a unified, streamlined, and fully integrated consent system that works seamlessly with Google Tag Manager (GTM), Google Analytics 4 (GA4), and WordPress.

The final product is a lightweight, flexible, and fully configurable cookie banner with consent signaling that complies with modern requirements while allowing complete customization from the backend.


Objectives

1. Implement GDPR-aligned consent behavior

  • Ensure analytics and ad tags only fire when consent is granted.
  • Enforce correct behavior on first-page load.
  • Persist user decisions across sessions.

2. Support Google Consent Mode v2

  • Trigger consent defaults before GTM loads.
  • Provide accurate consent updates based on user actions.
  • Enable measurement modeling and correct data behavior when consent is denied.

3. Deliver a reusable WordPress plugin

  • Works across multiple sites with zero code edits.
  • Allows centralized management from the WordPress admin.
  • Ensures high performance and low overhead.

4. Provide full customization control

  • Editable text, button labels, and messaging.
  • Selectable privacy policy page.
  • Custom colors and border radius settings.
  • Choose default consent: Granted or Declined.

Key Features Delivered

A. Fully Custom Consent Banner

A sleek, responsive consent banner appears whenever no previous preference is stored. It includes:

  • Accept all button
  • Reject non-essential cookies button
  • Optional link to the Privacy Policy
  • Dynamic text with a shortcode replacement for [privacy_page]

Styling options include:

  • Background color
  • Text color
  • Button colors
  • Border radius
  • Custom heading and message fields

All adjustable from the plugin settings page.


B. Complete Consent Mode v2 Integration

The plugin now sends both key consent signals:

  • consent.default – based on admin setting (granted or denied)
  • consent.update – after user accepts or rejects

This ensures:

  • No analytics or ad cookies are placed before consent.
  • GTM behaves according to Google’s latest compliance requirements.
  • GA4 continues modeling when denied, and full tracking resumes when granted.

C. Persistent Consent Storage

User choices are saved using localStorage. This provides:

  • Consistent behavior across the entire site
  • No repeated banners after the user makes a choice
  • Instant consent updates inside GTM

D. Dedicated WordPress Admin Page

A standalone Cookie Manager menu was added to the WordPress dashboard, containing:

  • Enable/disable switch
  • Custom banner heading
  • Editable banner message
  • Accept and reject button text
  • “More information” text
  • Dropdown to select the Privacy Policy page
  • Default consent selection
  • Color controls
  • Border radius control

Everything is configurable directly by the website administrator.


E. Verified Compatibility With GTM

Using GTM Preview Mode, the DataLayer Checker extension, and network inspection, we validated:

  • Consent defaults load before the GTM container triggers
  • Accept/reject interactions correctly push updates
  • GTM receives the right consent signals
  • No undesired overrides occur unless explicitly set in GTM

This ensures consistent, compliant tracking behavior.


Challenges Solved

1. Ensuring early consent signals

We ensured the default consent command loads as early as possible in the <head>, so GTM initializes with the correct state.

2. Preventing GTM overrides

We identified how GTM settings can override consent and developed the plugin to remain the authoritative source unless intentionally changed.

3. Developer-friendly testing

A clear reset process allows easy re-testing of the consent banner without affecting other site behavior.

4. Design flexibility

The banner styling is fully customizable to match any brand identity without editing code.


Outcome

The completed plugin provides:

  • Proper implementation of Google Consent Mode v2
  • A fully functional and customizable cookie consent banner
  • Seamless integration with GA4 and GTM
  • Persistent and accurate consent tracking
  • A scalable solution ready for deployment across all client websites

This project reduces dependency on third-party cookie tools, improves compliance accuracy, enhances site performance, and empowers administrators with full control directly from WordPress.

Let's get your website started

Take the first step toward a stunning, high-performing website that works for your business.
Let's get started
arrow-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram