Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to send events when user consents and stop when user revokes consent? #12148

Unanswered
okabak123 asked this question in Q&A
Discussion options

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!

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

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.

You must be logged in to vote
2 replies
Comment options

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?

Comment options

yup that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /