getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
766 stars 239 forks source link

GDPR Cookie / Consent Solution #2310

Closed FantaMagier closed 2 months ago

FantaMagier commented 2 months ago

Problem Statement

I would like to get the user consent to send his crash reports. As soon as the user has given me the ok, I can send the crash reports and co. to Sentry.

Solution Brainstorm

Is there a function to activate or deactivate tracking at any time?

Are you willing to submit a PR?

None

buenaflor commented 2 months ago

Using beforeSend will allow you to do this. This code snippet will prevent any data from being sent before the consent:

await SentryFlutter.init((options) {
  options.beforeSend = (event, hint) async {
    if (consentGiven) {
        return event;
    }
    return null;
  };
});
FantaMagier commented 2 months ago

Thanks!