For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.
Session Replay iOS Segment Integration
This article covers installation of Session Replay using the Session Replay iOS Segment plugin. Use this option if your app uses Segment's Analytics-Swift library and Amplitude (Actions) destination.
If your app uses an Amplitude iOS SDK, use the Session Replay iOS SDK Plugin.
If you use Segment with other options, choose the standalone implementation.
Session Replay and performance
Amplitude built Session Replay to minimize impact on the performance of the iOS apps in which it's installed by:
- Asynchronously processing replay data, to avoid blocking the main user interface thread. The main thread must be used to interact with the view hierarchy, but all processing is performed on a background queue.
- Using batching and lightweight compression to reduce the number of network connections and bandwidth.
- Optimizing view hierarchy processing. Contact Amplitude if you experience issues with hierarchy processing.
Session Replay captures changes to an app's view tree: the main view and all its child views recursively. Session Replay then replays these changes to build a video-like replay. At the start of a session, Session Replay captures a full snapshot of the app's view tree. As the user interacts with the app, Session Replay captures each change as a diff. When you watch the replay, Session Replay applies each diff back to the original view tree in sequential order. Session replays have no maximum length.
Report issues
To report issues with Session Replay for iOS, go to the AmplitudeSessionReplay-ios GitHub repository.
Before you begin
The Session Replay iOS Segment Plugin requires that:
- Your application runs on iOS or iPadOS.
- You use Segment's Analytics-Swift library for ingestion.
- You use Segment's Amplitude (Actions) destination.
- You use Segment's Amplitude Plugin.
Supported iOS versions
Session Replay supports a minimum target version of iOS 13.
Quickstart
Add the latest version of the plugin to your project dependencies.
The Segment plugin is available through Swift Package Manager only. Add Session Replay as a dependency in your Package.swift file or the Package list in Xcode.
dependencies: [
.package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", from: "0.12.8")
]
To integrate with Analytics-Swift, use the AmplitudeSegmentSessionReplayPlugin target.
.product(name: "AmplitudeSegmentSessionReplayPlugin", package: "AmplitudeSessionReplay")
Configure your application code:
import AmplitudeSegmentSessionReplayPlugin
import Segment
import SegmentAmplitude
// Initialize Segment
let analytics = Analytics(configuration: config)
// Ensure Segment's AmplitudeSession plugin is added before AmplitudeSegmentSessionReplayPlugin
analytics.add(plugin: AmplitudeSession())
// Initialize AmplitudeSegmentSessionReplayPlugin with your Amplitude API key
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.1))
Configuration
Pass the following option when you initialize the Session Replay plugin:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
amplitudeApiKey | String | Yes | n/a | Sets the Amplitude API key. The Segment plugin requires this value to send replays to Amplitude. |
sampleRate | Float | No | 0 | Use this option to control how many sessions to select for replay collection. The number should be a decimal between 0 and 1 (for example, 0.4), representing the fraction of sessions to have randomly selected for replay collection. Over a large number of sessions, 0.4 would select 40% of those sessions. |
serverZone | ServerZone | No | .US | EU or US. Sets the Amplitude server zone. Set this to EU for Amplitude projects created in EU data center. |
enableRemoteConfig | Bool | No | true | Enables or disables remote configuration for this instance of Session Replay. |
autoStart | Bool | No | true | Controls whether Session Replay begins capturing automatically when it initializes. |
maskLevel | MaskLevel | No | .medium | Sets how much on-screen content Session Replay masks. Use .light, .medium, or .conservative. For more detail, refer to Mask level. |
captureWebViews | Bool | No | false | Enables capture of web view content. By default, Session Replay blocks web views. |
webviewMappings | [String: String] | No | [:] | Maps substrings in captured web view content to replacement values. When you enable captureWebViews, Session Replay applies each entry as a case-insensitive find-and-replace on the web view recording data before upload. This is an advanced option; most apps leave it empty. |
recordLogOptions.logCountThreshold | Int | No | 1000 | Use this option to configure the maximum number of logs per session. |
recordLogOptions.maxMessageLength | Int | No | 2000 | Use this option to configure the maximum length of a log message. |
quality | QualityProfile | No | .high | Controls capture and encoding quality (for example, frame rate and image resolution). Use .low, .medium, or .high to balance replay fidelity with performance and storage. Use QualityProfile.automatic to let the SDK choose a profile based on the device. |
uploadConfig | UploadConfig | No | UploadConfig() | Controls when Session Replay uploads data. Use UploadConfig(disableMeteredUploads: true) to pause uploads on metered networks (for example, cellular). |
Remote configuration
Enable remote configuration to set Sample Rate and Masking Level in Amplitude.
Remote configuration and testing
When you enable remote configuration, settings you define in Amplitude take precedence over settings you define locally in the SDK. As a result, while testing your application, you should disable remote configuration to ensure you can set sampleRate to 1, and ensure you capture test sessions.
Block on-screen data
Session Replay supports three ways to block sensitive on-screen data. Masking setting for WebViews is in the Web view support section.
Mask level
Session Replay for iOS supports three levels of masking, configurable with the maskLevel option.
Use this option in the Session Replay configuration.
| Mask level | Description |
|---|---|
light | Masks all passwords, email addresses, credit card numbers, and phone numbers. |
medium | Masks all editable text views. |
conservative | Masks all text views. |
Privacy methods for UIKit
Session Replay provides an extension on UIView to manage privacy. Import the Session Replay library to access it.
import AmplitudeSessionReplay
| Variable | Description |
|---|---|
amp_isBlocked | Set view.amp_isBlocked to selectively replace a view and its subviews with a placeholder in session replays. UITextViews and UITextFields are automatically blocked. To unblock a view that is masked by default, set the this value to false |
Privacy Modifiers for SwiftUI
Session Replay provides an extension on View to manage privacy. Import the Session Replay Library to access it.
import AmplitudeSessionReplay
| Modifier | Description |
|---|---|
amp_setBlocked(_ blocked: Bool) | Add the amp_setBlocked() modifier to a View to selectively replace a view and its subviews with a placeholder in session replays. To unblock a view that is masked by default, set the this value to false |
User opt-out
Set optOut on the plugin to indicate that a user opted out of session replay.
// Pass a boolean value to indicate a users opt-out status
amplitudeSegmentSessionReplayPlugin.optOut = true
EU data residency
Session Replay is available to Amplitude Customers who use the EU data center. Set the serverZone configuration option to EU during initialization. For example:
// Set serverZone on the AmplitudeSegmentSessionReplayPlugin
let plugin = AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.1,
serverZone: .EU)
Sampling rate
By default, Session Replay captures 0% of sessions for replay. Use your SDK's sampleRate configuration option to set the proportion of sessions to capture.
For manual and dynamic sampling, quota planning, and quota accounting, go to Configure Session Replay sampling.
// This configuration samples 1% of all sessions
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.01))
Recording quality
Choose a quality profile to balance replay fidelity with performance and storage. Lower profiles use a lower capture frame rate and lower image resolution. Higher profiles use a higher frame rate and higher resolution. Use QualityProfile.automatic to let the SDK select a profile based on the device. For example, the SDK selects high on newer devices and lower on older ones.
// Use automatic profile selection based on device
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.1,
quality: .automatic))
// Or set a fixed profile (low, medium, or high)
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.1,
quality: .medium))
Disable uploads on metered networks
Avoid using the user's cellular data by pausing Session Replay uploads while the device uses a metered network. Session Replay still records data locally. Uploads resume when the device reconnects to Wi‑Fi or another non-metered connection.
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 0.1,
uploadConfig: UploadConfig(disableMeteredUploads: true)))
Disable replay collection
After you enable Session Replay, it runs on your app until either:
- The user leaves your app.
- You call
amplitudeSegmentSessionReplayPlugin.stop(). - You remove the plugin from Segment with
analytics.remove(plugin: amplitudeSegmentSessionReplayPlugin).
Call amplitudeSegmentSessionReplayPlugin.stop() before a user navigates to a restricted area of your app to disable replay collection while the user is in that area.
Keep a reference
Keep a reference to the SessionReplayPlugin instance: let amplitudeSegmentSessionReplayPlugin = AmplitudeSegmentSessionReplayPlugin(/* session replay options */).
Call amplitudeSegmentSessionReplayPlugin.start() to re-enable replay collection when the user returns to an unrestricted area of your app.
To capture only specific screens, initialize the plugin with autoStart: false so it doesn't start on launch, then call start() and stop() as the user enters and leaves those screens:
// Add the plugin once, without starting capture
let amplitudeSegmentSessionReplayPlugin = AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
sampleRate: 1.0,
autoStart: false)
analytics.add(plugin: amplitudeSegmentSessionReplayPlugin)
// Start capture when the user enters a screen you want to record
amplitudeSegmentSessionReplayPlugin.start()
// Stop capture when the user leaves that screen
amplitudeSegmentSessionReplayPlugin.stop()
You can also use a feature flag product like Amplitude Experiment to create logic that enables or disables replay collection based on criteria like location. For example, create a feature flag that targets a specific user group, then add that flag to your initialization logic:
import AmplitudeSegmentSessionReplayPlugin
import Segment
import SegmentAmplitude
// Your existing initialization logic with Segment
let analytics = Analytics(configuration: config)
analytics.add(plugin: AmplitudeSession())
if (nonEUCountryFlagEnabled) {
// Create and Install Session Replay Plugin
let amplitudeSegmentSessionReplayPlugin = AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY, sampleRate: 0.1)
analytics.add(plugin: amplitudeSegmentSessionReplayPlugin)
}
Web view support (Beta)
By default, Session Replay blocks web views in a capture. To enable capture of all WebView components, set captureWebViews to true in the Session Replay configuration.
To mask specific WebView components, use the privacy methods described in Block on-screen data.
// UIKit
webView.amp_isBlocked = false
Map View Support (Alpha)
Session Replay supports capturing map views in iOS applications. To enable map view capture, unmask the map view in your implementation.
// UIKit
mapView.amp_isBlocked = false
// SwiftUI
Map().amp_setBlocked(false)
Log Recording
Availability
AmplitudeSessionReplay 0.8.0 and later support log recording.
Session Replay supports recording logs in iOS applications. Configure the limits with recordLogOptions when you initialize the integration, then send log messages through recordLog(level:message:date:).
import AmplitudeSessionReplay
let sessionReplay = SessionReplay(
apiKey: API_KEY,
recordLogOptions: .init(logCountThreshold: 2000, maxMessageLength: 4000)
)
sessionReplay.recordLog(level: .error, message: "This is an error log")
If you have implemented a log system, you can make single-point modifications to integrate log recording functionality. See the following examples for more information.
CocoaLumberjack
If you use CocoaLumberjack, you can integrate it with a custom logger provider.
class AmplitudeLogRecordLogger: DDAbstractLogger {
private weak var plugin: SessionReplayPlugin?
init(_ plugin: SessionReplayPlugin) {
self.plugin = plugin
}
override func log(message logMessage: DDLogMessage) {
let recordLevel: RecordLogLevel
switch logMessage.flag {
case .error:
recordLevel = .error
case .warning:
recordLevel = .warn
case .info:
recordLevel = .log
default:
return
}
plugin?.recordLog(level: recordLevel,
message: logMessage.message,
date: logMessage.timestamp)
}
}
let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin()
amplitude.add(plugin: sessionReplayPlugin)
DDLog.add(AmplitudeLogRecordLogger(sessionReplayPlugin))
React Native
If you use console log or react-native-logs with consoleTransport, you can integrate it with RCTAddLogFunction.
RCTAddLogFunction { level, source, fileName, lineNumber, message in
let recordLevel: RecordLogLevel
switch level {
case .error:
recordLevel = .error
case .warning:
recordLevel = .warn
case .info:
recordLevel = .log
case .fatal:
recordLevel = .error
case .trace:
recordLevel = .init("trace")
default:
return
}
self.sessionReplayPlugin.recordLog(level: recordLevel, message: message)
}
Data retention, deletion, and privacy
Review consent guidance when you implement capture.
Retention period
For native and Flutter SDK retention guidance and the effective date of changes, go to the Session Replay data lifecycle reference.
DSAR API
For replay metadata returned by the DSAR API, go to Session Replay DSAR metadata.
Data deletion
For user and project deletion behavior, go to Session Replay data deletion.
Bot filter
For bot filtering and property-filter restrictions, go to Session Replay bot filtering.
Session Replay storage
If a user opts out tracking in your app, use the optOut configuration option to disable replay collection for that user.
Session Replay temporarily stores replay data data on the file system before it is uploaded. At every initialization, the least recent replays are trimmed to bring the total disk usage down to a maximum size.
Known limitations
Keep the following limitations in mind as you implement Session Replay:
Session Replay doesn't stitch together replays from a single user across multiple projects. For example:
- You instrument multiple apps as separate Amplitude projects with Session Replay enabled in each.
- A known user begins on one app, and then switch to another.
- Amplitude captures both sessions.
- The replay for each session is available for view in the corresponding host project.
The User Sessions chart doesn't show session replays if your organization uses a custom session definition.
Session Replay cannot capture the following iOS views:
- Out-of-process iOS views, such as SFSafariViewController
- AVPlayerLayer backed views
Was this helpful?