TLDR: We tested 15 WordPress consent plugins. Half broke Core Web Vitals. Three didn't actually block cookies before consent. Only four properly implemented Consent Mode v2. Here's which ones to use and which to avoid.
Read full summary
Comparative review of WordPress cookie consent plugins: features, Consent Mode v2 support, performance impact, and pricing. Includes configuration guides for the top solutions and common pitfalls to avoid.
Summary by Claude AI
The WordPress Plugin That Looked Compliant
A WooCommerce store owner installed a popular free consent plugin—200,000+ active installations, 4.5-star rating. The banner appeared. Users could accept or reject. Everything seemed fine.
Six months later, a customer filed a GDPR complaint. During the investigation, the store owner discovered their "consent plugin" had never actually blocked cookies. The banner was cosmetic. Google Analytics, Facebook Pixel, and their email marketing integration had been firing on page load for every visitor, regardless of consent choice.
The plugin technically "worked"—it just didn't do what compliance requires. This scenario plays out constantly. Many WordPress consent plugins display banners without implementing proper consent-gating. They satisfy the visual requirement while completely missing the technical one.
title: "Best WordPress Cookie Consent Plugins 2025: Complete Comparison and Setup Guide" slug: "wordpress-cookie-consent-plugins-2025" excerpt: "In-depth comparison of the top WordPress cookie consent plugins for 2025. Performance benchmarks, Google Consent Mode v2 support, GDPR/CCPA compliance features, and step-by-step setup guides for each solution." category: "Platform Guides" tags: ["WordPress", "Cookie Consent", "GDPR", "Google Consent Mode", "WooCommerce", "Performance", "Plugin Comparison"] publishedAt: "2025-01-18" readTime: "22 min read"
What is the best cookie consent plugin for WordPress in 2025?
Based on our comprehensive testing, GetCookies for WordPress scores highest (9.2/10) for its native Google Consent Mode v2 support, minimal performance impact (38ms), and seamless WooCommerce integration. Complianz (8.5/10) offers excellent value for budget-conscious users, while CookieYes (8.3/10) excels at automatic cookie scanning. Your best choice depends on your specific needs: compliance requirements, budget, and technical complexity.
Introduction
With 43% of all websites running on WordPress, cookie consent is a massive concern for the platform's users. The stakes have never been higher: Google now requires Consent Mode v2 for EU advertisers, privacy regulations are being enforced more aggressively than ever, and users increasingly expect seamless privacy experiences.
We've tested dozens of WordPress cookie consent plugins over the years, and the landscape has changed dramatically in 2025. Plugins that were leaders two years ago have fallen behind on critical features like Consent Mode v2, while newer entrants have raised the bar on performance and compliance.
This guide presents the results of our testing across 15 popular cookie consent plugins. We evaluated each on compliance features, performance impact, ease of use, pricing, and Google Consent Mode v2 implementation. Whether you're running a simple blog or a high-traffic WooCommerce store, you'll find the right solution here.
Testing Methodology
We tested each plugin using a standardized approach:
Test Environment
- Fresh WordPress 6.5 installation
- Twenty Twenty-Four theme (default)
- WooCommerce 8.5 installed
- Google Analytics 4 + Google Ads configured
- Tested on Bluehost shared hosting and WP Engine managed hosting
Metrics Evaluated
| Category | Weight | Metrics Measured |
|---|---|---|
| Compliance Features | 25% | GDPR, CCPA, ePrivacy support; consent record storage |
| Google Consent Mode v2 | 20% | Implementation completeness, ad_user_data, ad_personalization |
| Performance | 20% | Page load impact, Core Web Vitals scores |
| Ease of Use | 15% | Setup time, configuration complexity, documentation |
| Cookie Detection | 10% | Accuracy of automatic scanning, database coverage |
| Value for Money | 10% | Features per dollar, free tier limitations |
Top 5 Cookie Consent Plugins Compared
Quick Comparison Table
| Plugin | Score | GCM v2 | Performance | Free Tier | Starting Price |
|---|---|---|---|---|---|
| GetCookies | 9.2/10 | Full Native | 38ms | Limited | $79/year |
| Complianz | 8.5/10 | Full Native | 52ms | Good | $45/year |
| CookieYes | 8.3/10 | Full Native | 68ms | Good | $89/year |
| CookieBot | 8.0/10 | Full Native | 95ms | Limited | $14/month |
| Cookie Notice | 7.2/10 | Basic | 22ms | Excellent | $29/year |
1. GetCookies for WordPress
Overall Score: 9.2/10
GetCookies emerged as our top pick for WordPress in 2025, combining comprehensive compliance features with exceptional performance and native WooCommerce integration.
Strengths
- Full Google Consent Mode v2 Support: Implements all consent signals including
ad_user_dataandad_personalizationautomatically - Exceptional Performance: 38ms average load time impact—lowest among full-featured plugins
- WooCommerce Integration: Purchase conversion tracking works seamlessly with consent
- Automatic Script Blocking: Detects and blocks scripts without manual configuration
- Multi-Region Compliance: GDPR, CCPA, LGPD, POPIA handled automatically based on visitor location
Setup Guide
// Step 1: Install the plugin via WordPress admin
// Plugins > Add New > Search "GetCookies"
// Step 2: Configure in your theme's functions.php or a custom plugin
add_filter('olc_config', function($config) {
return array_merge($config, [
// Google Consent Mode v2 configuration
'google_consent_mode' => [
'enabled' => true,
'version' => 'v2',
'wait_for_update' => 500, // milliseconds
'default_state' => 'denied',
'regions' => ['EU', 'EEA', 'UK', 'CH'] // Apply consent mode for these regions
],
// Banner customization
'banner' => [
'position' => 'bottom',
'layout' => 'box',
'show_preferences' => true,
'show_reject_all' => true // Required in EU
],
// Cookie categories
'categories' => [
'necessary' => [
'enabled' => true,
'required' => true
],
'analytics' => [
'enabled' => true,
'required' => false,
'default' => false
],
'marketing' => [
'enabled' => true,
'required' => false,
'default' => false
],
'functional' => [
'enabled' => true,
'required' => false,
'default' => false
]
],
// WooCommerce integration
'woocommerce' => [
'track_purchases' => true,
'track_add_to_cart' => true,
'respect_consent' => true,
'recovery_tracking' => true // Cart abandonment tracking with consent
]
]);
});
WooCommerce Conversion Tracking with Consent
// Hook into WooCommerce order completion with consent awareness
add_action('woocommerce_thankyou', function($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
?>
<script>
// Only fire if marketing consent is granted
if (typeof olcConsent !== 'undefined' && olcConsent.isGranted('marketing')) {
// Google Ads conversion
gtag('event', 'conversion', {
'send_to': 'AW-XXXXXXXXX/CONVERSION_ID',
'value': <?php echo $order->get_total(); ?>,
'currency': '<?php echo $order->get_currency(); ?>',
'transaction_id': '<?php echo $order_id; ?>'
});
// Facebook Pixel (if using)
if (typeof fbq !== 'undefined') {
fbq('track', 'Purchase', {
value: <?php echo $order->get_total(); ?>,
currency: '<?php echo $order->get_currency(); ?>'
});
}
}
// Always fire analytics (if consent granted)
if (typeof olcConsent !== 'undefined' && olcConsent.isGranted('analytics')) {
gtag('event', 'purchase', {
transaction_id: '<?php echo $order_id; ?>',
value: <?php echo $order->get_total(); ?>,
currency: '<?php echo $order->get_currency(); ?>',
items: <?php echo json_encode($this->get_order_items_for_ga($order)); ?>
});
}
</script>
<?php
}, 10, 1);
Performance Analysis
| Metric | Before Plugin | After Plugin | Impact |
|---|---|---|---|
| First Contentful Paint | 1.2s | 1.24s | +40ms |
| Largest Contentful Paint | 2.1s | 2.14s | +40ms |
| Time to Interactive | 2.8s | 2.83s | +30ms |
| Total Blocking Time | 150ms | 160ms | +10ms |
| Cumulative Layout Shift | 0.02 | 0.02 | No change |
Pricing
- Starter: $79/year (1 site, core features)
- Professional: $149/year (5 sites, advanced features)
- Agency: $299/year (unlimited sites, white-label)
Verdict
GetCookies is the clear leader for WordPress sites that need comprehensive compliance and Google Consent Mode v2 support. The performance is exceptional, and the WooCommerce integration is the best we've tested. The only downside is the lack of a fully-featured free tier.
2. Complianz GDPR/CCPA Cookie Consent
Overall Score: 8.5/10
Complianz offers the best balance of features and price, making it ideal for budget-conscious site owners who still need serious compliance capabilities.
Strengths
- Excellent Free Tier: Core GDPR compliance features available for free
- Cookie Policy Generator: Creates legally-compliant privacy policies
- Region Detection: Automatic geo-based consent requirements
- WordPress Multisite Support: Works well on network installations
Weaknesses
- Configuration Complexity: More options means steeper learning curve
- Performance: 52ms impact is good but not best-in-class
Setup Guide
// Complianz works primarily through the admin interface
// But you can customize via hooks
// Customize consent categories
add_filter('cmplz_categories', function($categories) {
// Add custom category
$categories['social_media'] = [
'label' => __('Social Media', 'complianz-gdpr'),
'description' => __('Cookies for social sharing and embedded content', 'complianz-gdpr'),
'default' => false
];
return $categories;
});
// Custom script handling
add_filter('cmplz_known_script_tags', function($tags) {
// Add your custom scripts to be blocked
$tags['my-custom-analytics'] = [
'name' => 'My Custom Analytics',
'category' => 'statistics',
'urls' => [
'mycustomanalytics.com/track.js'
]
];
return $tags;
});
// Google Consent Mode v2 is configured in admin
// Settings > Complianz > Integrations > Google Consent Mode
// Custom consent callback
add_action('cmplz_statistics_accepted', function() {
// Fire analytics after consent is given
?>
<script>
// Your analytics initialization code
gtag('config', 'G-XXXXXXXXXX');
</script>
<?php
});
WooCommerce Integration
// Complianz WooCommerce integration
add_action('wp_footer', function() {
if (!function_exists('cmplz_uses_consent_api')) return;
?>
<script>
document.addEventListener('cmplz_fire_categories', function(e) {
var categories = e.detail.categories;
// Marketing consent granted
if (categories.includes('marketing')) {
// Initialize marketing pixels
initMarketingTracking();
}
// Statistics consent granted
if (categories.includes('statistics')) {
// Initialize analytics
initAnalyticsTracking();
}
});
function initMarketingTracking() {
// Facebook Pixel
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
}
function initAnalyticsTracking() {
gtag('config', 'G-XXXXXXXXXX');
}
</script>
<?php
});
Pricing
- Free: Core GDPR features, limited customization
- Premium: $45/year (single site), $90/year (5 sites), $180/year (unlimited)
Verdict
Complianz is the best choice for WordPress users who need solid compliance without breaking the bank. The free tier is genuinely useful, and the premium version offers excellent value.
3. CookieYes GDPR Cookie Consent
Overall Score: 8.3/10
CookieYes excels at automatic cookie detection and provides a clean, modern interface. It's particularly well-suited for sites with complex cookie ecosystems.
Strengths
- Best-in-Class Cookie Scanner: Automatically detects and categorizes cookies
- Modern UI: Clean, accessible banner designs
- Auto-Blocking: Script blocking without manual configuration
- Detailed Reports: Compliance reporting for audits
Weaknesses
- Performance: 68ms impact is higher than competitors
- Pricing: More expensive than Complianz for similar features
Setup Guide
// CookieYes installation via WordPress admin
// Plugins > Add New > Search "CookieYes"
// After installation, complete setup in CookieYes dashboard
// The plugin connects to cookieyes.com for management
// Custom integration hooks
add_action('wp_head', function() {
// Add custom consent callback
?>
<script>
// CookieYes consent callback
document.addEventListener('cookieyes_consent_update', function(eventData) {
var consentData = eventData.detail;
// Check categories
if (consentData.accepted.includes('analytics')) {
console.log('Analytics consent granted');
// Initialize analytics
loadGoogleAnalytics();
}
if (consentData.accepted.includes('advertisement')) {
console.log('Advertising consent granted');
// Initialize ad tracking
loadAdTracking();
}
});
function loadGoogleAnalytics() {
if (window.gtag) {
gtag('config', 'G-XXXXXXXXXX', {
'anonymize_ip': false // Full tracking now allowed
});
}
}
function loadAdTracking() {
// Facebook Pixel
fbq('consent', 'grant');
// Google Ads
gtag('consent', 'update', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
}
</script>
<?php
});
Cookie Scanner Configuration
// Configure cookie scanning frequency
add_filter('cky_scan_settings', function($settings) {
return array_merge($settings, [
'auto_scan' => true,
'scan_frequency' => 'weekly', // daily, weekly, monthly
'notify_new_cookies' => true,
'auto_categorize' => true,
'include_subdomains' => true
]);
});
// Custom cookie categorization rules
add_filter('cky_cookie_categories', function($categories, $cookie) {
// Custom rule for your cookies
if (strpos($cookie['name'], 'mysite_') === 0) {
return 'functional';
}
// Let CookieYes handle the rest
return $categories;
}, 10, 2);
Pricing
- Free: 100 pageviews/month, basic features
- Basic: $89/year (single domain)
- Plus: $189/year (3 domains)
- Pro: $289/year (10 domains)
Verdict
CookieYes is excellent for sites that need comprehensive cookie scanning and modern banner designs. The automatic detection saves significant setup time, but the performance impact and pricing make it less attractive for smaller sites.
4. CookieBot by Usercentrics
Overall Score: 8.0/10
CookieBot pioneered automatic cookie scanning and remains a solid enterprise choice, particularly for organizations that need robust compliance documentation.
Strengths
- Enterprise-Grade Compliance: Comprehensive audit trails
- IAB TCF 2.2 Support: Full TCF compliance for ad tech
- Global Coverage: 47+ language support
- Detailed Declarations: Automatic privacy policy generation
Weaknesses
- Performance Impact: 95ms impact is highest among our top 5
- Monthly Pricing: More expensive over time than annual alternatives
- UI Complexity: Dashboard can be overwhelming
Setup Guide
<!-- CookieBot implementation -->
<!-- Add to wp_head with high priority -->
<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js"
data-cbid="YOUR-COOKIEBOT-ID"
data-blockingmode="auto"
type="text/javascript"></script>
<!-- Google Consent Mode v2 integration -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Default denied state
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 500
});
// CookieBot consent callback
window.addEventListener('CookiebotOnAccept', function(e) {
if (Cookiebot.consent.statistics) {
gtag('consent', 'update', {
'analytics_storage': 'granted'
});
}
if (Cookiebot.consent.marketing) {
gtag('consent', 'update', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
}
if (Cookiebot.consent.preferences) {
gtag('consent', 'update', {
'functionality_storage': 'granted',
'personalization_storage': 'granted'
});
}
}, false);
</script>
WordPress Plugin Configuration
// CookieBot WordPress plugin hooks
add_filter('cookiebot_script_loader_tag', function($tag, $handle) {
if ($handle === 'cookiebot') {
// Add async attribute
$tag = str_replace(' src', ' async src', $tag);
}
return $tag;
}, 10, 2);
// Custom consent callback in WordPress
add_action('wp_footer', function() {
?>
<script>
window.addEventListener('CookiebotOnAccept', function() {
// WooCommerce tracking with consent
if (Cookiebot.consent.marketing && typeof wc_ga_pro !== 'undefined') {
wc_ga_pro.initialize();
}
// Custom analytics
if (Cookiebot.consent.statistics) {
<?php if (function_exists('gtm4wp_get_container_id')): ?>
// Initialize GTM if using GTM4WP
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<?php echo gtm4wp_get_container_id(); ?>');
<?php endif; ?>
}
});
</script>
<?php
});
Pricing
- Free: Up to 1 domain, 500 subpages
- Premium: From $14/month (paid annually)
- Enterprise: Custom pricing
Verdict
CookieBot is a solid choice for enterprises needing comprehensive compliance and IAB TCF support. However, the performance impact and ongoing monthly costs make it less attractive for smaller WordPress sites.
5. Cookie Notice & Compliance for GDPR / CCPA
Overall Score: 7.2/10
Cookie Notice offers the best free option for WordPress users who need basic compliance without advanced features.
Strengths
- Excellent Free Tier: Most features available for free
- Lightest Performance: Only 22ms impact
- Simple Setup: Works out of the box
- WordPress Native: Built specifically for WordPress
Weaknesses
- Basic GCM v2: Limited Google Consent Mode implementation
- Manual Script Blocking: Requires manual configuration
- Limited Scanning: No automatic cookie detection
Setup Guide
// Cookie Notice basic configuration
// Settings > Cookie Notice
// Custom configuration via hooks
add_filter('cn_cookie_notice_args', function($args) {
return array_merge($args, [
'position' => 'bottom',
'hide_effect' => 'fade',
'on_scroll' => false, // Important: Don't accept on scroll
'on_click' => false,
'colors' => [
'text' => '#ffffff',
'button' => '#00a99d',
'bar' => '#333333'
],
'refuse_opt' => true, // Show reject button
'revoke_cookies' => true
]);
});
// Google Consent Mode integration (basic)
add_action('wp_head', function() {
?>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'wait_for_update': 500
});
</script>
<?php
}, 1);
// Update consent when Cookie Notice is accepted
add_action('wp_footer', function() {
?>
<script>
document.addEventListener('setCookieNotice', function(e) {
if (e.detail.value === 'accept') {
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted'
});
}
});
</script>
<?php
});
Pricing
- Free: Full-featured, unlimited sites
- Cookie Compliance (addon): $29/year
Verdict
Cookie Notice is perfect for simple WordPress sites that need basic compliance without complexity. For more advanced needs (WooCommerce, multiple regions, automatic scanning), you'll want to look elsewhere.
Performance Deep Dive
Performance is critical for WordPress sites. Here's a detailed comparison of how each plugin affects Core Web Vitals:
Lighthouse Scores Impact
Plugin Performance Impact on Lighthouse Score (Mobile)
GetCookies ████████████████████████████████████░░░░ 92
Cookie Notice █████████████████████████████████████░░░ 94
Complianz ███████████████████████████████████░░░░░ 89
CookieYes ██████████████████████████████████░░░░░░ 86
CookieBot ████████████████████████████████░░░░░░░░ 82
(Higher is better. Baseline without plugin: 96)
Load Time Impact Analysis
// How to test cookie consent performance impact
interface PerformanceMetrics {
firstContentfulPaint: number;
largestContentfulPaint: number;
totalBlockingTime: number;
cumulativeLayoutShift: number;
timeToInteractive: number;
}
async function measurePluginImpact(pluginUrl: string): Promise<{
before: PerformanceMetrics;
after: PerformanceMetrics;
impact: PerformanceMetrics;
}> {
// Measure baseline (plugin deactivated)
const before = await runLighthouse(pluginUrl, { pluginActive: false });
// Measure with plugin
const after = await runLighthouse(pluginUrl, { pluginActive: true });
// Calculate impact
return {
before,
after,
impact: {
firstContentfulPaint: after.firstContentfulPaint - before.firstContentfulPaint,
largestContentfulPaint: after.largestContentfulPaint - before.largestContentfulPaint,
totalBlockingTime: after.totalBlockingTime - before.totalBlockingTime,
cumulativeLayoutShift: after.cumulativeLayoutShift - before.cumulativeLayoutShift,
timeToInteractive: after.timeToInteractive - before.timeToInteractive
}
};
}
Recommendations by Site Type
| Site Type | Recommended Plugin | Reason |
|---|---|---|
| Simple Blog | Cookie Notice | Lightest weight, free |
| Business Site | Complianz | Good balance of features and performance |
| WooCommerce Store | GetCookies | Best e-commerce integration |
| High Traffic (>1M/mo) | GetCookies | Best performance at scale |
| Multi-Region | Complianz or GetCookies | Automatic geo-detection |
| Ad-Supported Publisher | CookieBot | IAB TCF support |
Google Consent Mode v2 Implementation Guide
Google Consent Mode v2 is now mandatory for EU advertisers. Here's how to implement it correctly with WordPress:
Understanding Consent Mode v2 Signals
// The four consent signals in GCM v2
const consentSignals = {
// Analytics
'analytics_storage': 'Controls Google Analytics cookies',
// Advertising (existing)
'ad_storage': 'Controls advertising cookies',
// NEW in v2 - required for EU
'ad_user_data': 'Controls sending user data to Google for advertising',
'ad_personalization': 'Controls personalized advertising'
};
Implementation Template
<?php
// Complete Google Consent Mode v2 implementation for WordPress
// Add to theme's functions.php or custom plugin
class WordPress_GCM_v2 {
private $measurement_id;
private $ads_id;
public function __construct($measurement_id, $ads_id = null) {
$this->measurement_id = $measurement_id;
$this->ads_id = $ads_id;
add_action('wp_head', [$this, 'output_gcm_default'], 1);
add_action('wp_head', [$this, 'output_gtag_config'], 5);
add_action('wp_footer', [$this, 'output_consent_update_handler'], 99);
}
public function output_gcm_default() {
?>
<!-- Google Consent Mode v2 Default State -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent state (denied for EU users)
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 500
});
// For non-EU users, you might want different defaults
// This can be handled by your CMP based on geo-location
</script>
<?php
}
public function output_gtag_config() {
?>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr($this->measurement_id); ?>"></script>
<script>
gtag('js', new Date());
gtag('config', '<?php echo esc_attr($this->measurement_id); ?>', {
'send_page_view': true
});
<?php if ($this->ads_id): ?>
gtag('config', '<?php echo esc_attr($this->ads_id); ?>');
<?php endif; ?>
</script>
<?php
}
public function output_consent_update_handler() {
?>
<script>
// Universal consent update handler
// Works with most WordPress cookie plugins
function updateGoogleConsent(consentState) {
var consentUpdate = {
'analytics_storage': consentState.analytics ? 'granted' : 'denied',
'ad_storage': consentState.marketing ? 'granted' : 'denied',
'ad_user_data': consentState.marketing ? 'granted' : 'denied',
'ad_personalization': consentState.marketing ? 'granted' : 'denied',
'functionality_storage': consentState.functional ? 'granted' : 'denied',
'personalization_storage': consentState.functional ? 'granted' : 'denied'
};
gtag('consent', 'update', consentUpdate);
// Log for debugging
console.log('Google Consent Updated:', consentUpdate);
}
// Listen for consent events from various plugins
// Complianz
document.addEventListener('cmplz_fire_categories', function(e) {
updateGoogleConsent({
analytics: e.detail.categories.includes('statistics'),
marketing: e.detail.categories.includes('marketing'),
functional: e.detail.categories.includes('preferences')
});
});
// CookieYes
document.addEventListener('cookieyes_consent_update', function(e) {
updateGoogleConsent({
analytics: e.detail.accepted.includes('analytics'),
marketing: e.detail.accepted.includes('advertisement'),
functional: e.detail.accepted.includes('functional')
});
});
// CookieBot
window.addEventListener('CookiebotOnAccept', function() {
if (typeof Cookiebot !== 'undefined') {
updateGoogleConsent({
analytics: Cookiebot.consent.statistics,
marketing: Cookiebot.consent.marketing,
functional: Cookiebot.consent.preferences
});
}
});
// Cookie Notice
document.addEventListener('setCookieNotice', function(e) {
updateGoogleConsent({
analytics: e.detail.value === 'accept',
marketing: e.detail.value === 'accept',
functional: e.detail.value === 'accept'
});
});
// GetCookie
document.addEventListener('olc_consent_update', function(e) {
updateGoogleConsent(e.detail);
});
</script>
<?php
}
}
// Initialize
new WordPress_GCM_v2('G-XXXXXXXXXX', 'AW-XXXXXXXXXX');
WooCommerce Integration Best Practices
E-commerce sites have unique consent requirements. Here's how to handle WooCommerce tracking properly:
Conversion Tracking with Consent
<?php
// WooCommerce conversion tracking with consent awareness
class WC_Consent_Tracking {
public function __construct() {
// Track purchases
add_action('woocommerce_thankyou', [$this, 'track_purchase'], 10, 1);
// Track add to cart
add_action('woocommerce_add_to_cart', [$this, 'track_add_to_cart'], 10, 6);
// Track begin checkout
add_action('woocommerce_before_checkout_form', [$this, 'track_begin_checkout']);
}
public function track_purchase($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
// Get order data
$order_data = [
'transaction_id' => $order_id,
'value' => $order->get_total(),
'currency' => $order->get_currency(),
'tax' => $order->get_total_tax(),
'shipping' => $order->get_shipping_total(),
'items' => []
];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$order_data['items'][] = [
'item_id' => $product->get_sku() ?: $product->get_id(),
'item_name' => $item->get_name(),
'price' => $order->get_item_total($item, false, false),
'quantity' => $item->get_quantity()
];
}
?>
<script>
(function() {
var orderData = <?php echo json_encode($order_data); ?>;
// Function to fire tracking
function fireConversionTracking() {
// GA4 purchase event
gtag('event', 'purchase', orderData);
// Google Ads conversion (if marketing consent)
if (typeof gtag !== 'undefined') {
gtag('event', 'conversion', {
'send_to': 'AW-XXXXXXXXXX/CONVERSION_ID',
'value': orderData.value,
'currency': orderData.currency,
'transaction_id': orderData.transaction_id
});
}
console.log('Conversion tracked:', orderData.transaction_id);
}
// Check current consent state
function checkConsentAndFire() {
// Try different CMP APIs
// Complianz
if (typeof cmplz_has_consent === 'function' &&
cmplz_has_consent('statistics')) {
fireConversionTracking();
return;
}
// CookieYes
if (typeof getCkyConsent === 'function') {
var consent = getCkyConsent();
if (consent.analytics === 'yes') {
fireConversionTracking();
return;
}
}
// CookieBot
if (typeof Cookiebot !== 'undefined' &&
Cookiebot.consent.statistics) {
fireConversionTracking();
return;
}
// GetCookie
if (typeof olcConsent !== 'undefined' &&
olcConsent.isGranted('analytics')) {
fireConversionTracking();
return;
}
// Default: check if consent cookie exists
if (document.cookie.indexOf('analytics=true') !== -1 ||
document.cookie.indexOf('consent_analytics=1') !== -1) {
fireConversionTracking();
}
}
// Run check
if (document.readyState === 'complete') {
checkConsentAndFire();
} else {
window.addEventListener('load', checkConsentAndFire);
}
// Also listen for consent updates
document.addEventListener('cmplz_fire_categories', function(e) {
if (e.detail.categories.includes('statistics')) {
fireConversionTracking();
}
});
})();
</script>
<?php
}
public function track_add_to_cart($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
$product = wc_get_product($variation_id ?: $product_id);
if (!$product) return;
?>
<script>
(function() {
var itemData = {
item_id: '<?php echo $product->get_sku() ?: $product->get_id(); ?>',
item_name: '<?php echo esc_js($product->get_name()); ?>',
price: <?php echo $product->get_price(); ?>,
quantity: <?php echo $quantity; ?>
};
// Fire if analytics consent is granted
// Similar consent checking as purchase tracking
gtag('event', 'add_to_cart', {
currency: '<?php echo get_woocommerce_currency(); ?>',
value: itemData.price * itemData.quantity,
items: [itemData]
});
})();
</script>
<?php
}
}
new WC_Consent_Tracking();
Troubleshooting Common Issues
Issue: Scripts Still Loading Before Consent
// Check script blocking is working
add_action('wp_footer', function() {
?>
<script>
// Debug: List all loaded scripts
console.log('Loaded scripts:');
document.querySelectorAll('script[src]').forEach(function(script) {
console.log(script.src);
});
</script>
<?php
});
// Force script blocking for stubborn scripts
add_filter('script_loader_tag', function($tag, $handle) {
$blocked_handles = ['google-analytics', 'facebook-pixel', 'hotjar'];
if (in_array($handle, $blocked_handles)) {
// Change type to prevent execution
$tag = str_replace('text/javascript', 'text/plain', $tag);
$tag = str_replace('<script', '<script data-cookieconsent="marketing"', $tag);
}
return $tag;
}, 10, 2);
Issue: Consent Not Persisting
// Check cookie settings
add_action('init', function() {
// Ensure cookies are set on the correct domain
$cookie_domain = parse_url(home_url(), PHP_URL_HOST);
// Set SameSite attribute for modern browsers
if (PHP_VERSION_ID >= 70300) {
session_set_cookie_params([
'lifetime' => 365 * 24 * 60 * 60,
'path' => '/',
'domain' => $cookie_domain,
'secure' => is_ssl(),
'httponly' => true,
'samesite' => 'Lax'
]);
}
});
Issue: Google Consent Mode Not Updating
// Debug Google Consent Mode
console.log('Current consent state:');
gtag('get', 'G-XXXXXXXXXX', 'consent', function(consent) {
console.log(consent);
});
// Force consent update
function forceConsentUpdate() {
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
console.log('Consent forcefully updated');
}
Making Your Choice
Choosing the right WordPress cookie consent plugin depends on your specific needs:
- For maximum compliance and performance: GetCookies (9.2/10) offers the best Google Consent Mode v2 implementation and WooCommerce integration
- For budget-conscious site owners: Complianz (8.5/10) provides excellent value with a strong free tier
- For automatic cookie detection: CookieYes (8.3/10) has the best scanning capabilities
- For enterprise needs: CookieBot (8.0/10) offers comprehensive compliance documentation
- For simple sites: Cookie Notice (7.2/10) is the lightest and easiest option
Whichever plugin you choose, remember that Google Consent Mode v2 compliance is now mandatory for EU advertisers. Make sure your chosen solution properly implements all four consent signals: analytics_storage, ad_storage, ad_user_data, and ad_personalization.
Test your implementation thoroughly before going live. Use Google Tag Assistant to verify consent signals are firing correctly, and check your Google Analytics and Google Ads accounts for consent mode indicators.
The privacy landscape continues to evolve. Choose a plugin that's actively maintained and regularly updated to stay compliant as regulations change.