Cookie Consent Integration
Overview
Section titled “Overview”The Barion Pixel requires explicit user consent before collecting marketing data (GDPR compliance). The plugin must call bp('consent', 'grantConsent') when the user accepts, and bp('consent', 'rejectConsent') when the user declines. Both events are mandatory per Barion’s requirements.
The base pixel script always loads for fraud prevention, but no marketing data is collected until consent is explicitly granted or rejected.
Important: Your cookie banner must offer both an accept and a reject option. A “cookie wall” (accept-only) is not GDPR compliant since 2020 and will be rejected by Barion.
The plugin supports three tiers of consent integration, checked in order:
- WP Consent API (recommended) — universal, works with all major cookie plugins
- Cookie Law Info (fallback) — direct integration for sites using CookieYes/Cookie Law Info
- Manual — for custom consent managers or edge cases
Tier 1: WP Consent API (Recommended)
Section titled “Tier 1: WP Consent API (Recommended)”The WP Consent API is a WordPress standard for consent communication. It’s supported by all major cookie consent plugins.
How it works
Section titled “How it works”The plugin checks for the wp_has_consent() JavaScript function at runtime. If the WP Consent API is available:
- On page load, checks if
marketingconsent is granted or rejected - Calls
bp('consent', 'grantConsent')if marketing consent is granted - Calls
bp('consent', 'rejectConsent')if marketing consent is not granted - Listens for the
wp_listen_for_consent_changeevent for real-time consent updates — grants or rejects accordingly
Supported cookie plugins
Section titled “Supported cookie plugins”Any plugin that implements the WP Consent API will work automatically:
| Plugin | Active installs | Notes |
|---|---|---|
| CookieYes | 1.5M+ | WP Consent API built-in |
| Complianz | 1M+ | Co-creator of WP Consent API |
| Cookie Notice by dFactory | 1M+ | WP Consent API compatible |
| GDPR Cookie Compliance (Moove) | 300K+ | WP Consent API compatible |
| Real Cookie Banner | 100K+ | WP Consent API compatible |
- Install and activate the WP Consent API plugin
- Install and configure your preferred cookie consent plugin (see table above)
- Install and configure Advanced Pixel for Barion
- No additional configuration needed — consent is handled automatically
Consent category
Section titled “Consent category”The Barion Pixel is registered under the marketing consent category in the WP Consent API. This is the standard category for tracking pixels used for retargeting and analytics.
Tier 2: Cookie Law Info (Fallback)
Section titled “Tier 2: Cookie Law Info (Fallback)”If the WP Consent API is not available, the plugin falls back to direct integration with the Cookie Law Info / CookieYes plugin.
How it works
Section titled “How it works”- Checks for the
CLIJavaScript global object - If cookies are already accepted (returning visitor), grants consent immediately
- If cookies are not accepted, rejects consent immediately
- Listens for the
cli_user_preference_setevent when the user interacts with the cookie banner - Grants or rejects based on the
cookielawinfo-checkbox-necessarycookie value
No configuration needed. Install both plugins and the integration works automatically.
Tier 3: Manual Integration
Section titled “Tier 3: Manual Integration”For custom consent managers or environments where neither WP Consent API nor Cookie Law Info is available.
Method 1: JavaScript functions (recommended)
Section titled “Method 1: JavaScript functions (recommended)”// When user accepts marketing cookiesfunction onMarketingConsentGranted() { if (typeof window.wcBarionGrantConsent === 'function') { window.wcBarionGrantConsent(); }}
// When user rejects marketing cookiesfunction onMarketingConsentRejected() { if (typeof window.wcBarionRejectConsent === 'function') { window.wcBarionRejectConsent(); }}Method 2: Custom DOM events
Section titled “Method 2: Custom DOM events”// Grant consentdocument.dispatchEvent(new Event('wcBarionGrantConsent'));
// Reject consentdocument.dispatchEvent(new Event('wcBarionRejectConsent'));Method 3: WordPress action hook
Section titled “Method 3: WordPress action hook”// In your consent manager plugin or themeadd_action('wc_barion_pixel_footer_scripts', 'my_barion_consent_handler');
function my_barion_consent_handler() { ?> <script> // Your custom consent logic here </script> <?php}Examples for specific consent managers
Section titled “Examples for specific consent managers”Cookiebot:
window.addEventListener('CookiebotOnAccept', function() { if (Cookiebot.consent.marketing) { window.wcBarionGrantConsent(); } else { window.wcBarionRejectConsent(); }});window.addEventListener('CookiebotOnDecline', function() { window.wcBarionRejectConsent();});OneTrust:
function OptanonWrapper() { if (OnetrustActiveGroups.includes('C0004')) { window.wcBarionGrantConsent(); } else { window.wcBarionRejectConsent(); }}How consent affects the pixel
Section titled “How consent affects the pixel”| State | Base pixel (bp.js) | pageView | Marketing data collection |
|---|---|---|---|
| Before any consent action | Loaded | Fires (fraud prevention) | No data collected |
After grantConsent |
Loaded | Fires | Full data collection enabled |
After rejectConsent |
Loaded | Fires (fraud prevention) | No marketing data collected |
The base pixel always loads for Barion’s fraud prevention. The grantConsent / rejectConsent calls control whether marketing data is collected.
Testing
Section titled “Testing”- Enable Debug Mode in Settings > Barion Pixel
- Open the browser console (F12)
- Look for consent-related log messages:
[Barion Pixel] Consent auto-granted via WP Consent API— Tier 1, user accepted[Barion Pixel] Consent auto-rejected via WP Consent API— Tier 1, user declined[Barion Pixel] Consent auto-granted via Cookie Law Info— Tier 2, user accepted[Barion Pixel] Consent auto-rejected via Cookie Law Info— Tier 2, user declined[Barion Pixel] No consent manager detected...— Tier 3 (manual mode)[Barion Pixel] Consent granted (grantConsent)— consent was granted (any tier)[Barion Pixel] Consent rejected (rejectConsent)— consent was rejected (any tier)
- Test both accept and reject flows on your cookie banner
- The consent functions are safe to call multiple times (idempotent)