Session Replay iOS Plugin

This article covers the installation of Session Replay using the iOS plugin. If your app is already instrumented with the the Amplitude iOS Swift SDK or legacy Amplitude iOS SDK, use this option.

If you use Segment through their Analytics-Swift SDK and Amplitude (Actions) destination, choose the Segment Plugin.

If you use a provider other than Amplitude for in-product analytics, 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, this means the main view and all it's child views recursively. It then replays these changes to build a video-like replay. For example, 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 to the view as a diff. When you watch the replay of a session, Session Replay applies each diff back to the original view tree in sequential order, to construct the replay. Session replays have no maximum length.

Report issues

To report issues with Session Replay for iOS, see the AmplitudeSessionReplay-ios GitHub repository.

Before you begin

The method you use depends on the version of the Amplitude Android SDK you use.

Use the latest version of the iOS Session Replay plugin above 0.0.11.

The Session Replay iOS Plugin requires that:

  1. Your application runs on iOS or iPadOS.
  2. You are using 1.9.0 or higher of the iOS Swift SDK.
Use the latest version of the Session Replay Middleware above version 0.0.11. For a list of available versions, see all release versions on GitHub.

The Session Replay Middleware requires that:

Supported iOS versions

Session replay supports a minimum target version of iOS 13. Over 91% of Apple devices are running iOS 16 or later, per App Store statistics.

Quickstart

Add the latest version of the plugin to your project dependencies.

Swift Package Manager

Add Session Replay as a dependency in your Package.swift file, or the Package list in Xcode.

1dependencies: [
2 .package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", .branch("main"))
3]

For integrating with Amplitude-Swift, use the AmplitudeSwiftSessionReplayPlugin target.

1.product(name: "AmplitudeSwiftSessionReplayPlugin", package: "AmplitudeSessionReplay")

CocoaPods

Add the core library and the plugin to your Podfile.

1pod 'AmplitudeSessionReplay', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git'
2pod 'AmplitudeSwiftSessionReplayPlugin', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git'

Configure your application code

1import AmplitudeSwift
2import AmplitudeSwiftSessionReplayPlugin
3 
4// Initialize Amplitude Analytics SDK instance
5let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY))
6 
7// Create and Install Session Replay Plugin
8// Recording will be handled automatically
9amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(sampleRate: 1.0))

Swift Package Manager

Add Session Replay as a dependency in your Package.swift file, or the Package list in Xcode.

1dependencies: [
2 .package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", .branch("main"))
3]

For integrating with Amplitude-iOS, use the AmplitudeiOSSessionReplayMiddleware target.

1.product(name: "AmplitudeiOSSessionReplayMiddleware", package: "AmplitudeSessionReplay")

CocoaPods

Add the core library and the middleware to your Podfile.

1pod 'AmplitudeSessionReplay', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git'
2pod 'AmplitudeiOSSessionReplayMiddleware', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git'

Configure your application code

1import Amplitude
2import AmplitudeiOSSessionReplayMiddleware
3 
4// Initialize Amplitude Analytics SDK instance
5 
6let amplitude = Amplitude.instance()
7 
8// Although not required, we recommend enabling session start and end events when enabling Session Replay
9amplitude.defaultTracking.sessions = true
10 
11// Create and Install Session Replay Middleware
12// Recording will be handled automatically
13amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(sampleRate: 0.1))
14 
15amplitude.initializeApiKey(API_KEY)

Configuration

Pass the following option when you initialize the Session Replay plugin:

Name Type Required Default Description
sampleRate number 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.
enableRemoteConfig boolean No true Enables or disables remote configuration for this instance of Session Replay.

Remote configuration

Enable remote configuration to set Sample Rate and Masking Level in Amplitude.

Remote configuration and testing

With enableRemoteConfig set to true, settings you define in Amplitude take precedence over settings you define locally in the SDK. For this reason, 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.

Mask level

Session Replay for iOS supports three levels of masking, configurable with the the maskLevel config option.

