Session Replay Flutter Standalone SDK
This article covers the installation of Session Replay for Flutter.
iOS and Android only
The Session Replay Flutter SDK supports iOS and Android only. The SDK doesn't support Flutter Web, macOS, Windows, or Linux.
Beta release
Session Replay for Flutter is in beta. APIs may change and you should expect breaking changes before the stable release.
Report issues
To report issues with Session Replay for Flutter, contact Amplitude support.
Before you begin
Use the latest version of the amplitude_session_replay package.
The Session Replay Flutter SDK requires that:
- Your application runs on iOS 13.0+ or Android 5.0+ (minSdk 21).
- Your project uses Dart SDK 3.7.2 or later and Flutter SDK 3.29.2 or later.
- You can provide a
device IDandsession IDto the SDK. These values must match the identifiers you send as event properties to Amplitude.
The SDK doesn't provide session management. Your application or a third-party integration must update the SDK when the session ID or device ID changes.
Compatibility
| Requirement | Minimum version |
|---|---|
| Dart SDK | 3.7.2 |
| Flutter SDK | 3.29.2 |
| iOS | 13.0 |
| Android minSdk | 21 (Android 5.0) |
| Android compileSdk | 36 |
Quickstart
Add Session Replay to your pubspec.yaml:
dependencies:
amplitude_session_replay: ^0.1.0-beta.1
Then run flutter pub get.
Configure your application code:
- Create a
SessionReplayinstance withSessionReplayConfig, passing your API key, device ID, and session ID. - Call
start()to initialize the native SDK and begin recording. - Wrap your app with
SessionReplayWidgetso the recording engine has a Flutter render context. - When the session ID or device ID changes, call
setSessionId()orsetDeviceId()to keep Session Replay synchronized.
import 'package:amplitude_session_replay/amplitude_session_replay.dart';
import 'package:flutter/widgets.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final sessionReplay = SessionReplay(
SessionReplayConfig(
apiKey: 'YOUR_AMPLITUDE_API_KEY',
deviceId: 'your-device-id',
sessionId: DateTime.now().millisecondsSinceEpoch,
sampleRate: 0.1,
),
);
await sessionReplay.start();
runApp(SessionReplayWidget(sessionReplay: sessionReplay, app: const MyApp()));
}
Configuration
Pass the following options through SessionReplayConfig when you create the SessionReplay instance:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | String | Yes | — | Your Amplitude API key for authentication and data routing. |
deviceId | String | Yes | — | Device identifier. Must match the device ID you send with Amplitude events. Must be at least 6 characters. |
sessionId | int | No | -1 | Session identifier in milliseconds since epoch. A value of -1 means no active session, and Session Replay doesn't record. Must match the session ID you send with Amplitude events. |
sampleRate | double | No | 0.0 | Fraction of sessions to capture for replay (0.0–1.0). For example, 0.4 captures 40% of sessions. |
logLevel | LogLevel | No | LogLevel.warn | Logging verbosity. Options: LogLevel.off, LogLevel.error, LogLevel.warn, LogLevel.log, LogLevel.debug. |
privacyConfig | PrivacyConfig | No | PrivacyConfig.medium | Automatic masking behavior. Options: PrivacyConfig.conservative, PrivacyConfig.medium, PrivacyConfig.light. |
enableRemoteConfig | bool | No | true | Enables remote configuration from Amplitude servers. |
optOut | bool | No | false | When true, Session Replay doesn't record or upload data. Use setOptOut() to change at runtime. |
serverZone | ServerZone | No | ServerZone.us | Server zone for data residency. Set to ServerZone.eu for EU data center. |
shouldInitializeNativeSDK | bool | No | true | When false, the Flutter SDK skips native SDK initialization. Use this for hybrid and add-to-app setups where a native host app already initializes the Amplitude Session Replay native SDK. |
Remote configuration
Enable remote configuration to set Sample Rate and Masking Level in Amplitude.
Remote configuration and testing
With enableRemoteConfig set to true, settings you define in Amplitude take precedence over settings you define locally in the SDK. For this reason, while testing your application, you should disable remote configuration to ensure you can set sampleRate to 1, and ensure you capture test sessions.
Mask onscreen data
Session Replay provides three Flutter widgets for privacy control. These widgets apply to the entire subtree of the wrapped widget. Priority order: AmpBlock > AmpMask > AmpUnmask.
Privacy levels
The privacyConfig option controls automatic masking behavior:
| Level | Behavior |
|---|---|
PrivacyConfig.conservative | Masks all text and all form fields. |
PrivacyConfig.medium (default) | Masks all form fields and text inputs. |
PrivacyConfig.light | Masks only password fields. |
AmpMask
Replaces every character of captured text with an asterisk (*), preserving the original text length and layout. Use this to protect sensitive information that the automatic privacy level doesn't catch:
AmpMask(
child: Text('Sensitive information'),
)
AmpBlock
Blocks an entire subtree from recording and replaces it with a placeholder. Use this for highly sensitive content:
AmpBlock(
child: TextField(
decoration: InputDecoration(labelText: 'Password'),
),
)
AmpUnmask
Prevents automatic masking from privacy level rules. Use this to reveal content that the privacy level would otherwise mask. AmpUnmask can't override a manual AmpMask or AmpBlock:
AmpUnmask(
child: Text('Public content'),
)
User opt-out
To opt users out of session replay collection, pass optOut: true during initialization, or call setOptOut(optOut: true) at runtime. Opted-out users don't record or upload replay data.
await sessionReplay.setOptOut(optOut: true);
EU data residency
Amplitude customers who use the EU data center can access Session Replay. Set serverZone to ServerZone.eu during initialization.
final sessionReplay = SessionReplay(
SessionReplayConfig(
apiKey: 'YOUR_AMPLITUDE_API_KEY',
deviceId: 'your-device-id',
sessionId: DateTime.now().millisecondsSinceEpoch,
serverZone: ServerZone.eu,
),
);
Sampling rate
By default, Session Replay captures 0% of sessions for replay. Use the sampleRate configuration option to set the percentage of total sessions that Session Replay captures. For example:
To set the sampleRate consider the monthly quota on your Session Replay plan. For example, if your monthly quota is 2,500,000 sessions, and you average 3,000,000 monthly sessions, your quota is 83% of your average sessions. In this case, to ensure sampling lasts through the month, set sampleRate to .83 or lower.
Keep the following in mind as you consider your sample rate:
- When you reach your monthly session quota, Amplitude stops capturing sessions for replay.
- Session quotas reset on the first of every month.
- Use sample rate to distribute your session quota over the course of a month, rather than using your full quota at the beginning of the month.
- To find the best sample rate, Amplitude recommends that you start low, for example
.01. If this value doesn't capture enough replays, raise the rate over the course of a few days. For ways to monitor the number of session replays captured, see View the number of captured sessions. - Replays with processing errors don't count toward your monthly quota. Replays with a retention error message have already been counted against the quota, when the session was still in the retention period.
final sessionReplay = SessionReplay(
SessionReplayConfig(
apiKey: 'YOUR_AMPLITUDE_API_KEY',
deviceId: 'your-device-id',
sessionId: DateTime.now().millisecondsSinceEpoch,
sampleRate: 0.01, // Capture 1% of sessions
),
);
Update the session ID
When your session ID changes (for example, on user login or session timeout), update Session Replay:
final newSessionId = DateTime.now().millisecondsSinceEpoch;
await sessionReplay.setSessionId(newSessionId);
Start and stop recording
Control recording for specific pages or features:
// Stop recording before entering a restricted area
await sessionReplay.stop();
// Resume recording after leaving the restricted area
await sessionReplay.start();
Disable replay collection
After you enable Session Replay, it runs on your app until either:
- The user leaves your app.
- You call
sessionReplay.stop(). - You call
sessionReplay.dispose().
Call sessionReplay.stop() before a user navigates to a restricted area of your app to disable replay collection while the user is in that area.
Call sessionReplay.start() to re-enable replay collection when the user returns to an unrestricted area of your app.
Hybrid and add-to-app
If your Flutter module runs inside a native iOS or Android host that already integrates the Amplitude Session Replay native SDK, set shouldInitializeNativeSDK: false in SessionReplayConfig. This tells the Flutter SDK to skip native SDK initialization and let the host app's native SDK own the API key, device ID, session ID, sampling, and upload lifecycle. You still need SessionReplayWidget to enable recording.
import 'package:amplitude_session_replay/amplitude_session_replay.dart';
import 'package:flutter/widgets.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final sessionReplay = SessionReplay(
SessionReplayConfig(
apiKey: 'YOUR_AMPLITUDE_API_KEY',
deviceId: 'your-device-id',
sessionId: DateTime.now().millisecondsSinceEpoch,
shouldInitializeNativeSDK: false,
),
);
await sessionReplay.start();
runApp(SessionReplayWidget(sessionReplay: sessionReplay, app: const MyApp()));
}
Methods
The SessionReplay class exposes the following methods:
| Method | Returns | Description |
|---|---|---|
start() | Future<void> | Start recording. Initializes the native SDK on first call. |
stop() | Future<void> | Stop recording. Call start() to resume. |
dispose() | Future<void> | Release all resources. The instance can't be reused after disposal. |
flush() | Future<void> | Force-upload any pending replay data. Useful before the app backgrounds or terminates. |
setSessionId(int) | Future<void> | Update the session ID. |
sessionId() | Future<int> | Get the current session ID. |
setDeviceId(String) | Future<void> | Update the device ID. |
deviceId() | Future<String> | Get the current device ID. |
setOptOut(optOut: bool) | Future<void> | Toggle opt-out at runtime. When true, stops recording and data upload. |
optOut (getter) | bool | Get the current opt-out status. |
Lifecycle
Created → start() → Started → stop() → Stopped → start() → Started ...
↘ dispose() → Disposed
You can call dispose() from any state. It's idempotent — calling it on an already-disposed instance is a no-op. Use dispose() for permanent teardown only. For temporarily pausing and resuming recording, use stop() and start() instead.
Once disposed, the instance can't be reused. To resume recording after disposal, create a new SessionReplay instance and remount SessionReplayWidget with the new instance (for example, by assigning a new Key to force a rebuild). The engine is bound to the widget at mount time and doesn't rebind when SessionReplay is replaced.
Data retention, deletion, and privacy
Session replay uses existing Amplitude tools and APIs to handle privacy and deletion requests. <!--vale off-->
Consent management and Session Replay
While privacy laws and regulations vary across states and countries, certain constants exist, including the requirements to disclose in a privacy notice the categories of personal information you are collecting, the purposes for its use, and the categories of third parties with which personal information is shared. When implementing a session replay tool, you should review your privacy notice to make sure your disclosures remain accurate and complete. And as a best practice, review your notice with legal counsel to make sure it complies with the constantly evolving privacy laws and requirements applicable to your business and personal information data practices.
Retention period
If your Amplitude plan includes Session Replay, Amplitude retains raw replay data for 30 days from the date of ingestion.
If you purchase extra session volume, Amplitude retains raw replay data for 90 days from the date of ingestion. If you need a more strict policy, contact Amplitude support to set the value to 30 days.
Changes to the retention period impact replays ingested after the change. Sessions captured and ingested before a retention period change retain the previous retention period.
Retention periods are set at the organization level. Replays that are outside of the retention period aren't viewable in Amplitude.
DSAR API
The Amplitude DSAR API returns metadata about session replays, but not the raw replay data. All events that are part of a session replay include a [Amplitude] Session Replay ID event property. This event provides information about the sessions collected for replay for the user, and includes all metadata collected with each event.
{
"amplitude_id": 123456789,
"app": 12345,
"event_time": "2020-02-15 01:00:00.123456",
"event_type": "first_event",
"server_upload_time": "2020-02-18 01:00:00.234567",
"device_id": "your device id",
"user_properties": { ... }
"event_properties": {
"[Amplitude] Session Replay ID": "cb6ade06-cbdf-4e0c-8156-32c2863379d6/1699922971244"
}
"session_id": 1699922971244,
}
Data deletion
Session Replay uses Amplitude's User Privacy API to handle deletion requests. Successful deletion requests remove all session replays for the specified user.
When you delete the Amplitude project on which you use Session Replay, Amplitude deletes that replay data.
Bot filter
Session Replay uses the same block filter available in the Amplitude app. Session Replay doesn't block traffic based on event or user properties.
Known limitations
- Beta status: APIs may change. Expect breaking changes before the stable release.
- RSuperellipse capture: Requires Flutter 3.32 or later. Base functionality works on Flutter 3.29.2+.
- Multi-view apps: The SDK captures only the first attached
FlutterView. The SDK doesn't supportrunWidget,FlutterEngineGroup, or view remounts afterstart(). - Remote config override: When
enableRemoteConfigistrue, server settings can override the localsampleRateand privacy settings. - Native SDK dependencies: iOS uses
AmplitudeSessionReplay~>0.10.0. Android usessession-replay-android[0.26.0, 0.27.0).
Troubleshooting
Session replays don't appear in Amplitude
Session replays may not appear because of:
- Lack of network connectivity.
- Sampling excluded the session (
sampleRatetoo low). - No events sent with matching
deviceIdandsessionIdfor the session. sessionReplay.start()wasn't called after construction.
Verify your configuration
- Check that
sampleRateis greater than0. The default is0.0, which captures no sessions. - Confirm you call
sessionReplay.start()after constructing theSessionReplayinstance. - Ensure the
apiKey,deviceId, andsessionIdmatch the values you send with analytics events.
Verify network connectivity
Ensure your app has access to the internet and try again.
Check sample rate
The default sampleRate is 0.0. Update the rate to a higher number. For more information, refer to Sampling rate.
Session Replay processing errors
Replays appear in Amplitude within minutes of ingestion. Delays or errors may result from:
- Mismatched API keys or device IDs between Session Replay and your analytics instrumentation.
- Session Replay references the wrong project.
- Short sessions. If a user bounces within a few seconds of initialization, the SDK may not have time to upload replay data.
Was this helpful?