Set Up User Feedback

Learn more about collecting user feedback when an event occurs. Sentry pairs the feedback with the original event, giving you additional insight into issues.

When a user experiences an error, Sentry provides the ability to collect additional feedback. You can collect feedback according to the method supported by the SDK.

The user feedback API allows you to collect user feedback while utilizing your own UI. Sentry pairs the feedback with the original event, giving you additional insight into issues. Sentry needs the associatedEventId to be able to associate the user feedback to the corresponding event. There are several ways to get the associatedEventId:

  • use beforeSend
  • use the return value of any method capturing an event.
  • use Sentry.lastEventId to get the ID of the last event sent.
Copied
// Option 1: Retrieving SentryId from beforeSend
SentryId sentryId = SentryId.empty();

await SentryFlutter.init((options) {
  options.beforeSend = (event, hint) {
    sentryId = event.eventId;
    return event;
  };
});

// Option 2: Retrieving SentryId from the method capturing the event
SentryId sentryId = Sentry.captureMessage("My message");

// Option 3: Retrieving SentryId from the beforeSend callback
SentryId sentryId = Sentry.lastEventId;

final feedback = SentryFeedback(
    message: 'Hello World!',
    contactEmail: 'foo@bar.org',
    name: 'John Doe',
    associatedEventId: sentryId,
);

Sentry.captureFeedback(feedback);

Use the SentryFeedbackWidget to let users send feedback data to Sentry.

The widget requests and collects the user's name, email address, and a description of what occurred. When an event identifier is provided, Sentry pairs the feedback with the original event, giving you additional insights into issues.

Users can also take a screenshot of their app's UI. Additionally, you can provide a screenshot in code. Learn more about how to enable screenshots in our Screenshots documentation.

The image below provides an example of the widget, though yours may differ depending on your customization:

SentryFeedbackWidget

One possible use for the SentryFeedbackWidget is to listen for specific Sentry events in the beforeSend callback and show the widget to users. Users also can take a screenshot from their app's UI if the SentryWidget is wrapped around the main app widget.

Copied
// The example uses the `NavigatorState` to present the widget. Adapt as needed to your navigation stack.
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

...

Future<void> main() async {
  await SentryFlutter.init(
    (options) {
      options.navigatorKey = navigatorKey; // Needed so the widget can be presented.
      options.beforeSend = (event, hint) async {
        // Filter here what kind of events you want users to give you feedback.
        
        final screenshot = await SentryFlutter.captureScreenshot();

        final context = navigatorKey.currentContext;
        if (context != null && context.mounted) {
          SentryFeedbackWidget.show(
            context,
            associatedEventId: event.eventId,
            screenshot: screenshot,
          );
        }
      };
    },
    appRunner: () => runApp(
      SentryWidget(
        child: MyApp(),
      ),
    ),
  );
}

You can customize the SentryFeedbackWidget to your needs by modifying the SentryFeedbackOptions class, which is provided by the SentryFlutter.init options.

Copied
SentryFlutter.init((options) {
  options.feedback.title = 'Report a Bug';
  options.feedback.isNameRequired = false;
  options.feedback.showName = true;
  options.feedback.isEmailRequired = false;
  options.feedback.showEmail = true;
  options.feedback.useSentryUser = true;
  options.feedback.showBranding = true;
});

The following table lists all the options you can customize to change behavior of the SentryFeedbackWidget.

OptionTypeDefaultDescription
titleString'Report a Bug'The title of the feedback form.
isNameRequiredBoolfalseRequires the name field on the feedback form to be filled in.
showNameBooltrueDisplays the name field on the feedback form. Ignored if isNameRequired is true.
isEmailRequiredBoolfalseRequires the email field on the feedback form to be filled in.
showEmailBooltrueDisplays the email field on the feedback form. Ignored if isEmailRequired is true.
useSentryUserBooltrueSets the email and name fields to the corresponding Sentry SDK user fields that were called with SentrySDK.setUser.
showBrandingBooltrueDisplays the Sentry logo inside the form.
showCaptureScreenshotBooltrueDisplays the capture screenshot button on the feedback form.

You can also provide differnt labels or localization for the feedback widget:

OptionTypeDefaultDescription
formTitleString'Report a Bug'The title of the feedback form.
messageLabelString'Description'The label of the feedback description input field.
messagePlaceholderString'What's the bug? What did you expect?'The placeholder in the feedback description input field.
isRequiredLabelString' (Required)'The text to attach to the title label for a required field.
successMessageTextString'Thank you for your report!'The message displayed after a successful feedback submission.
nameLabelString'Name'The label next to the name input field.
namePlaceholderString'Your Name'The placeholder in the name input field.
emailLabelString'Email'The label next to the email input field.
emailPlaceholderString'your.email@example.org'The placeholder in the email input field.
submitButtonLabelString'Send Bug Report'The label of the submit button.
cancelButtonLabelString'Cancel'The label of the cancel button.
validationErrorLabelString'Can't be empty'The label of the validation error message.
captureScreenshotButtonLabelString'Capture a screenshot'The label of the capture screenshot button.
removeScreenshotButtonLabelString'Remove screenshot'The label of the remove screenshot button.
takeScreenshotButtonLabelString'Take Screenshot'The label of the take screenshot button shown outside of the feedback widget.
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").