-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
-
I'm trying to start/stop sending events when user consents. There is a privacy banner on the page (using iubenda) and it basically takes a callback in its config like so:
_iub.csConfiguration = { // ... callback: { onPreferenceExpressed: function () { if (_iub.cs.api.cs.consent.purposes["4"]) { console.log("user consented to monitoring"); // TODO: activate Sentry } if (!_iub.cs.api.cs.consent.purposes["4"]) { console.log("user revoked consent of monitoring"); // TODO: deactivate Sentry } }, }, };
I'm using the loader script and sentryOnLoad before the script. I've gotten this far:
window.sentryOnLoad = function () { Sentry.init({ release: "", enabled: false, }); };
This successfully stops Sentry from sending events however I don't understand how I could do enabled: true after init. Or even if this is the right way of doing it?
Any guidance is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
you could either add an event processor (recommended) or have a condition in beforeSend
and beforeSendTransaction
like so:
Sentry.addEventProcessor((event) => { if (!userHasGivenConsent) { return null; } return event; })
That way, all events are dropped unless the user has given consent.
Beta Was this translation helpful? Give feedback.
All reactions
-
This suggestion looks nice! @lforst
If I wanted this to only target client events, would it be appropriate to handle that logic inside of the eventProcessor? For example like this:
Sentry.addEventProcessor((event) => {
if (!userHasGivenConsent && typeof window !== 'undefined') {
return null;
}
return event;
})
Or is there a better way of splitting this logic?
Beta Was this translation helpful? Give feedback.
All reactions
-
yup that works
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1