@datadog/mobile-react-native-session-replay

中文文档
3.11.0发布于 2026/10/20Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 79.5万

A client-side React Native module to enable session replay with Datadog

原始使用文档
文档目录9 节
  1. Setup
  2. Enable Session Replay
  3. Start or stop the recording manually
  4. SVG Support
  5. Prerequisites
  6. Setup Babel Plugin
  7. Setup Metro Plugin
  8. Installation Workflow
  9. Development Workflow

Session Replay for React Native

Mobile Session Replay expands visibility into your mobile applications by visually replaying each user interaction, such as taps, swipes, and scrolls. Visually replaying user interactions on your applications makes it easier to reproduce crashes and errors, as well as understand the user journey for making UI improvements.

Setup

Note: Make sure you’ve setup and initialized the Datadog React Native SDK with views instrumentation enabled.

To install with NPM, run:

npm install @datadog/mobile-react-native-session-replay

To install with Yarn, run:

yarn add @datadog/mobile-react-native-session-replay

Enable Session Replay

To enable Session Replay, import and call the enable method with your configuration. Below is an example setup:

import { SessionReplay } from "@datadog/mobile-react-native-session-replay";

SessionReplay.enable({
    replaySampleRate: sampleRate, // The percentage of sampled replays, in the range 0.0 - 100.0 (Default: 100.0).
    textAndInputPrivacyLevel: TextAndInputPrivacyLevel.MASK_ALL, // Defines the way text and input (e.g text fields, checkboxes) should be masked (Default: `MASK_ALL`).
    imagePrivacyLevel: ImagePrivacyLevel.MASK_ALL, // Defines the way images should be masked (Default: `MASK_ALL`).
    touchPrivacyLevel: TouchPrivacyLevel.HIDE  // Defines the way user touches (e.g tap) should be masked (Default: `HIDE`).
});

Note: All configuration properties are optional and should be adjusted based on your application's needs.

Start or stop the recording manually

By default, Session Replay starts recording automatically. However, if you prefer to manually start recording at a specific point in your application, you can use the optional startRecordingImmediately parameter as shown below, and later call SessionReplay.startRecording(). You can also use SessionReplay.stopRecording() to stop the recording anytime.

import { SessionReplay } from "@datadog/mobile-react-native-session-replay";

SessionReplay.enable({
  replaySampleRate: sampleRate,
  startRecordingImmediately: false
});
// Do something
SessionReplay.startRecording();
SessionReplay.stopRecording();

SVG Support

Session Replay provides enhanced support for capturing SVG images in your React Native application. To enable SVG tracking, you need to set up the Datadog Babel plugin and Metro plugin.

Prerequisites

Install the Datadog Babel plugin:

npm install @datadog/mobile-react-native-babel-plugin

or with Yarn:

yarn add @datadog/mobile-react-native-babel-plugin

Setup Babel Plugin

Configure the Babel plugin in your babel.config.js to enable SVG tracking:

module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [
    [
      '@datadog/mobile-react-native-babel-plugin',
      {
        sessionReplay: {
          // SVG tracking is disabled by default
          // Set to true to enable SVG asset extraction
          svgTracking: true
        }
      }
    ]
  ]
};

Setup Metro Plugin

Configure the Metro plugin in your metro.config.js to enable automatic SVG asset bundling:

const { withSessionReplayAssetBundler } = require('@datadog/mobile-react-native-session-replay/metro');

module.exports = withSessionReplayAssetBundler({
  /* your existing Metro config */
});

The Metro plugin automatically monitors and bundles SVG assets during development and production builds.

Installation Workflow

When setting up your project or after installing new dependencies, follow this workflow to ensure SVG assets are properly generated for native builds:

# 1. Install dependencies
yarn install

# 2. Generate Session Replay SVG assets
npx datadog-generate-sr-assets

# 3. Install iOS pods (if building for iOS)
cd ios && pod install && cd ..

# 4. Run your app
yarn ios
# or
yarn android

The datadog-generate-sr-assets CLI utility scans your codebase for SVG elements and pre-generates optimized assets that will be included in your native builds.

CLI Options

The datadog-generate-sr-assets command supports the following options:

npx datadog-generate-sr-assets [options]
OptionAliasDescriptionExample
--ignore <pattern>-iAdditional glob patterns to ignore during scanning. Can be specified multiple times.npx datadog-generate-sr-assets --ignore "**/legacy/**" --ignore "**/vendor/**"
--verbose-vEnable verbose output for debugging.npx datadog-generate-sr-assets --verbose
--path <path>-pPath to the root directory to scan. Defaults to the current working directory.npx datadog-generate-sr-assets --path ./src
--followSymlinksFollow symbolic links during directory traversal. Default: false (symlinks are ignored).npx datadog-generate-sr-assets --followSymlinks

Note for CI/CD: If you use continuous integration for your builds, make sure to include these steps in your CI pipeline. The workflow should be: yarn install → npx datadog-generate-sr-assets → pod install (for iOS) → build your app. This ensures SVG assets are properly generated before the native build process.

Development Workflow

During development, the Metro plugin automatically handles SVG assets created by the Babel plugin:

  1. Write your components with SVG elements from react-native-svg
  2. The Babel plugin extracts and transforms SVG nodes during the build process
  3. The Metro plugin detects new SVG assets and automatically bundles them
  4. SVG images are seamlessly captured in Session Replay recordings

No manual asset management is required during development.

版本与发布记录

@datadog/mobile-react-native-session-replay 共发布 76 个版本,首次发布于 2024/01/16;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.11.0latest2026/10/2021 天前
3.10.02026/10/091 个月前
3.9.02026/10/011 个月前
3.8.02026/09/221 个月前
3.7.02026/09/032 个月前
3.6.02026/08/172 个月前

其他发布通道:next → 2.0.3-alpha.0,v2 → 2.14.9。

关于 @datadog/mobile-react-native-session-replay 的常见问题

@datadog/mobile-react-native-session-replay 是什么?

A client-side React Native module to enable session replay with Datadog

如何安装 @datadog/mobile-react-native-session-replay?

在项目目录运行 npm install @datadog/mobile-react-native-session-replay,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.13.1)、react-native(>=0.63.4 <1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@datadog/mobile-react-native-session-replay 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@datadog/mobile-react-native-session-replay 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@datadog/mobile-react-native-session-replay 可以商用吗?

@datadog/mobile-react-native-session-replay 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@datadog/mobile-react-native-session-replay 的下载量有多少?

根据 npm 官方下载统计,@datadog/mobile-react-native-session-replay 在 2026/10/12 – 2026/11/10 这 30 天内被下载 794,956 次,日均约 26,499 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@datadog/mobile-react-native-session-replay 还在维护吗?

最新版本 3.11.0 发布于 2026/10/20(21 天前);至今共发布 76 个版本,其中过去 12 个月发布了 32 个;首次发布于 2024/01/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。