This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 观察 iconExpo 观察

一个收集应用性能指标和用户自定义事件并将它们发送到 EAS Observe 的库。

Android
iOS
tvOS
Recommended version:
~58.0.13

expo-observe 是一个库,它可以收集你应用的性能指标和用户自定义事件,并将它们发送到 EAS Observe —— Expo 的性能监控服务,或者你喜欢的任何符合 OpenTelemetry (OTEL) 标准的后台。它可以测量真实环境下的启动性能,比如 首屏渲染时间 (TTR) 和 可交互时间 (TTI),针对在生产环境运行的应用。

除了应用启动指标,这个库还可以:

🌐 Beyond app startup metrics, the library can also:

安装

🌐 Installation

Terminal
- npx expo install expo-observe
- yarn expo install expo-observe
- pnpm expo install expo-observe
- bun expo install expo-observe

If you are installing this in an existing React Native app, make sure to install expo in your project.

配置

🌐 Configuration

在发布版本中,安装“expo-observe”库即可配置库开始发送启动指标(不过你需要按照以下使用说明调用“markInteractive”来跟踪TTI)。该库不会在调试构建中发送事件,但你可以更改此及其他配置选项,如采样率、环境名称以及启用与“Observe.configure()”调用的集成。所有可用选项请参见[EAS Observe 配置指南](/eas/observe/configuration/)。

🌐 In release builds, installing the expo-observe library is all that is needed to configure the library to start sending startup metrics (though you will need to follow the usage instructions below to call markInteractive to track TTI). The library will not dispatch events in debug builds, but you can change this and other config options such as sample rate, environment name and enabling integrations with the Observe.configure({}) call. For all available options, see the EAS Observe configuration guide.

用法

🌐 Usage

将你的根布局用 ObserveRoot 封装,以自动测量首次渲染时间。然后,当你的应用准备好供用户交互时,调用 markInteractive 来记录可交互时间:

🌐 Wrap your root layout with ObserveRoot to measure Time to First Render automatically. Then, call markInteractive when your app is ready for user interaction to record Time to Interactive:

src/app/_layout.tsx
import { ObserveRoot, useObserve } from 'expo-observe'; import { Stack } from 'expo-router'; import { useEffect } from 'react'; function RootLayout() { const { markInteractive } = useObserve(); useEffect(() => { // Replace this effect with your own readiness signal: only call // markInteractive() after initialization work behind the splash screen // (such as loading initial data) completes. markInteractive(); }, [markInteractive]); return <Stack />; } export default ObserveRoot.wrap(RootLayout);

有关逐步说明,包括完整的启动屏示例以及如何处理具有多个入口屏的应用,请参阅 EAS Observe 入门指南。要从你的应用发送自定义事件,请参阅 用户自定义事件。

🌐 For step-by-step instructions, including a complete splash screen example and how to handle apps with multiple entry screens, see the EAS Observe Get started guide. To send custom events from your app, see User-defined events.

应用接口

🌐 API

import { Observe, ObserveRoot, useObserve } from 'expo-observe';

No API data file found, sorry!