使用 LogRocket

有关安装和配置 LogRocket 以进行会话重放和错误监控的指南。


LogRocket 会记录用户会话并在用户使用你的应用时识别错误。你可以按更新 ID 筛选会话,也可以在 EAS 控制面板中连接你的 LogRocket 账户,以快速访问应用的会话数据。

安装和配置 LogRocket

🌐 Install and configure LogRocket

你可以使用以下命令安装 LogRocket SDK:

🌐 You can install the LogRocket SDK with the following command:

Terminal
npx expo install @logrocket/react-native expo-build-properties

然后,在你的 应用配置 中,包含 LogRocket 配置插件:

🌐 Then, in your app config, include the LogRocket config plugin:

app.json
{ "plugins": [ [ "expo-build-properties", { "android": { "minSdkVersion": 25 } } ], "@logrocket/react-native" ] }

最后,在你的应用中的顶层文件中初始化 LogRocket,比如 app/_layout.tsx:

🌐 Finally, initialize LogRocket in your app in a top-level file, like app/_layout.tsx:

app/_layout.tsx
import { useEffect } from 'react'; import * as Updates from 'expo-updates'; import LogRocket from '@logrocket/react-native'; const App = () => { useEffect(() => { LogRocket.init('<App ID>', { updateId: Updates.isEmbeddedLaunch ? null : Updates.updateId, expoChannel: Updates.channel, }); }, []); };

在上面的代码中,将 <App ID> 替换为你的 LogRocket 应用 ID

🌐 In the code above, replace <App ID> with your LogRocket App ID.

在 EAS 仪表板上连接 LogRocket

🌐 Connecting LogRocket on the EAS dashboard

你可以在 Expo 的仪表板上将你的 LogRocket 账户和项目链接到你的 Expo 账户和项目,以便你可以在部署和更新仪表板中查看应用的最后几个会话。

🌐 You can link your LogRocket account and project to your Expo account and project on Expo's dashboard, so that you can see the last few sessions from your app in the deployments and updates dashboards.

进入你的 账户设置 > 概览 > 连接,然后点击 连接 以通过 LogRocket 进行身份验证:

🌐 Go to your Account settings > Overview > Connections and click Connect to authenticate with LogRocket:

然后,进入你的项目,在 项目设置 > 常规 下点击 连接,将你的 LogRocket 项目与你在 Expo 上的项目关联起来:

🌐 Then, go to your project, under Project settings > General and click Connect to link your LogRocket project with your project on Expo:

然后,你会在 EAS 仪表板中的原生部署和更新仪表板中看到 在 LogRocket 查看 按钮,以及你应用的最近几个会话。

🌐 Then, you'll start to see View on LogRocket buttons in the EAS dashboard in the Native Deployments and Updates dashboards, along with the last few sessions from your app.

了解有关 LogRocket 的更多信息

🌐 Learn more about LogRocket

想了解如何在 Expo 中使用 LogRocket,请查看 LogRocket 文档

🌐 To learn more about how to use LogRocket with Expo, check out the LogRocket documentation.