Get started with Browser Session Replay

npmv1.37.041.9 kB gzip

이 페이지는 아직 귀하의 언어로 번역되지 않았습니다. 현재 작업 중이므로 곧 다시 확인해 주십시오.

For web developers10 minBeginner

This guide installs Session Replay on a website, records one test session, and confirms the replay in Amplitude. Session Replay is off until you install it and set a sample rate. Each step lists the conditions that commonly stop replays at that step, so you can fix a problem where it happens. For every option, go to Configuration options. For changes in each release, go to the Session Replay Browser SDK release notes.

Choose a variant

Session Replay for the browser ships in two packages. Install one of them, not both.

The plugin reads the device ID, session ID, opt-out setting, and server zone from Browser SDK 2. The standalone SDK reads nothing from other tools: you pass it the device ID and session ID that your analytics tool sends with its events. Amplitude uses those IDs to match each replay to the user's events. For the options, go to Choose a session matching option.

For a new Amplitude installation, use the Browser Unified SDK (@amplitude/unified) instead. It includes Browser SDK 2 and the Session Replay plugin in one package.

Prerequisites

  • An Amplitude project and its API key. Find the key in Settings > Projects > your project > General.
  • The data center your organization uses: US (default) or EU.
  • A Session Replay plan. Your organization shares one replay quota across projects.
  • For the plugin, Browser SDK 2 installed on the page. For the standalone SDK, a device ID and session ID from your analytics tool, available in the browser.
  • A page served over http:// or https://, in a browser that Amplitude SDKs support.

Install the SDK

Choose one installation method for your variant.

bash
npm install @amplitude/plugin-session-replay-browser
ts
import * as amplitude from "@amplitude/analytics-browser";
import { sessionReplayPlugin } from "@amplitude/plugin-session-replay-browser";

To serve the script from your own domain, go to Self-host the browser Session Replay script.

Fix installation problems

Initialize the SDK

Set sampleRate explicitly. It defaults to 0, which records no sessions. The examples use 1 to record every session while you test. Lower it before you release, or set the rate in Amplitude, which overrides the code.

Add the plugin before you call init(), so it records from the first page load.

ts
amplitude.add(sessionReplayPlugin({ sampleRate: 1 }));
amplitude.init("AMPLITUDE_API_KEY");

With the script tag, use the global:

html
<script>
  window.amplitude.add(window.sessionReplay.plugin({ sampleRate: 1 }));
  window.amplitude.init("AMPLITUDE_API_KEY");
</script>

If your project uses the EU data center, set serverZone: "EU" in the Browser SDK 2 init() options. The plugin reads serverZone from Browser SDK 2.

Initialize Session Replay only in browser code. With server-side rendering, initialize it from a client entry point or an effect, not from code that also runs on the server.

Fix initialization problems

To see these log lines, turn on debug logging.

Record a test session

  1. Open a page where Session Replay runs.
  2. Click, type, and scroll for about a minute. Navigate to a second page if your site has one.
  3. Send at least one analytics event during the session. With the plugin, a Browser SDK 2 page view counts. With the standalone SDK, send it from your analytics tool with the same device ID and session ID you passed to Session Replay.

The SDK uploads recorded data in batches while the user interacts, and when the user hides or leaves the page. A page with no activity sends nothing until the next interaction.

Fix upload problems

Confirm a replay in Amplitude

  1. In Amplitude, open User Lookup and search for the device ID or user ID from your test session.
  2. Open the session in the Activity tab, and select Play Session.
  3. Confirm that the replay shows the clicks and page changes you made.

Replays usually appear in Amplitude about five minutes after the session starts. If the replay doesn't appear, follow Verify replays, which checks each stage between the page and Amplitude.

Next steps

이 내용이 도움이 되었나요?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

이 페이지에서