# Session Replay Plugin for Segment

Choose this option if you use Segment for your site&#x27;s analytics.

Source: https://amplitude.com/docs/sdks/session-replay/session-replay-wrapper-for-segment

---

On this page

- [Before you begin](#before-you-begin)
- [Install the plugin](#install-the-plugin)
- [Use](#use)
- [Segment plugin architecture](#segment-plugin-architecture)
- [User ID to Device ID mapping](#user-id-to-device-id-mapping)
- [Troubleshooting](#troubleshooting)

# 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)](https://segment.com/docs/connections/destinations/catalog/actions-amplitude/) destination only.

To use Session Replay with [Segment's Amplitude (Classic) destination](https://segment.com/docs/connections/destinations/catalog/amplitude/), use the [Session Replay Standalone SDK](/docs/sdks/session-replay/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](/docs/sdks/session-replay/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](https://gethelp.amplitude.com/hc/en-us/requests/new).

## 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](https://gethelp.amplitude.com/hc/en-us/requests/new).

## 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](/docs/sdks/session-replay/session-replay-standalone-sdk#troubleshooting)

Was this helpful?

<!--$-->

<!--/$-->
