Skip to content

Android SESSION REPLAY

Prerequisites

  • Ensure you have set up and initialized the FTSdk RUM configuration, and enabled View monitoring collection.
  • Android Session Replay requires ft-sdk:1.7.0 or higher.
  • ft-session-replay and ft-session-replay-material must use the same version number.
  • It is recommended to prioritize using the stable release version displayed by the badges at the top of the document. Using pre-release versions like alpha or beta is no longer recommended.
  • If you wish to access cutting-edge capabilities early, stay updated on the latest features, or follow changes not yet officially released, you can visit the GitHub repository for the Android SDK and its changelog: GuanceCloud/datakit-android

Configuration

//Add SDK dependency
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-sdk:[latest_version]'
//Required to enable session replay functionality
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-session-replay:[session_replay_version]'
//Required for session replay support for material components
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-session-replay-material:[session_replay_version]'
//Required for session replay support for compose components
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-session-replay-compose:[session_replay_version]'

Code Sample

FTSdk.initSessionReplayConfig(new FTSessionReplayConfig().setSampleRate(1f)
                .setTouchPrivacy(TouchPrivacy.SHOW)
                .setImagePrivacy(ImagePrivacy.MASK_LARGE_ONLY)
                .setTextAndInputPrivacy(TextAndInputPrivacy.MASK_SENSITIVE_INPUTS)
                .addExtensionSupport(new MaterialExtensionSupport()), context);
FTSdk.initSessionReplayConfig(FTSessionReplayConfig().setSampleRate(1f)
                .setTouchPrivacy(TouchPrivacy.SHOW)
                .setImagePrivacy(ImagePrivacy.MASK_LARGE_ONLY)
                .setTextAndInputPrivacy(TextAndInputPrivacy.MASK_SENSITIVE_INPUTS)
                .addExtensionSupport(MaterialExtensionSupport()), context)
Method Name Type Required Description
setSampleRate Float No Sets the sampling rate. Value range [0,1]. 0 means no sampling, 1 means full sampling. Default is 1.
setSessionReplayOnErrorSampleRate Float No Sets the error sampling rate. When a session is not sampled by setSampleRate, if an error occurs during the session, data from the 1 minute before the error can be collected. Value range [0,1]. 0 means no sampling, 1 means full sampling. Default is 0. Supported in ft-session-replay 0.1.2-alpha01 and above.
setPrivacy SessionReplayPrivacy No SessionReplayPrivacy.ALLOW does not mask private data. SessionReplayPrivacy.MASK masks all data, including text, CheckBox, RadioButton, Switch. SessionReplayPrivacy.USER_INPUT (recommended) masks user-input data, including text in input fields, CheckBox, RadioButton, Switch. Default is SessionReplayPrivacy.MASK. Deprecated soon, can be used for compatibility, but it is recommended to prioritize using setTouchPrivacy, setTextAndInputPrivacy for masking settings.
setTextAndInputPrivacy TextAndInputPrivacy No TextAndInputPrivacy.MASK_SENSITIVE_INPUTS only masks sensitive information like passwords. TextAndInputPrivacy.MASK_ALL_INPUTS masks user-input data, including text in input fields, CheckBox, RadioButton, Switch. TextAndInputPrivacy.MASK_ALL masks all data, including text, CheckBox, RadioButton, Switch. Default is TextAndInputPrivacy.MASK_ALL. Settings here override configurations from setPrivacy. Supported in ft-session-replay 0.1.1-alpha01 and above.
setImagePrivacy ImagePrivacy No ImagePrivacy.MASK_ALL masks all images. ImagePrivacy.MASK_LARGE_ONLY only masks large image content (content images larger than 100x100 dp). ImagePrivacy.MASK_NONE does not mask images. Default is ImagePrivacy.MASK_ALL. Settings here override configurations from setPrivacy. Requires ft-sdk >= 1.7.0-alpha40, ft-session-replay >= 0.1.3-alpha14.
setTouchPrivacy TouchPrivacy No TouchPrivacy.SHOW does not mask touch data. TouchPrivacy.HIDE masks touch data. Settings here override configurations from setPrivacy. Supported in ft-session-replay 0.1.1-alpha01 and above.
addExtensionSupport ExtensionSupport No Adds additional custom support. Using ft-session-replay-material allows the use of MaterialExtensionSupport to provide additional Material component collection support.

Privacy Override

Supported in ft-session-replay 0.1.1-alpha01 and above.

In addition to supporting global masking levels configured via FTSessionReplayConfig, the SDK also supports overriding these settings at the view level.

View-level privacy override:

  • Supports overriding image masking level.
  • Supports overriding text and input masking level and touch masking level.
  • Supports setting specific views to be completely hidden.

Note:

  • To ensure correct identification of override settings, they should be applied as early as possible in the view lifecycle. This prevents cases where Session Replay processes the view before the applied override settings.
  • Privacy overrides affect the view and its child views. This means that even if an override is applied to a view where it might not take immediate effect (e.g., applying an image override to a text input), the override will still apply to all child views.
  • Privacy override priority: child view > parent view > global settings

Image Override

Requires ft-sdk >= 1.7.0-alpha40, ft-session-replay >= 0.1.3-alpha14.

To override image privacy, use PrivacyOverrideExtensions.setSessionReplayImagePrivacy(View,ImagePrivacy) on the view instance, setting it to a value from the ImagePrivacy enum. To remove an existing override rule, simply set this property to null.

