Skip to content

feat(js): Add docs for new captureFeedback method #10172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/platforms/javascript/common/user-feedback/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ description: "Learn how to enable User Feedback in your app."
sidebar_order: 6000
---

The User Feedback feature allows you to collect user feedback from anywhere inside your application, without requiring an error event to occur. This requires a minimum SDK version of [7.85.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.85.0). The [Crash-Report Modal](#crash-report-modal) feature still exists to handle user feedback associated with an error event.
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. The [Crash-Report Modal](#crash-report-modal) feature, on the other hand, lets you prompt for user feedback when an error event occurs.

Note that 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.

<PlatformSection notSupported={["javascript.node", "javascript.aws-lambda", "javascript.azure-functions", "javascript.connect", "javascript.express", "javascript.fastify", "javascript.gcp-functions", "javascript.hapi", "javascript.koa", "javascript.nestjs"]}>

Expand Down
37 changes: 18 additions & 19 deletions platform-includes/user-feedback/sdk-api-example/javascript.mdx
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
_Requires JS SDK version v7.47.0 or higher._

```javascript
import * as Sentry from "@sentry/browser";

const eventId = Sentry.captureMessage("User Feedback");
// OR: const eventId = Sentry.lastEventId();

const userFeedback = {
event_id: eventId,
name: "John Doe",
email: "john@doe.com",
comments: "I really like your App, thanks!",
message: "I really like your App, thanks!",
associatedEventId: eventId,
};
Sentry.captureUserFeedback(userFeedback);
Sentry.captureFeedback(userFeedback);
```

You could also collect feedback and send it when an error occurs via the SDK's `beforeSend` callback:

<SignInNote />
You can also attach further data to the feedback event by passing a hint as a second argument. This is similar to other `capture` methods:

```javascript
Sentry.init({
dsn: '___PUBLIC_DSN___',
beforeSend: event => {
const userFeedback = collectYourUserFeedback();
const feedback = {
...userFeedback,
event_id: event.event_id,
}
Sentry.captureUserFeedback(feedback);
return event;
Sentry.captureFeedback(
{ message: "I really like your App, thanks!" },
{
captureContext: {
tags: { key: "value" },
extra: { key: "value" },
},
attachments: [
{
filename: "screenshot.png",
data: "base64-encoded-image",
},
],
}
})
);
```

This file was deleted.