@amplitude/plugin-session-replay-browser

中文文档
1.36.7发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 450.9万
原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. 1. Import Amplitude packages
  4. 2. Instantiate Session Replay plugin
  5. 3. Install plugin to Amplitude SDK
  6. 4. Start and stop recording (optional)
  7. Privacy
  8. Debugging
  9. Using debugMode when developing locally


@amplitude/plugin-session-replay-browser

Official Browser SDK plugin for session replay

Installation

This package is published on NPM registry and is available to be installed using npm and yarn.

# npm
npm install @amplitude/plugin-session-replay-browser

# yarn
yarn add @amplitude/plugin-session-replay-browser

Usage

This plugin works on top of Amplitude Browser SDK and adds session replay features to built-in features. To use this plugin, you need to install @amplitude/analytics-browser version v1.9.1 or later.

This plugin requires that default tracking for sessions is enabled. If default tracking for sessions is not enabled in the config, the plugin will automatically enable it.

1. Import Amplitude packages

  • @amplitude/analytics-browser
  • @amplitude/plugin-session-replay-browser
import * as amplitude from '@amplitude/analytics-browser';
import { sessionReplayPlugin } from '@amplitude/plugin-session-replay-browser';

2. Instantiate Session Replay plugin

The plugin must be registered with the amplitude instance via the following code. The plugin accepts an optional parameter which is an Object to configure the plugin based on your use case.

amplitude.init(API_KEY);
const sessionReplayTracking = sessionReplayPlugin({
  sampleRate: undefined
});

Options

NameTypeDefaultRequiredDescription
sampleRatenumberundefinedYesUse this option to control how many sessions will be selected for replay collection. A selected session will be collected for replay, while sessions that are not selected will not.

The number should be a decimal between 0 and 1, ie 0.01, representing the fraction of sessions you would like to have randomly selected for replay collection. Over a large number of sessions, 0.01 would select 1% of those sessions.
privacyConfigobjectundefinedNoSupports advanced masking configs with CSS selectors.
forceSessionTrackingbooleanfalseNoIf this is enabled we will force the browser SDK to also send start and end session events.
debugModebooleanfalseNoAdds additional debug event property to help debug instrumentation issues (such as mismatching apps). Only recommended for debugging initial setup, and not recommended for production.
configServerUrlstringNoundefinedSpecifies the endpoint URL to fetch remote configuration. If provided, it overrides the default server zone configuration.
trackServerUrlstringNoundefinedSpecifies the endpoint URL for sending session replay data. If provided, it overrides the default server zone configuration.
shouldInlineStylesheetbooleanNotrueIf stylesheets are inlined, the contents of the stylesheet will be stored. During replay, the stored stylesheet will be used instead of attempting to fetch it remotely. This prevents replays from appearing broken due to missing stylesheets. Note: Inlining stylesheets may not work in all cases. If this is undefined stylesheets will be inlined.
inlineImagesbooleanNofalseWhen true, image sources are inlined as data URLs in the rrweb snapshot so replays do not depend on fetching remote image assets at playback time. Increases snapshot payload size. Passed through to rrweb's inlineImages record option.
storeTypestringNoidbSpecifies how replay events should be stored. idb uses IndexedDB to persist replay events when all events cannot be sent during capture. memory stores replay events only in memory, meaning events are lost when the page is closed. If IndexedDB is unavailable, the system falls back to memory.
performanceConfig.enabledbooleanNotrueIf enabled, event compression will be deferred to occur during the browser's idle periods.
performanceConfig.timeoutnumberNoundefinedOptional timeout in milliseconds for the requestIdleCallback API. If specified, this value will be used to set a maximum time for the browser to wait before executing the deferred compression task, even if the browser is not idle.
performanceConfig.mergeMutationsbooleanNofalseIf enabled, consecutive mutation events are merged into a single event before compression. This reduces the stored event count and coalesces bursts of inline style mutations on the same node (last-write-wins), without changing replay semantics.
experimental.useWebWorkerbooleanNofalseIf the SDK should compress the replay events using a webworker.

