设置用户反馈

了解更多关于在事件发生时收集用户反馈。Sentry 将反馈与原始事件配对,为您提供更多问题的洞察。

当用户遇到错误时,Sentry 提供了收集额外反馈的能力。您可以根据 SDK 支持的方法收集反馈。

我们的嵌入式、基于 JavaScript 的崩溃报告模态框在您通常会在网站上渲染一个简单的错误页面(经典的 500.html)时非常有用。

为了收集反馈,崩溃报告模态框会请求并收集用户的姓名、电子邮件地址以及对所发生情况的描述。当提供反馈时,Sentry 会将反馈与原始事件配对,为您提供更多关于问题的洞察。

下面的截图提供了一个崩溃报告模态框的示例,尽管您的模态框可能会因自定义而有所不同:

An example of a Crash-Report modal with text boxes for user name, email, and additional details about the break.

模态框使用您的公共 DSN 进行身份验证,然后传递在后端生成的事件 ID。

This function php returns the last eventId:

Copied
\Sentry\SentrySdk::getCurrentHub()->getLastEventId();

Make sure you've got the JavaScript SDK available:

Copied
<script
  src="https://browser.sentry-cdn.com/8.54.0/bundle.min.js"
  integrity="sha384-OOkJGcfpcHOW2qdROjcfMtqqMTrDnSBag7fGypKUDA4WxyB6mmS5cMzY9YBGcBvF"
  crossorigin="anonymous"
></script>

Depending on how you render your templates, the example would be in a simple php file:

Copied
<?php if (\Sentry\SentrySdk::getCurrentHub()->getLastEventId()) { ?>
<script>
  Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0" });
  Sentry.showReportDialog({
    eventId:
      "<?php echo \Sentry\SentrySdk::getCurrentHub()->getLastEventId(); ?>",
  });
</script>
<?php } ?>