Use this option in the Session Replay configuration.

Mask level Description
light Masks all password, email address, 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.

1import 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.

Privacy Modifiers for SwiftUI

Session Replay provides an extension on View to manage privacy. Import the Session Replay Library to access it.

1import 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.

User opt-out

The Session Replay plugin follows the Ampltiude-Swift SDK's optOut setting, and doesn't support user opt-outs on its own.

1// Set optOut on the Amplitude SDK
2let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
3 optOut: true,
4 /* other configuration */))
5amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(/* session replay options */))

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:

1// Set serverZone on the Amplitude SDK
2let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
3 serverZone: .EU,
4 /* other configuration */))
5amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(/* session replay options */))

Sampling rate

By default, Session Replay captures 0% of sessions for replay. Use the sampleRate configuration option to set the percentage of total sessions that Session Replay captures. For example:

To set the sampleRate consider the monthly quota on your Session Replay plan. For example, if your monthly quota is 2,500,000 sessions, and you average 3,000,000 monthly sessions, your quota is 83% of your average sessions. In this case, to ensure sampling lasts through the month, set sampleRate to .83 or lower.

Keep the following in mind as you consider your sample rate:

  • When you reach your monthly session quota, Amplitude stops capturing sessions for replay.
  • Session quotas reset on the first of every month.
  • Use sample rate to distribute your session quota over the course of a month, rather than using your full quota at the beginning of the month.
  • To find the best sample rate, Amplitude recommends that you start low, for example .01. If this value doesn't capture enough replays, raise the rate over the course of a few days. For ways to monitor the number of session replays captured, see View the number of captured sessions.
  • Replays with processing errors don't count toward your monthly quota. Replays with a retention error message have already been counted against the quota, when the session was still in the retention period.

1// This configuration samples 1% of all sessions
2amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(sampleRate: 0.01))

Disable replay collection

Once enabled, Session Replay runs on your app until either:

  • The user leaves your app
  • You call amplitude.remove(plugin: sessionReplayPlugin)

Call amplitude.remove(plugin: sessionReplayPlugin) 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

This requires keeping a reference to the SessionReplayPlugin instance let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(/* session replay options */).

Call amplitude.add(plugin: sessionReplayPlugin) to re-enable replay collection when the return to an unrestricted area of your app.

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, you can create a feature flag that targets a specific user group, and add that to your initialization logic:

1import AmplitudeSwift
2import AmplitudeSwiftSessionReplayPlugin
3 
4// Your existing initialization logic with Amplitude-Swift SDK
5let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
6 /* other configuration */))
7 
8if (nonEUCountryFlagEnabled) {
9 // Create and Install Session Replay Plugin
10 let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(sampleRate: 0.1)
11 amplitude.add(plugin: sessionReplayPlugin)
12}

Data retention, deletion, and privacy

Session replay uses existing Amplitude tools and APIs to handle privacy and deletion requests.

Consent management and Session Replay

While privacy laws and regulations vary across states and countries, certain constants exist, including the requirements to disclose in a privacy notice the categories of personal information you are collecting, the purposes for its use, and the categories of third parties with which personal information is shared. When implementing a session replay tool, you should review your privacy notice to make sure your disclosures remain accurate and complete. And as a best practice, review your notice with legal counsel to make sure it complies with the constantly evolving privacy laws and requirements applicable to your business and personal information data practices.

Retention period

If your Amplitude plan includes Session Replay, Amplitude retains raw replay data for 30 days from the date of ingestion.

If you purchase extra session volume, Amplitude retains raw replay data for 90 days from the date of ingestion. If you need a more strict policy, contact Amplitude support to set the value to 30 days.

Changes to the retention period impact replays ingested after the change. Sessions captured and ingested before a retention period change retain the previous retention period.

Retention periods are set at the organization level. Replays that are outside of the retention period aren't viewable in Amplitude.

DSAR API

