Skip to content

iOS SESSION REPLAY

Prerequisites

  • Ensure you have set up and initialized the FTMobileSDK RUM configuration and enabled View monitoring collection.
  • iOS Session Replay version support: SDK.Version >= 1.6.0.
  • It is recommended to prioritize using the stable release version indicated by the badge at the top of the document. Using pre-release versions such as alpha or beta is no longer recommended.
  • If you wish to integrate advanced capabilities early, follow the latest features, or track changes not yet officially released, you can visit the GitHub repository for the iOS SDK and its changelog: GuanceCloud/datakit-ios

Configuration

Link the FTSessionReplay feature component from the FTMobileSDK library to your project based on your package manager:

CocoaPods

pod 'FTMobileSDK', 'last_version'
pod 'FTMobileSDK/FTSessionReplay', 'last_version' # Added

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/GuanceCloud/FTMobileSDK.git",
             from: "last_version")
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "FTMobileSDK", package: "FTMobileSDK")
            .product(name: "FTSessionReplay", package: "FTMobileSDK"), //Added
        ]),
]

Carthage/Framework

Supported in SDK version 1.6.2 and above

When using Carthage or manually integrating the Framework, in addition to the base SDK, you also need to add the FTSessionReplay session replay component to the Frameworks of the main project's Target.

FTSessionReplay is the session replay feature component, which depends on the FTMobileSDK base capabilities and cannot be used alone.

Code Sample

#import <FTMobileSDK/FTRumSessionReplay.h>
// or
#import <FTSessionReplay/FTRumSessionReplay.h>

   FTSessionReplayConfig *srConfig = [[FTSessionReplayConfig alloc]init];
   srConfig.touchPrivacy = FTTouchPrivacyLevelShow;
   srConfig.textAndInputPrivacy = FTTextAndInputPrivacyLevelMaskSensitiveInputs;
   srConfig.imagePrivacy = FTImagePrivacyLevelMaskNonBundledOnly;
   srConfig.sampleRate = 100;
   [[FTRumSessionReplay sharedInstance] startWithSessionReplayConfig:srConfig];
   let srConfig = FTSessionReplayConfig.init()
   srConfig.touchPrivacy = .show
   srConfig.textAndInputPrivacy = .maskSensitiveInputs
   srConfig.imagePrivacy = .maskNonBundledOnly
   srConfig.sampleRate = 100
   FTRumSessionReplay.shared().start(with: srConfig)
Property Type Required Description
sampleRate int No Sampling rate. Value range [0,100], where 0 means no collection, 100 means full collection. Default is 100. This sampling rate is applied on top of the RUM sampling rate.
sessionReplayOnErrorSampleRate int No Sets the error collection rate. When a session is not sampled by sampleRate, if an error occurs during the session, data from the 1 minute before the error can be collected. Value range [0,100], where 0 means no collection, 100 means full collection. Default is 0. Supported in SDK version 1.6.2 and above.
privacy FTSRPrivacy No Sets the privacy level for content masking in Session Replay. Default is FTSRPrivacyMask.
Masking process: Text is replaced with * or #.
FTSRPrivacyAllow: Records text and input except for sensitive input controls, shows user touches, and records all images.
FTSRPrivacyMaskUserInput: Masks input elements and hides user touches, only records SF Symbols and images loaded via [UIImage imageNamed:] / UIImage(named:) that are bundled with the App.
FTSRPrivacyMask: Masks all text, input, touches, and images.
Deprecated soon, compatible for now. It is recommended to use touchPrivacy, textAndInputPrivacy, imagePrivacy for fine-grained privacy level settings.
touchPrivacy FTTouchPrivacyLevel No Available privacy levels for touch masking in session replay. Default is FTTouchPrivacyLevelHide.
FTTouchPrivacyLevelShow: Shows all user touches.
FTTouchPrivacyLevelHide: Masks all user touches.
Once set, overrides the configuration in privacy.
Supported in SDK version 1.6.1 and above.
textAndInputPrivacy FTTextAndInputPrivacyLevel No Available privacy levels for text and input masking in session replay. Default is FTTextAndInputPrivacyLevelMaskAll.
FTTextAndInputPrivacyLevelMaskSensitiveInputs: Shows all text except sensitive inputs, e.g., password fields.
FTTextAndInputPrivacyLevelMaskAllInputs: Masks all input fields, e.g., UITextField, UISwitch, UISlider, etc.
FTTextAndInputPrivacyLevelMaskAll: Masks all text and input.
Once set, overrides the configuration in privacy.
Supported in SDK version 1.6.1 and above.
imagePrivacy FTImagePrivacyLevel No Available privacy levels for image masking in session replay. Default is FTImagePrivacyLevelMaskAll.
FTImagePrivacyLevelMaskNonBundledOnly: Only records SF Symbols and images loaded via [UIImage imageNamed:] / UIImage(named:) that are bundled with the App. Images downloaded from the network or generated at runtime are masked.
FTImagePrivacyLevelMaskAll: Masks all images.
FTImagePrivacyLevelMaskNone: Records all images, including those downloaded from the network or generated at runtime. Ensure images contain no sensitive content before using this setting.
Once set, overrides the configuration in privacy.
Supported in SDK version 1.6.2 and above.
enableLinkRUMKeys NSArray No When enabled, associates corresponding fields from the RUM Context to the session replay data based on the set keys. Can be used to implement session replay data shunting.
Supported in SDK version 1.6.2 and above.

