@amplitude/segment-session-replay-plugin-react-native
Amplitude Segment Session Replay Plugin for React Native
Installation
npm install @amplitude/segment-session-replay-plugin-react-native
Dependencies
This plugin requires the following dependencies to be installed:
npm install @amplitude/session-replay-react-native @segment/analytics-react-native
Important: This plugin requires the @segment/analytics-react-native-plugin-amplitude-session plugin to extract session IDs from Amplitude integration data. Make sure to add this plugin to your Segment client before adding the session replay plugin.
Usage
Segment Session Replay Plugin
Add the segment session replay plugin to your Segment Analytics instance to automatically integrate Amplitude Session Replay with your Segment events.
import { createSegmentSessionReplayPlugin } from '@amplitude/segment-session-replay-plugin-react-native';
import { createClient } from '@segment/analytics-react-native';
import { AmplitudeSessionPlugin } from '@segment/analytics-react-native-plugin-amplitude-session';
// Initialize Segment client
const segmentClient = createClient({
writeKey: 'YOUR_SEGMENT_WRITE_KEY',
});
// Configure session replay plugin
const sessionReplayConfig = {
apiKey: 'YOUR_AMPLITUDE_API_KEY',
deviceId: 'YOUR_DEVICE_ID'
};
// Add the Amplitude session plugin first (required for session ID extraction)
await segmentClient.add({ plugin: new AmplitudeSessionPlugin() });
// Add the session replay plugin to Segment
await segmentClient.add(createSegmentSessionReplayPlugin(sessionReplayConfig));
Plugin Configuration
The plugin accepts a SegmentSessionReplayPluginConfig object: every option from the
SessionReplayConfig of @amplitude/session-replay-react-native, plus:
| Option | Default | Description |
|---|---|---|
autoStart | true | Start recording as soon as the plugin is added to the Segment client. |
Set autoStart: false to control when recording begins, then call start() from
@amplitude/session-replay-react-native yourself:
import { start } from '@amplitude/session-replay-react-native';
await segmentClient.add(createSegmentSessionReplayPlugin({ ...sessionReplayConfig, autoStart: false }));
// later, once you're ready to record
await start();
Automatic Integration
The plugin automatically:
- Initializes Session Replay: Sets up Amplitude Session Replay with your configuration
- Starts Recording: Begins recording once configured, unless
autoStartisfalse - Syncs Session Data: Updates session ID and device ID for each Segment event
- Manages Lifecycle: Handles start/stop operations for session replay
Event Processing
For every event, the plugin:
- Extracts session ID from event properties or Amplitude integration data
- Extracts device ID from event context or anonymous ID
- Forwards both to Session Replay so the recording is attributed correctly
Events are passed through unmodified; the plugin does not add properties to them.