-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(feedback): Example docs on
sendFeedback
(#9560)
- Loading branch information
Showing
1 changed file
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,7 @@ import {BrowserClient, getCurrentHub} from '@sentry/react'; | |
import {Feedback} from '@sentry-internal/feedback'; | ||
|
||
function MyFeedbackButton() { | ||
const client = hub && getCurrentHub().getClient<BrowserClient>(); | ||
const client = getCurrentHub().getClient<BrowserClient>(); | ||
const feedback = client?.getIntegration(Feedback); | ||
|
||
// Don't render custom feedback button if Feedback integration not installed | ||
|
@@ -230,22 +230,40 @@ function MyFeedbackButton() { | |
|
||
### Bring Your Own Widget | ||
|
||
You can also bring your own widget and UI and simply pass a feedback object to the `sendFeedback()` function. | ||
You can also bring your own widget and UI and simply pass a feedback object to the `sendFeedback()` function. The `sendFeedback` function accepts two parameters: | ||
* a feedback object with a required `message` property, and additionally, optional `name` and `email` properties | ||
* an options object | ||
|
||
```javascript | ||
sendFeedback({ | ||
name: 'Jane Doe', // optional | ||
email: '[email protected]', // optional | ||
message: 'This is an example feedback', // required | ||
}, { | ||
includeReplay: true, // optional | ||
}) | ||
``` | ||
|
||
Here is a simple example | ||
|
||
```html | ||
<form id="my-feedback-form"> | ||
<input name="name" /> | ||
<input name="email" /> | ||
<textarea name="message" placeholder="What's the issue?" /> | ||
</form> | ||
``` | ||
|
||
```javascript | ||
import {BrowserClient, getCurrentHub} from '@sentry/react'; | ||
import {Feedback} from '@sentry-internal/feedback'; | ||
|
||
<script> | ||
document.getElementById('my-feedback-form').addEventListener('submit', (event) => { | ||
const feedback = getCurrentHub().getClient<BrowserClient>()?.getIntegration(Feedback); | ||
const formData = new FormData(event.currentTarget); | ||
Feedback.sendFeedback(formData); | ||
feedback.sendFeedback(formData); | ||
event.preventDefault(); | ||
}); | ||
</script> | ||
``` | ||
## Alerting on User Feedback Reports | ||
|