Skip to main content

Set up consent mode for the Insights pixel

Wait for visitor consent before the Insights pixel tracks anything — built for GDPR and ePrivacy compliance

Written by Bidisha Sinha

If your site shows a cookie banner, you can turn on consent mode for the Insights pixel so it stays completely silent until a visitor accepts cookies. You don't lose any tracking accuracy by doing this — once consent is granted, the pixel sends everything that happened while it was waiting.

Consent mode is optional: if you don't turn it on, the pixel behaves exactly as it always has.

How consent mode works

Mode

What it does

Who it's for

Default

Starts tracking as soon as the page loads.

Sites with no cookie banner, or where tracking doesn't need to wait for consent.

Consent mode

Stays silent until the visitor accepts cookies.

Sites with a cookie banner (GDPR / ePrivacy).

Turn on consent mode

  1. Add the Insights script tag to your site, if you haven't already:

<script src="https://cdn.uniqode.com/insights/production/v1/latest/sdk.js"></script>

2. Initialize the pixel with requireConsent: true:

<script>   window.insights.init({ clientKey: 'your-client-key', requireConsent: true }); </script>

3. Tell the pixel the visitor's decision by calling window.insights.grantConsent() when they accept cookies, and window.insights.revokeConsent() when they decline or withdraw consent. Wire these calls to your cookie consent management platform (CMP) so they fire automatically — on page load and whenever the visitor's choice changes.

Note: grantConsent() and revokeConsent() only do something when requireConsent: true is set. In default mode they're ignored, so leftover calls to them can't accidentally switch tracking off.

Generic integration pattern

Any CMP works the same way: listen for the event your CMP fires when consent changes, check whether the visitor has accepted analytics/statistics cookies, then call grantConsent() or revokeConsent() accordingly.

<script>   window.insights.init({ clientKey: 'your-client-key', requireConsent: true });    function syncInsightsConsent(analyticsConsentGiven) {     if (analyticsConsentGiven) {       window.insights.grantConsent();     } else {       window.insights.revokeConsent();     }   }    // Call syncInsightsConsent(true/false) from your CMP's own callback or   // event listener — both on initial page load and whenever the visitor   // changes their choice. </script>

Cookiebot

Cookiebot fires CookiebotOnAccept and CookiebotOnDecline events on window, and exposes the visitor's choice per category on Cookiebot.consent:

<script src="https://cdn.uniqode.com/insights/production/v1/latest/sdk.js"></script> <script>   window.insights.init({ clientKey: 'your-client-key', requireConsent: true });    window.addEventListener('CookiebotOnAccept', function () {     if (Cookiebot.consent.statistics) {       window.insights.grantConsent();     } else {       window.insights.revokeConsent();     }   });    window.addEventListener('CookiebotOnDecline', function () {     window.insights.revokeConsent();   }); </script>

OneTrust

OneTrust exposes the visitor's active consent categories through the OnetrustActiveGroups string, and updates it via the OptanonWrapper callback and the OneTrustGroupsUpdated event:

<script>   window.insights.init({ clientKey: 'your-client-key', requireConsent: true });    function OptanonWrapper() {     // Assuming C0002 is the Analytics cookie category     if (OnetrustActiveGroups.indexOf('C0002') !== -1) {       window.insights.grantConsent();     } else {       window.insights.revokeConsent();     }   } </script>

What happens after you turn it on

  1. Page loads, banner shows. The pixel is silent — it sets no cookie and sends no data. Anything the visitor does while waiting is held in memory only.

  2. Visitor accepts. The pixel starts tracking and sends everything that was held while waiting, so you don't lose those first few seconds.

  3. Visitor declines or withdraws. The held activity is discarded, the pixel stays silent, and any cookie or storage it had already set is deleted from the visitor's device.

Frequently asked questions (FAQs)

  1. What data does the pixel collect?

    By default, no personally identifiable information. It collects a pseudonymous device ID, which page was viewed, what was clicked, scroll depth, screen size, and timestamps. A userId is only attached if your integration explicitly sets one.

  2. What happens to returning visitors?

    Your CMP (Cookiebot, OneTrust, or your own) remembers the visitor's choice and re-applies it on each page load — the pixel itself doesn't store a separate consent record.

  3. What if a visitor changes their mind?

    If they later accept after declining, tracking resumes once the page reloads. If they withdraw consent, tracking stops immediately and their existing cookie/storage is deleted from their device.

  4. What's available today vs. planned?

Capability

Status

Wait for consent before tracking

Available

Delete cookie/storage on withdrawal

Available

Works with any CMP (Cookiebot, OneTrust, custom banners)

Available

Server-side data deletion

Planned — for now, email support@uniqode.com with the device ID or user ID

Automatic data retention/expiry

Planned

Separate consent categories (analytics vs. marketing)

Not yet — consent is all-or-nothing; your CMP decides which category triggers it

Tips for best results

  • Test on a staging page first

    Confirm your CMP's accept/decline actions actually call grantConsent() / revokeConsent() before rolling this out on your live site.

  • Only set requireConsent: true if you have a cookie banner

    Turning it on without wiring up grantConsent()/revokeConsent() means the pixel will stay silent forever, since nothing tells it consent was given.

Did this answer your question?