3. Install plugin to Amplitude SDK

amplitude.add(sessionReplayTracking);

4. Start and stop recording (optional)

The plugin instance exposes start() and stop() so you can pause and resume capture without removing the plugin. Sampling, targeting, and opt-out still apply.

const sessionReplayTracking = sessionReplayPlugin({
  sampleRate: 1,
});
amplitude.add(sessionReplayTracking);

// Pause capture, for example on a sensitive screen
sessionReplayTracking.stop();

// Resume capture
await sessionReplayTracking.start();

Privacy

By default, the session replay will mask all inputs, meaning the text in inputs will appear in a session replay as asterisks: ***. You may require more specific masking controls based on your use case, so we offer the following controls:

1. Unmask inputs

In your application code, add the class .amp-unmask to any input whose text you'd like to have unmasked in the replay. In the session replay, it will be possible to read the exact text entered into an input with this class, the text will not be converted to asterisks.

2. Mask non-input elements

In your application code, add the class .amp-mask to any non-input element whose text you'd like to have masked from the replay. The text in the element, as well as it's children, will all be converted to asterisks.

3. Block non-text elements

In your application code, add the class .amp-block to any element you would like to have blocked from the collection of the replay. The element will appear in the replay as a placeholder with the same dimensions.

4. Block elements by CSS selectors.

In the SDK initialization code, you can configure the SDK to block elements based on CSS selectors.

const sessionReplayTracking = sessionReplayPlugin({
  sampleRate: 0.01,
  privacyConfig: {
      blockSelector: ['.ignoreClass', '#ignoreId']
  }
});

Debugging

Using debugMode when developing locally

Since the Session Replay plugin only records and tags events when the page is in focus, this can sometimes be problematic when developing locally with the browser console open. If you are having issues with the replays not showing up (while your quota usage going up). Try turning setting debugMode:true to see if that helps with the issue.

版本与发布记录

@amplitude/plugin-session-replay-browser 共发布 329 个版本,首次发布于 2023/06/28;过去 12 个月发布了 138 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.36.7latest2026/11/071 天前
1.36.7-sr-bfcache-pageshow-snapshot.02026/11/052 天前
1.36.62026/10/317 天前
1.36.52026/10/299 天前
1.36.6-video-analytics-8.02026/10/2811 天前
1.36.6-video-analytics-7.02026/10/2712 天前

其他发布通道:beta → 0.6.9,srtargeting → 1.7.0-srtargeting.2,next → 1.13.2-beta.0,networkautocapture → 1.16.1-networkautocapture.0,fixtypedefinition → 1.16.1-fixtypedefinition.0,networkautocapture-1 → 1.16.1-networkautocapture-1.0。

关于 @amplitude/plugin-session-replay-browser 的常见问题

如何安装 @amplitude/plugin-session-replay-browser?

在项目目录运行 npm install @amplitude/plugin-session-replay-browser,或使用 pnpm add / yarn add / bun add。

@amplitude/plugin-session-replay-browser 支持 TypeScript 吗?

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

@amplitude/plugin-session-replay-browser 支持 ESM 还是 CommonJS?

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

@amplitude/plugin-session-replay-browser 可以商用吗?

@amplitude/plugin-session-replay-browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amplitude/plugin-session-replay-browser 的下载量有多少?

根据 npm 官方下载统计,@amplitude/plugin-session-replay-browser 在 2026/10/06 – 2026/11/04 这 30 天内被下载 4,509,132 次,日均约 150,304 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amplitude/plugin-session-replay-browser 还在维护吗?

最新版本 1.36.7 发布于 2026/11/07(1 天前);至今共发布 329 个版本,其中过去 12 个月发布了 138 个;首次发布于 2023/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。