The Amplitude DSAR API returns metadata about session replays, but not the raw replay data. All events that are part of a session replay include a [Amplitude] Session Replay ID event property. This event provides information about the sessions collected for replay for the user, and includes all metadata collected with each event.

1{
2 "amplitude_id": 123456789,
3 "app": 12345,
4 "event_time": "2020-02-15 01:00:00.123456",
5 "event_type": "first_event",
6 "server_upload_time": "2020-02-18 01:00:00.234567",
7 "device_id": "your device id",
8 "user_properties": { ... }
9 "event_properties": {
10 "[Amplitude] Session Replay ID": "cb6ade06-cbdf-4e0c-8156-32c2863379d6/1699922971244"
11 }
12 "session_id": 1699922971244,
13}

Data deletion

Session Replay uses Amplitude's User Privacy API to handle deletion requests. Successful deletion requests remove all session replays for the specified user.

When you delete the Amplitude project on which you use Session Replay, Amplitude deletes that replay data.

Bot filter

Session Replay uses the same block filter available in the Amplitude app. Session Replay doesn't block traffic based on event or user properties.

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
    • MKMapView
    • WKWebView

Multiple Amplitude instances

Session Replay supports attaching to a single instance of the Amplitude SDK. If you have more than one instance instrumented in your application, make sure to start Session Replay on the instance that most relates to your project.

Troubleshooting

For more information about individual statuses and errors, see the Session Replay Ingestion Monitor.

Replay length and session length don't match

In some scenarios, the length of a replay may exceed the time between the [Amplitude] Start Session and [Amplitude] End Session events. This happens when a user closes the [Amplitude] End Session occurs, but before the iOS SDK and Session Replay plugin can process it. When the user uses the app again, the SDK and plugin process the event and send it to Amplitude, along with the replay. You can verify this scenario occurs if you see a discrepancy between the End Session Client Event Time and the Client Upload Time.

Session replays don't appear in Amplitude

Session replays may not appear in Amplitude due to:

  • Lack of connectivity
  • No events triggered through the iOS SDK in the current session
  • Sampling

Lack of connectivity

Ensure your app has access to the internet then try again.

No events triggered through the iOS SDK in the current session

Session Replay requires that at least one event in the user's session has the [Amplitude] Session Replay ID property. If you instrument your events with an analytics provider other than Amplitude, the iOS SDK may send only the default Session Start and Session End events, which don't include this property.

For local testing, you can force a Session Start event to ensure that Session Replay functions.

  1. In Amplitude, in the User Lookup Event Stream, you should see a Session Start event that includes the [Amplitude] Session Replay ID property. After processing, the Play Session button should appear for that session.

Sampling

As mentioned above, the default sampleRate for Session Replay is 0. Update the rate to a higher number. For more information see, Sampling rate.

Some sessions don't include the Session Replay ID property

Session replay doesn't require that all events in a session have the [Amplitude] Session Replay ID property, only that one event in the session has it. Reasons why [Amplitude] Session Replay ID may not be present in an event include:

  • The user may have opted out or the session may not be part of the sample set given the current sampleRate. Increasing the sampleRate captures more sessions.
  • Amplitude events may still send through your provider, but additionalEventProperties doesn't return the [Amplitude] Session Replay ID property. This can result from optOut and sampleRate configuration settings. Check that optOut and sampleRate are set to include the session.

Session Replay processing errors

In general, replays should be available within minutes of ingestion. Delays or errors may be the result of one or more of the following:

  • Mismatching API keys or Device IDs. This can happen if Session Replay and standard event instrumentation use different API keys or Device IDs.
  • Session Replay references the wrong project.
  • Short sessions. If a users bounces within a few seconds of initialization, the SDK may not have time to upload replay data.
  • Replays older than the set retention period (defaults to 90 days).
Was this page helpful?

Thanks for your feedback!

October 30th, 2024

Need help? Contact Support

Visit Amplitude.com

Have a look at the Amplitude Blog

Learn more at Amplitude Academy

© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.