// Mark a specific view for image privacy override
PrivacyOverrideExtensions.setSessionReplayImagePrivacy(view, ImagePrivacy.MASK_ALL);
// Remove the image privacy override setting for the view
PrivacyOverrideExtensions.setSessionReplayImagePrivacy(view, null);
// Mark a specific view for image privacy override
PrivacyOverrideExtensions.setSessionReplayImagePrivacy(view, ImagePrivacy.MASK_ALL)
// Remove the image privacy override setting for the view
PrivacyOverrideExtensions.setSessionReplayImagePrivacy(view, null)

Text and Input Override

To override text and input privacy, use PrivacyOverrideExtensions.setSessionReplayTextAndInputPrivacy(View,TextAndInputPrivacy) on the view instance, setting it to a value from the TextAndInputPrivacy enum. To remove an existing override rule, simply set this property to null.

// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayTextAndInputPrivacy(view, TextAndInputPrivacy.MASK_ALL);
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayTextAndInputPrivacy(view, null);
// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayTextAndInputPrivacy(view, TextAndInputPrivacy.MASK_ALL)
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayTextAndInputPrivacy(view, null)

Touch Override

To override touch privacy, use PrivacyOverrideExtensions.setSessionReplayTouchPrivacy(View,TouchPrivacy) on the view instance, setting it to a value from the TouchPrivacy enum. To remove an existing override rule, simply set this property to null.

// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayTouchPrivacy(view, TouchPrivacy.HIDE);
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayTouchPrivacy(view, null);
// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayTouchPrivacy(view, TouchPrivacy.HIDE)
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayTouchPrivacy(view, null)

Hidden Element Override

For sensitive elements that need to be completely hidden, use PrivacyOverrideExtensions.setSessionReplayHidden(View,Boolean) to set them.

When an element is set to hidden, it will be replaced by a placeholder marked as "Hidden" in the replay, and its child views will not be recorded.

Note: Marking a view as hidden does not prevent touch interactions on that element from being recorded. To hide touch interactions, in addition to marking the element as hidden, also use Touch Override.

// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayHidden(view, true)
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayHidden(view, false)
// Mark a specific view for hidden element override
PrivacyOverrideExtensions.setSessionReplayHidden(view, true)
// Remove the hidden element override setting for the view
PrivacyOverrideExtensions.setSessionReplayHidden(view, false)

Webview Session Replay

Supported in ft-session-replay 0.1.3-alpha11, ft-sdk 1.7.0-alpha36 and above.

For WebView Session Replay, you need to integrate the Web Monitoring SDK into the WebView-accessed page, and enable Session Replay within the Webview.

//In addition to webview RUM settings
window.DATAFLUX_RUM.startSessionReplayRecording();

Tencent Webivew X5 Support

FTSdk.initSessionReplayConfig(new FTSessionReplayConfig()
    //...
    // Additional CustomExtensionSupport settings
    .addExtensionSupport(new CustomExtensionSupport()
            .addMapper(new MapperTypeWrapper<>(com.tencent.smtt.sdk.WebView.class,
                    new WebViewXWireframeMapper())))
)
FTSdk.initSessionReplayConfig(FTSessionReplayConfig()
    //...
    // Additional CustomExtensionSupport settings
    .addExtensionSupport(
        CustomExtensionSupport()
            .addMapper(
                MapperTypeWrapper(
                    com.tencent.smtt.sdk.WebView::class.java,
                    WebViewXWireframeMapper()
                )
            )
    )
)

Jetpack Compose Support

ft-session-replay-compose must use the same version number as ft-session-replay.

Android Session Replay now supports collection and replay of Jetpack Compose interfaces. When using Compose pages, you need to additionally introduce the Compose extension dependency and add ComposeExtensionSupport to FTSessionReplayConfig.

Add Dependency

implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-session-replay-compose:[session_replay_version]'

Initialization Configuration

FTSdk.initSessionReplayConfig(new FTSessionReplayConfig().setSampleRate(1f)
                .setTouchPrivacy(TouchPrivacy.SHOW)
                .setImagePrivacy(ImagePrivacy.MASK_LARGE_ONLY)
                .setTextAndInputPrivacy(TextAndInputPrivacy.MASK_SENSITIVE_INPUTS)
                .addExtensionSupport(new ComposeExtensionSupport())
                .addExtensionSupport(new MaterialExtensionSupport()), context);
FTSdk.initSessionReplayConfig(FTSessionReplayConfig().setSampleRate(1f)
                .setTouchPrivacy(TouchPrivacy.SHOW)
                .setImagePrivacy(ImagePrivacy.MASK_LARGE_ONLY)
                .setTextAndInputPrivacy(TextAndInputPrivacy.MASK_SENSITIVE_INPUTS)
                .addExtensionSupport(ComposeExtensionSupport())
                .addExtensionSupport(MaterialExtensionSupport()), context)

Compose Privacy Override

Compose pages support overriding Session Replay privacy configurations via Modifier:

  • sessionReplayHide(Boolean): Hides the specified Compose node.
  • sessionReplayImagePrivacy(ImagePrivacy): Overrides the image privacy level.
  • sessionReplayTextAndInputPrivacy(TextAndInputPrivacy): Overrides the text and input privacy level.
  • sessionReplayTouchPrivacy(TouchPrivacy): Overrides the touch privacy level.

Current Limitations

  • Compose replay relies on semantic nodes and component mapping, pixel-perfect restoration is not guaranteed.
  • Currently supports replay of common components like text, input fields, images, buttons, switches, sliders, radio buttons, checkboxes, tabs, and container classes.
  • Brush backgrounds are not yet supported. For example, linear gradients, radial gradients, etc., will not be restored with their original gradient effects. It is recommended to use solid color backgrounds for key demonstration areas.

Code and Configuration Reference