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

{% callout type="note" heading="" %}
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).
{% /callout %}

## Install the plugin

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

{% code-group %}
```bash npm
npm install @amplitude/segment-session-replay-plugin --save
```

```bash yarn
yarn add @amplitude/segment-session-replay-plugin
```
{% /code-group %}

## 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. The plugin sends this event 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 whether `userId` is set, and if not, the plugin uses `anonymousId`.

The session replay ID uses 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

{% callout type="warning" heading="Session replay and ad blockers" %}
Session Replay isn't compatible with ad blocking software.
{% /callout %}

For troubleshooting information, go to [Session Replay Standalone SDK | Troubleshooting](/docs/sdks/session-replay/session-replay-standalone-sdk#troubleshooting).
