Consent
Pass the visitor's consent choices to TrackBee, so downstream platforms get the right signal.
trackbee.consent({ userData: true, personalization: false });Call this when the visitor makes a choice in your consent banner, and again on later pages if you restore their stored choice yourself.
What you pass
An object with either key, or both. Each value must be a boolean.
| Key | Means |
|---|---|
userData | The visitor agreed to their personal data being used for measurement. |
personalization | The visitor agreed to personalized advertising. |
Only the keys you pass are updated. Sending { userData: true } leaves the personalization choice as it was.
The choices are stored in the browser and stay until the visitor clears site data, so you only need to call this when something changes.
What it actually does
Consent does not stop anything in the browser
This sets a flag on the events TrackBee receives. It does not stop the script sending events, and it does not strip the email address or phone number out of a checkout_completed. Enforcement happens on TrackBee's side and in the platforms the data reaches.
If your legal position requires that nothing leaves the browser without consent, you have to gate that yourself: do not load the script, or do not call track(), until the visitor has agreed.
Wiring it to a consent banner
Translate your banner's categories to these two, whatever it calls them, and call consent() on every change.
cmp.onChange((categories) => {
trackbee.consent({
userData: categories.analytics,
personalization: categories.marketing,
});
});Call it on page load too, with the choice the banner already has stored. The visitor only answers the banner once, but the SDK starts fresh on every page.
Gating events as well
If you need the stricter behavior described above, hold the events back yourself:
function trackIfAllowed(event, data) {
if (!cmp.hasConsent('analytics')) return;
trackbee.track(event, data);
}The SDK sends nothing on its own, so there is nothing to suppress. Every event, the page view included, goes out only when you call track.
When the call is rejected
A bad argument is logged and nothing is stored. The call never throws.
| Message | Cause |
|---|---|
the object passed to 'setConsent' must be an object that is never null or undefined. Received: ... | You passed null, undefined or something that is not an object. |
the object passed to 'setConsent' must contain either 'userData' or 'personalization' keys. Received: ... | The object has neither key. |
'userData' must be a boolean. Received: ... | You passed a string like 'granted', or a number. |
'personalization' must be a boolean. Received: ... | Same. |
These messages name setConsent, which is the internal name. The method you call is trackbee.consent.