Set Up User Feedback
Learn how to enable User Feedback in your Cocoa app.
The User Feedback feature allows you to collect user feedback from anywhere inside your application at any time, without needing an error event to occur first.
If you're using a self-hosted Sentry instance, you'll need to be on version 24.4.2 or higher in order to use the full functionality of the User Feedback feature. Lower versions may have limited functionality.
The User Feedback widget allows users to submit feedback from anywhere inside your application.
Ensure that your project is set up with Sentry and that you have added the Sentry Cocoa SDK to your project.
- Install the Sentry Cocoa SDK using CocoaPods, Carthage, or Swift Package Manager.
- Ensure you are using version 8.46.0 or above of the SDK to access the latest features.
To start using the User Feedback widget in your Cocoa application, provide a feedback configuration in your SentryOptions
when starting the SDK:
SentrySDK.start { options in
options.configureUserFeedback = { config in
config.onSubmitSuccess = { data in
print("Feedback submitted successfully: \(data)")
}
config.onSubmitError = { error in
print("Failed to submit feedback: \(error)")
}
}
}
This setup will insert the widget into your app's view hierarchy. By default, it appears in the bottom trailing corner of the screen, but you can fully customize its appearance and behavior.
SwiftUI apps cannot currently use automatic injection of the widget upon SDK start. Several options exist to display the feedback form:
Place a UIButton
somewhere in your app, then provide the reference to the feedback configuration in the options provided on SDK start:
import Sentry
import SwiftUI
import UIKit
@main
struct SwiftUIApp: App {
// a button displayed somewhere in your app
public let feedbackButton = {
let button = UIButton(type: .custom)
button.setTitle("BYOB Feedback", for: .normal)
return button
}()
init() {
// start the SentrySDK as usual, as early as possible in your app's launch sequence
SentrySDK.start { options in
options.configureFeedback { config in
config.customButton = feedbackButton
}
// your other SDK options
}
}
}
You must set up a UIApplicationDelegateAdapter
, connect a UIScene
to your app, and manually call SentrySDK.feedback.showWidget()
:
import Sentry
import SwiftUI
@main
struct SwiftUIApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
init() {
// start the SentrySDK as usual, as early as possible in your app's launch sequence
SentrySDK.start { options in
// configure feedback and any other SDK options
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class MyAppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
let configuration = UISceneConfiguration(
name: nil,
sessionRole: connectingSceneSession.role)
if connectingSceneSession.role == .windowApplication {
configuration.delegateClass = MySceneDelegate.self
}
return configuration
}
}
class MySceneDelegate: NSObject, UIWindowSceneDelegate, ObservableObject {
var initializedSentry = false
func sceneDidBecomeActive(_ scene: UIScene) {
guard !initializedSentry else { return }
// display the feedback widget
SentrySDK.feedback.showWidget()
initializedSentry = true
}
}
The User Feedback widget integrates seamlessly with Session Replay. When the widget is opened, the Replay SDK buffers up to 30 seconds of the user's session. If feedback is submitted, this replay is sent along with the feedback, allowing you to view both the feedback and the user's actions leading up to the feedback submission.
The User Feedback API allows you to collect user feedback while using your own UI components. You can submit feedback directly using the SentrySDK.capture(feedback:)
method:
SentrySDK.capture(feedback: .init(
message: "I encountered a bug while using the app.",
name: "John Doe",
email: "john.doe@example.com",
source: .custom,
screenshot: somePngImageData // optional
))
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").