Privacy Overrides

Supported in SDK version 1.6.1 and above

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

View-level privacy overrides:

  • Supports overriding text and input masking levels, touch masking levels, and image masking levels (supported in SDK version 1.6.2 and above).
  • Supports setting specific views to be completely hidden.

Note:

  • To ensure correct override identification, they should be applied as early as possible in the view's lifecycle. This prevents the session replay from processing the view before the override settings are applied.
  • Privacy overrides affect the view and its subviews. 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 subviews.
  • Privacy override priority: Subview > Parent view > Global settings

Text and Input Override

To override text and input privacy, use sessionReplayPrivacyOverrides.textAndInputPrivacy on a view instance and set it to a value from the FTTextAndInputPrivacyLevelOverride enumeration. To remove an existing override rule, simply set this property to FTTextAndInputPrivacyLevelOverrideNone.

#import <FTMobileSDK/UIView+FTSRPrivacy.h>
   // Set text and input override for a specific view
   myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = FTTextAndInputPrivacyLevelOverrideMaskAll;
   // Remove text and input override settings for the view
   myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = FTTextAndInputPrivacyLevelOverrideNone;
   // Set text and input override for a specific view
   myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = .maskAll
   // Remove text and input override settings for the view
   myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = .none

Touch Override

To override touch privacy, use sessionReplayPrivacyOverrides.touchPrivacy on a view instance and set it to a value from the FTTouchPrivacyLevelOverride enumeration. To remove an existing override rule, simply set this property to FTTouchPrivacyLevelOverrideNone.

#import <FTMobileSDK/UIView+FTSRPrivacy.h>
   // Set touch override for a specific view
   myView.sessionReplayPrivacyOverrides.touchPrivacy = FTTouchPrivacyLevelOverrideShow;
   // Remove touch override settings for the view
   myView.sessionReplayPrivacyOverrides.touchPrivacy = FTTouchPrivacyLevelOverrideNone;
   // Set touch override for a specific view
   myView.sessionReplayPrivacyOverrides.touchPrivacy = .show;
   // Remove touch override settings for the view
   myView.sessionReplayPrivacyOverrides.touchPrivacy = .none;

Image Override

Supported in SDK version 1.6.2 and above

To override image privacy, use sessionReplayPrivacyOverrides.imagePrivacy on a view instance and set it to a value from the FTImagePrivacyLevelOverride enumeration. To remove an existing override rule, simply set this property to FTImagePrivacyLevelOverrideNone.

Available image override levels:

  • FTImagePrivacyLevelOverrideMaskNonBundledOnly: Only records SF Symbols and images loaded via [UIImage imageNamed:] / UIImage(named:) that are bundled with the App. Images downloaded from the network or generated at runtime are masked.
  • FTImagePrivacyLevelOverrideMaskAll: Masks all images.
  • FTImagePrivacyLevelOverrideMaskNone: Records all images, including those downloaded from the network or generated at runtime. Ensure images contain no sensitive content before using this setting.
#import <FTMobileSDK/UIView+FTSRPrivacy.h>
   // Set image override for a specific view
   myImageView.sessionReplayPrivacyOverrides.imagePrivacy = FTImagePrivacyLevelOverrideMaskNonBundledOnly;
   // Remove image override settings for the view
   myImageView.sessionReplayPrivacyOverrides.imagePrivacy = FTImagePrivacyLevelOverrideNone;
   // Set image override for a specific view
   myImageView.sessionReplayPrivacyOverrides.imagePrivacy = .maskNonBundledOnly
   // Remove image override settings for the view
   myImageView.sessionReplayPrivacyOverrides.imagePrivacy = .none

Hide Element Override

For sensitive elements that need to be completely hidden, use sessionReplayPrivacyOverrides.hide 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 subviews will not be recorded.

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

#import <FTMobileSDK/UIView+FTSRPrivacy.h>
   // Mark a specific view with hide element override
   myView.sessionReplayPrivacyOverrides.hide = YES;
   // Remove hide element override settings for the view
   myView.sessionReplayPrivacyOverrides.hide = NO;
   // Mark a specific view with hide element override
   myView.sessionReplayPrivacyOverrides.hide = true;
   // Remove hide element override settings for the view
   myView.sessionReplayPrivacyOverrides.hide = false;

Webview Session Replay

Supported in SDK version 1.6.2 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();

Sample Code and Configuration Reference