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 displayed by the badge at the top of the document. It is no longer recommended to use pre-release versions such as
alpha,beta. -
If you wish to integrate advanced capabilities early, follow the latest features, or track changes not yet officially released, you can go to GitHub to follow the iOS SDK repository and related changelogs: GuanceCloud/datakit-ios
Configuration¶
Link the FTSessionReplay feature component from the FTMobileSDK library to your project according to your package manager:
CocoaPods¶
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 Framework, in addition to the base SDK, you also need to add the FTSessionReplay SESSION REPLAY component to the Frameworks of the main project Target.
FTSessionReplay is the SESSION REPLAY feature component, which depends on the basic capabilities of FTMobileSDK 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;
// To collect SwiftUI Views, enable this in SDK version 1.6.5 and above
srConfig.enableSwiftUI = YES;
srConfig.sampleRate = 100;
[[FTRumSessionReplay sharedInstance] startWithSessionReplayConfig:srConfig];
let srConfig = FTSessionReplayConfig.init()
srConfig.touchPrivacy = .show
srConfig.textAndInputPrivacy = .maskSensitiveInputs
srConfig.imagePrivacy = .maskNonBundledOnly
// To collect SwiftUI Views, enable this in SDK version 1.6.5 and above
srConfig.enableSwiftUI = true
srConfig.sampleRate = 100
FTRumSessionReplay.shared().start(with: srConfig)
| Property | Type | Required | Description |
|---|---|---|---|
| sampleRate | int | No | Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default is 100. This sampling rate is based on 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], 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 treatment: text is replaced with * or #. FTSRPrivacyAllow: Records text and input content except for sensitive input controls, displays 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:) and bundled with the App.FTSRPrivacyMask: Masks all text, input, touches, and images.Will be deprecated soon, can be used compatibly, it is recommended to prioritize using 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 touchesFTTouchPrivacyLevelHide: Masks all user touchesAfter setting, overrides the configuration of privacySupported in SDK version 1.6.1 and above |
| textAndInputPrivacy | FTTextAndInputPrivacyLevel | No | Available privacy levels for text and input masking in Session Replay. Default is FTTextAndInputPrivacyLevelMaskAllFTTextAndInputPrivacyLevelMaskSensitiveInputs: Shows all text except sensitive inputs, e.g., password inputsFTTextAndInputPrivacyLevelMaskAllInputs: Masks all input fields, e.g., UITextField, UISwitch, UISliderFTTextAndInputPrivacyLevelMaskAll: Masks all text and inputsAfter setting, overrides the configuration of privacySupported 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:) and 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. Please confirm images do not contain sensitive content before using.After setting, overrides the configuration of privacySupported in SDK version 1.6.2 and above |
| enableSwiftUI | BOOL | No | Enables Session Replay collection for SwiftUI Views, default is NO. Supported in SDK version 1.6.5 and above |
| enableLinkRUMKeys | NSArray | No | After enabling, 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 level, touch masking level, and image masking level (supported in SDK version 1.6.2 and above)
- Supports setting specific views to be completely hidden
Note:
- To ensure correct identification of overrides, 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.
- 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 the 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 the specified view
myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = FTTextAndInputPrivacyLevelOverrideMaskAll;
// Remove the text and input override setting for the view
myView.sessionReplayPrivacyOverrides.textAndInputPrivacy = FTTextAndInputPrivacyLevelOverrideNone;
Touch Override¶
To override touch privacy, use sessionReplayPrivacyOverrides.touchPrivacy on the 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 the specified view
myView.sessionReplayPrivacyOverrides.touchPrivacy = FTTouchPrivacyLevelOverrideShow;
// Remove the touch override setting for the view
myView.sessionReplayPrivacyOverrides.touchPrivacy = FTTouchPrivacyLevelOverrideNone;
Image Override¶
Supported in SDK version 1.6.2 and above
To override image privacy, use sessionReplayPrivacyOverrides.imagePrivacy on the 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:)and 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. Please confirm images do not contain sensitive content before using.
#import <FTMobileSDK/UIView+FTSRPrivacy.h>
// Set image override for the specified view
myImageView.sessionReplayPrivacyOverrides.imagePrivacy = FTImagePrivacyLevelOverrideMaskNonBundledOnly;
// Remove the image override setting for the view
myImageView.sessionReplayPrivacyOverrides.imagePrivacy = FTImagePrivacyLevelOverrideNone;
Hidden 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.
Webview Session Replay¶
Supported in SDK version 1.6.2 and above
For WebView Session Replay, you need to integrate the Web Monitoring SDK on the WebView access page and enable Session Replay in the Webview.