On this page

Session Replay Plugin for Segment

Amplitude provides a plugin to enable a one-line integration between Segment and Amplitude's Session Replay.

This plugin supports Segment's Amplitude (Actions) destination only.

To use Session Replay with Segment's Amplitude (Classic) destination, use the Session Replay Standalone SDK.

Before you begin

Use the latest version of the Session Replay Plugin for Segment above version {{sdk_versions:session_replay_segment_wrapper}}

Install the plugin

Use npm or Yarn to install the package, which includes the Amplitude Session Replay SDK.

bash
npm install @amplitude/segment-session-replay-plugin --save

Use

For information about the sessionReplayOptions, go to the Session Replay Standalone SDK configuration section.

js
import { AnalyticsBrowser } from '@segment/analytics-next';
import { createSegmentActionsPlugin } from '@amplitude/segment-session-replay-plugin';

export const segmentAnalytics = AnalyticsBrowser.load({
  writeKey: SEGMENT_API_KEY,
});

const segmentActionsPlugin = createSegmentActionsPlugin({
  segmentInstance: segmentAnalytics,
  amplitudeApiKey: AMPLITUDE_API_KEY,
  sessionReplayOptions: {
    logLevel: 4,
    sampleRate: 1,
    debugMode: true,
  },
});

segmentAnalytics.register(segmentActionsPlugin);

Segment plugin architecture

Amplitude automatically creates the [Amplitude] Replay Captured event when Session Replay captures a session. This event is sent directly to Amplitude to link replays with your analytics data. If you don't see this event in Amplitude, contact Amplitude support.

User ID to Device ID mapping

Following Segment's documentation, the plugin maps the Segment user ID to the Amplitude device ID. To find the device ID for replay captures, the plugin checks if userId is set, and if not, it uses anonymousId.

The session replay ID has the format <deviceId>/<sessionId>. Because Session Replay uses / as a delimiter, the device ID value can't contain /. Accepted characters: a-z A-Z 0-9 _ - . | @ : =. Segment's userId and anonymousId values are UUIDs, which always comply with these requirements. If you need an additional character, contact Amplitude support.

Troubleshooting

Session replay and ad blockers

Session Replay isn't compatible with ad blocking software.

For troubleshooting information, go to Session Replay Standalone SDK | Troubleshooting

Was this helpful?