PixelsClearedPixelsCleared

Manual Consent API

How to programmatically grant or revoke consent using the PixelsCleared JavaScript API.


When to Use the Manual API

The PixelsCleared widget auto-detects consent from most popular consent management platforms (see Supported Consent Providers). Use the manual API when:

  • You built a custom consent banner instead of using a CMP like Cookiebot or OneTrust
  • Your site uses server-side rendering and consent state is already known when the page loads
  • Your CMP is not in the supported list and does not implement IAB TCF v2
  • You want to test event flow without waiting for a consent banner interaction

Granting Consent

Call this after the visitor has accepted your consent banner:


window.PixelsCleared('consent', true);

After this call, the widget begins collecting and sending events to the gateway. Any page views, button clicks, or custom events that fire after the call will be sent with consent attached.

Revoking Consent

Call this when a visitor rejects your consent banner or withdraws consent:


window.PixelsCleared('consent', false);

After this call, the widget stops sending events immediately and clears its local state. Events that were already sent to the gateway before the revocation are not affected (they carried valid consent at the time they were sent).

Granting With Categories

You can pass granular consent categories instead of a boolean:


window.PixelsCleared('consent', {
  marketing: true,
  analytics: true,
  functional: false
});

When categories are provided, the widget sends this structure as the _consent_meta.categories object with each event. This is how you control which destination-specific consent signals are applied (for example, Meta LDU vs. normal forwarding).

If you pass true without categories, all categories default to true.

The Consent Meta Object

Every event sent after consent is granted includes a _consent_meta object:


{
  "granted": true,
  "source": "manual",
  "categories": {
    "marketing": true,
    "analytics": true,
    "functional": true
  }
}

| Field | Type | Description |

|---|---|---|

| granted | boolean | Whether consent was granted |

| source | string | "manual" for API calls, or the detected CMP name ("cookiebot", "onetrust", etc.) |

| categories | object | Breakdown by consent type: marketing, analytics, functional |

The source field is always "manual" when you use the API. This is recorded in the gateway audit log and visible in the consent source breakdown on the dashboard.

Integration Examples

Custom Consent Banner


document.getElementById('accept-btn').addEventListener('click', function () {
  window.PixelsCleared('consent', {
    marketing: true,
    analytics: true,
    functional: true
  });
});

document.getElementById('reject-btn').addEventListener('click', function () {
  window.PixelsCleared('consent', false);
});

Server-Side Rendered Page (Consent Already Known)

If you render consent state into the page from your backend:


<script>
  // Consent state injected by your server
  var hasConsent = {{ user.hasConsented }};
  if (hasConsent) {
    window.PixelsCleared('consent', true);
  }
</script>

Partial Consent (Analytics Only)


// Visitor accepted analytics but not marketing
window.PixelsCleared('consent', {
  marketing: false,
  analytics: true,
  functional: true
});

With this consent state, Meta CAPI events will be sent with opt_out: true, while GA4 events will have consent.ad_user_data: "denied" but analytics data will flow normally.

Important Notes

  • Call the API after the widget loads. The window.PixelsCleared function is only available after pixelscleared.js has loaded. If you call it before the script loads, the call is ignored.
  • Consent is per-event, not per-session. The gateway evaluates the _consent_meta attached to each individual event. If consent is revoked mid-session, only events sent after revocation are affected.
  • Manual consent overrides auto-detection. If you call the manual API, the widget stops polling for CMP cookies and uses your manual signal instead.

Back to Help Center