Skip to content

Flutter Session Replay

Prerequisites

  • Make sure you have set up and initialized Flutter RUM configuration and enabled View monitoring collection.
  • Flutter Session Replay requires both ft_mobile_agent_flutter and ft_session_replay_flutter to be installed.
  • Starting with ft_mobile_agent_flutter 0.5.7, Session Replay capabilities are no longer built in. Session Replay APIs need to be imported from ft_session_replay_flutter.
  • When using ft_mobile_agent_flutter 0.5.8, choose a version of ft_session_replay_flutter that is compatible with its native dependencies to avoid the two plugins depending on different versions of the native SDK. The matching ft_session_replay_flutter 0.1.1 depends on Android ft-sdk:1.7.6, ft-native:1.1.4, ft-session-replay:0.1.9, and iOS TrueWatchSDK1.6.9 and TrueWatchSDK/SessionReplay 1.6.9.
  • When using ft_mobile_agent_flutter 0.5.8, the iOS project's Deployment Target must be set to 15.0 or later.
  • We recommend completing RUM initialization before initializing Session Replay to ensure that contexts such as app_id, session_id, and view_id are established.

Installation

Run the following in the project directory:

flutter pub add ft_mobile_agent_flutter
flutter pub add ft_session_replay_flutter

This adds the dependencies to the package's pubspec.yaml:

dependencies:
  ft_mobile_agent_flutter: [latest_version]
  ft_session_replay_flutter: [session_replay_version]

To debug an unpublished version locally, use path dependencies:

dependencies:
  ft_mobile_agent_flutter:
    path: /path/to/ft-sdk-flutter
  ft_session_replay_flutter:
    path: /path/to/ft-sdk-flutter/packages/ft_session_replay_flutter

Then run:

flutter pub get

Additional iOS Configuration

Starting with Core SDK 0.5.8 and Session Replay SDK 0.1.1, Swift Package Manager is supported, while CocoaPods integration remains available. The minimum iOS version is 15.0.

When using ft_mobile_agent_flutter 0.5.8, ensure that the app's ios/Podfile and Xcode Deployment Target are not lower than 15.0 for CocoaPods integration:

platform :ios, '15.0'

Update CocoaPods dependencies:

cd ios
pod install

If CocoaPods reports a conflict with native SDK versions or the Deployment Target, first check whether there is an old direct FTMobileSDK dependency, a different version of TrueWatchSDK, or a lower iOS deployment version. When using Swift Package Manager, configure it according to Flutter iOS Integration, and use ft_mobile_agent_flutter 0.5.8 together with ft_session_replay_flutter 0.1.1 or a later compatible version. You do not need to manually add native SDK dependencies again.

Code Usage

Import both the main package and the Session Replay package in Dart code:

import 'package:ft_mobile_agent_flutter/ft_mobile_agent_flutter.dart';
import 'package:ft_session_replay_flutter/ft_session_replay_flutter.dart';

Recommended initialization order:

  1. WidgetsFlutterBinding.ensureInitialized()
  2. FTMobileFlutter.sdkConfig(...)
  3. FTRUMManager().setConfig(...)
  4. FTSessionReplayManager().setConfig(...)
  5. Wrap the Flutter view tree to be recorded with SessionReplayCapture
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await FTMobileFlutter.sdkConfig(
    datawayUrl: datawayUrl,
    cliToken: cliToken,
    serviceName: serviceName,
    debug: true,
  );

  await FTRUMManager().setConfig(
    androidAppId: androidAppId,
    iOSAppId: iOSAppId,
    sessionSamplingRate: 100.0,
    enableUserResource: true,
    enableNativeAppUIBlock: true,
    enableTrackNativeCrash: true,
  );

  await FTSessionReplayManager().setConfig(
    FTSessionReplayConfig(
      sessionReplaySamplingRate: 100.0,
      sessionReplayOnErrorSamplingRate: 0.0,
      touchPrivacy: FTTouchPrivacyLevel.show,
      textAndInputPrivacy: FTTextAndInputPrivacyLevel.maskSensitiveInputs,
      imagePrivacy: FTImagePrivacyLevel.maskAll,
      enableSwiftUI: false,
    ),
  );

  runApp(
    SessionReplayCapture(
      key: const ValueKey('session-replay-root'),
      child: const MyApp(),
    ),
  );
}

If your application wraps pages uniformly through MaterialApp.builder, you can also use SessionReplayCapture in builder:

