配置
了解用户反馈的通用配置字段。
由于 feedbackIntegration
是面向用户的集成,我们提供了两种对包大小有影响的加载策略。
对于大多数用户,我们建议在 Sentry.init
调用中使用 feedbackIntegration
。这将以良好的默认配置设置用户反馈,匹配您的环境。
本页面上的所有代码示例都默认使用 feedbackIntegration
,因为它无论您选择的是 CDN 还是 NPM 安装方法都可用。然而,feedbackIntegration
的实现对于这两种安装方法是不同的。对于 NPM 用户,feedbackIntegration
是 feedbackSyncIntegration
的别名。对于 CDN 用户,feedbackIntegration
是 feedbackAsyncIntegration
的别名。
如果您通过 NPM 安装了 SDK,默认使用此加载策略。如果通过 CDN 安装 SDK,则无法使用此策略。
此集成包含渲染“发送反馈”按钮以及点击按钮时触发的表单所需的所有代码。选择此加载策略意味着接受应用程序中最大的初始包大小。这样做的好处是,当用户与反馈小部件交互时,可以确保小部件能够打开,但无论如何,发送反馈消息都需要网络连接。
如果您通过 CDN 安装了 SDK,默认使用此加载策略。如果您使用 NPM 安装,仍然可以通过在 Sentry.init
调用中添加此集成来选择使用此加载策略。
此集成仅包含页面加载时在屏幕上显示“发送反馈”按钮所需的最小代码量。当用户点击该按钮时,集成将从 https://browser.sentry-cdn.com
异步加载内部集成以显示表单并允许用户输入反馈消息。这样做的好处是包大小最小。缺点是,如果用户有广告拦截器,异步加载可能会失败。
对于 CDN 用户,feedbackIntegration
是 feedbackAsyncIntegration
的别名。
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [
// Use the default strategy, an alias for `feedbackAsyncIntegration`
Sentry.feedbackIntegration({
// Additional SDK configuration goes in here, for example:
colorScheme: "system",
}),
],
});
对于 NPM 用户,feedbackIntegration
是 feedbackSyncIntegration
的别名。
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [
// Use the default strategy, an alias for `feedbackSyncIntegration`
Sentry.feedbackIntegration({
// Additional SDK configuration goes in here, for example:
colorScheme: "system",
}),
],
});
您可以根据组织的需求自定义崩溃报告模态框,例如用于本地化。所有选项都可以通过 Sentry.showReportDialog
调用传递。
参数 | 默认值 |
---|---|
eventId | 手动设置事件的 ID。 |
dsn | 手动设置要报告到的 DSN。 |
user | 手动设置用户数据 [包含以下键的对象]。 |
user.email | 用户的电子邮件地址。 |
user.name | 用户的姓名。 |
lang | [自动] – (覆盖 Sentry 的语言代码。) |
title | 看起来我们遇到了一些问题。 |
subtitle | 我们的团队已收到通知。 |
subtitle2 | 如果您愿意帮助,请在下方告诉我们发生了什么。– (在小屏幕分辨率下不可见。) |
labelName | 姓名 |
labelEmail | 电子邮件 |
labelComments | 发生了什么? |
labelClose | 关闭 |
labelSubmit | 提交 |
errorGeneric | 在提交您的报告时发生了一个未知错误。请重试。 |
errorFormEntry | 某些字段无效。请修正错误并重试。 |
successMessage | 您的反馈已发送。感谢! |
onLoad | n/a - (当小部件打开时调用的可选回调。) |
onClose | n/a - (当小部件关闭时调用的可选回调。) |
可选回调 onLoad
在用户看到小部件时被调用。您可以使用此回调来运行自定义逻辑,例如记录分析事件:
Sentry.showReportDialog({
// ...
onLoad() {
// Log an event to amplitude when the report dialog opens
amplitude.logEvent("report_dialog_seen");
},
});
可选回调 onClose
在用户关闭小部件时被调用。您可以使用此回调来运行自定义逻辑,例如重新加载页面:
需要 JS SDK 版本 v7.82.0 或更高。
Sentry.showReportDialog({
// ...
onClose() {
// Refresh the page after the user closes the report dialog
location.reload();
},
});