MaterialApp(
  builder: (BuildContext context, Widget? child) {
    return SessionReplayCapture(
      key: const ValueKey('session-replay-root'),
      child: child ?? const SizedBox.shrink(),
    );
  },
);
Property Type Required Description
sessionReplaySamplingRate double No Session Replay percentage sampling rate, range [0,100], supports decimals, defaults to 100 (full sampling). 0.1 means 0.1%, 1 means 1%. Replay sampling is performed on top of RUM session sampling. Supported since Session Replay SDK 0.1.1.
sampleRate double No Legacy probability configuration, retained for compatibility. Replay sampling rate on top of RUM session sampling, range [0,1], defaults to 1. 0.1 means 10%, 1 means 100%. We recommend using sessionReplaySamplingRate instead.
sessionReplayOnErrorSamplingRate double No Replay error supplemental sampling percentage, range [0,100], supports decimals, defaults to 0; used for sessions that do not hit normal Replay sampling. Supported since Session Replay SDK 0.1.1.
sessionReplayOnErrorSampleRate double No Legacy probability configuration, retained for compatibility. Replay error supplemental sampling probability, range [0,1], defaults to 0. We recommend using sessionReplayOnErrorSamplingRate instead.
touchPrivacy FTTouchPrivacyLevel No Sets the privacy level for touch behavior. FTTouchPrivacyLevel.show shows touch behavior; FTTouchPrivacyLevel.hide hides touch behavior. Defaults to FTTouchPrivacyLevel.hide.
textAndInputPrivacy FTTextAndInputPrivacyLevel No Sets the privacy level for text and input content. maskSensitiveInputs masks only sensitive input; maskAllInputs masks all input content; maskAll masks all text and input content. Defaults to maskAll.
imagePrivacy FTImagePrivacyLevel No Sets the privacy level for image content. maskNone does not mask images; maskLargeOnly masks large content images on Android, and on iOS retains only built-in app images and masks non-built-in images; maskAll masks all images. Defaults to maskAll.
enableLinkRUMKeys List<String> No By default, no additional fields are attached. Associates the corresponding fields in the RUM Context with replay data according to the specified keys; starting with Session Replay SDK 0.1.1, it is also used for image resource existence checks, uploads, and backend routing, enabling data routing. Field values are sent with requests; do not include sensitive information such as secrets.
enableSwiftUI bool No iOS: whether to enable native SwiftUI session replay recording. Defaults to false. Flutter Widget recording still requires wrapping the view tree with SessionReplayCapture.

Percentage Sampling Migration

Supported since Session Replay SDK 0.1.1.

Sampling Rate Parameter Naming

Starting with Session Replay SDK 0.1.1, we recommend using sessionReplaySamplingRate and sessionReplayOnErrorSamplingRate. Values are percentages in the range 0–100 and support decimals; 0 means no sampling, and 100 means full sampling. Invalid values such as out-of-range values, NaN, or infinity throw ArgumentError.

The legacy sampleRate and sessionReplayOnErrorSampleRate remain available for compatibility and take probability values in the range 0–1. For example, 0.1 in the legacy field means 10%, while 0.1 in the new field means 0.1%. If both the new and legacy fields are set for the same item, the new percentage field takes precedence, including an explicit 0.

For the units and precedence of remote sampling fields, see Flutter remote configuration fields.

For example, to migrate a 12.5% Replay sampling configuration to:

 FTSessionReplayConfig(
-  sampleRate: 0.125,
-  sessionReplayOnErrorSampleRate: 0.0,
+  sessionReplaySamplingRate: 12.5,
+  sessionReplayOnErrorSamplingRate: 0.0,
   imagePrivacy: FTImagePrivacyLevel.maskAll,
 )

Pause and Resume Flutter Session Replay Recording

Supported since Session Replay SDK 0.1.1.

After Session Replay initialization is complete, use FTSessionReplayManager().setCaptureActive(bool active) to pause or resume Flutter view capture. It returns Future<void>. The initial state is true; pass false to pause and true to resume. Actual capture is still controlled by the sampling configuration and RUM View association conditions.

// Pause Flutter Session Replay recording
await FTSessionReplayManager().setCaptureActive(false);

// Resume Flutter Session Replay recording
await FTSessionReplayManager().setCaptureActive(true);

In Add-to-App or multi-engine scenarios, pause Flutter recording before showing native pages, and resume after Flutter pages become visible again. This switch only controls the current Flutter capture; recording of native pages still requires the corresponding native integration configuration. To fully shut down the SDK, see Shutdown and Reinitialization.

Shutdown and Reinitialization

Unified shutdown is supported starting with Core SDK 0.5.8 and Session Replay SDK 0.1.1.

await FTMobileFlutter.shutDown();

After shutdown completes, if you need to resume collection, explicitly configure the base SDK, RUM, and Session Replay again in that order, and ensure that the Flutter view tree is still wrapped by SessionReplayCapture. For complete steps, see Initialization Example; there is no need to call a separate Replay shutdown method.

RUM View Association

Session Replay data needs to be associated with the RUM View context. Use FTRouteObserver to automatically collect page transitions, or manually call FTRUMManager().starView(...) and FTRUMManager().stopView(...) in a custom page lifecycle.

MaterialApp(
  navigatorObservers: [
    FTRouteObserver(),
  ],
);

If the base SDK or RUM is not initialized, Session Replay initialization will not crash the app, but no uploadable replay data will be generated.

Privacy Overrides

SessionReplayPrivacy can be used to set privacy overrides for a local Flutter view tree. Privacy overrides apply to its child views; when multiple override layers exist, child views use the nearest parent privacy configuration.

SessionReplayPrivacy(
  textAndInputPrivacyLevel: FTTextAndInputPrivacyLevel.maskAll,
  imagePrivacyLevel: FTImagePrivacyLevel.maskAll,
  touchPrivacyLevel: FTTouchPrivacyLevel.hide,
  child: child,
);

WebView Session Replay

Currently, Flutter Session Replay does not support session replay of web page content inside WebView.

View Session Replay

Session Replay on mobile is viewed in the same way as on the Web. See Web Session Replay access method.