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.
セッションリプレイ iOS プラグイン
この記事では、iOS プラグインを使用して セッションリプレイ をインストールする方法について説明します。 アプリがすでにAmplitude iOS Swift SDKまたはレガシーAmplitude iOS SDKを使用している場合は、このオプションを使用してください。
Analytics-Swift SDKとAmplitude(アクション)の送信先経由でセグメントを使用する場合は、セグメントプラグインを選択してください。
製品内アナリティクスにAmplitude以外のプロバイダーを使用している場合は、スタンドアロンの実装を選択してください。
Unified SDK
Unified SDK for Swiftをインストールすることで、他のAmplitude製品(アナリティクス、実験)とともにセッションリプレイにアクセスできます。Unified SDKは、Amplitudeのすべての機能に単一のエントリーポイントを提供し、すべてのコンポーネントの初期化と設定を処理することで統合を簡素化します。
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.
セッションリプレイは、メインビューとそのすべての子ビューを含む、アプリケーションのビューツリーへの変更を再帰的にキャプチャします。その後、 セッションリプレイ はこれらの変更を再生して、ビデオのような再生を構築します。セッションの開始時に、 セッションリプレイ はアプリケーションのビューツリーの完全なスナップショットをキャプチャします。ユーザーがアプリとやり取りするときに、セッションリプレイはビューの変更をそれぞれdiffとしてキャプチャします。セッションのリプレイを視聴するとき、セッションリプレイは各差分を順番に元のビューツリーに適用し、リプレイを構築します。セッションリプレイには最大長はありません。
問題の報告
iOS用セッションリプレイに関する問題を報告される場合は、AmplitudeSessionReplay-ios GitHubリポジトリにアクセスしてください。
始める前に
使用する方法は、使用しているAmplitude iOS SDKのバージョンによって異なります。
セッションリプレイiOSプラグインには次のことが必要です。
- アプリケーションは iOS または iPadOS 上で実行されます。
- iOS Swift SDKの
1.9.0以降を使用していること。
Supported iOS versions
Session Replay supports a minimum target version of iOS 13.
クイックスタート
プラグインの最新バージョンをプロジェクトの依存関係に追加します。
Swiftパッケージマネージャー
セッションリプレイをPackage.swiftファイルの依存関係として追加するか、Xcodeのパッケージリストに含めます。
dependencies: [
.package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", from: "0.12.8")
]
Amplitude-Swiftと統合する場合は、AmplitudeSwiftSessionReplayPluginターゲットを使用してください。
.product(name: "AmplitudeSwiftSessionReplayPlugin", package: "AmplitudeSessionReplay")
CocoaPods
コアライブラリとプラグインをPodfileに追加してください。
pod 'AmplitudeSessionReplay', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git', :tag => 'v0.12.8'
pod 'AmplitudeSwiftSessionReplayPlugin', :git => 'https://github.com/amplitude/AmplitudeSessionReplay-iOS.git', :tag => 'v0.12.8'
アプリケーションコードを設定する
import AmplitudeSwift
import AmplitudeSwiftSessionReplayPlugin
// Initialize Amplitude Analytics SDK instance
let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY))
// Create and Install Session Replay Plugin
// Recording will be handled automatically
amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(sampleRate: 1.0))
設定
セッションリプレイプラグインを初期化する際には、次のオプションを渡します。
| 名前 | タイプ | 必須 | デフォルト | 概要 |
|---|---|---|---|---|
sampleRate | Float | いいえ | 0 | Amplitudeがリプレイ収集のために選択するセッション数を制御します。 0から1の小数(例:0.4)を使用します。これは、Amplitudeがリプレイ収集のためにランダムに選択するセッションの割合を表します。セッションが多数ある場合、0.4ではそれらのセッションのうちの40%を選択します。 |
enableRemoteConfig | Bool | いいえ | true | このセッションリプレイのインスタンスに対するリモートコンフィギュレーションを有効または無効にします。 |
autoStart | Bool | いいえ | true | セッションリプレイの初期化時に、自動的にキャプチャを開始するかどうかを制御します。 |
maskLevel | MaskLevel | いいえ | .medium | セッションリプレイで画面上のコンテンツをマスクする量を設定します。 .light、.medium、または.conservativeを使用します。詳細については、マスクレベルを参照してください。 |
captureWebViews | Bool | いいえ | false | ウェブビューコンテンツのキャプチャを有効にします。デフォルトでは、セッションリプレイはウェブビューをブロックします。 |
webviewMappings | [String: String] | いいえ | [:] | キャプチャされたWebビューコンテンツ内のサブストリングを置換値にマッピングします。captureWebViewsを有効にすると、セッションリプレイはアップロード前に、ウェブビューの記録データに対して、各エントリを大文字と小文字を区別しない検索と置換として適用します。これは高度なオプションです。ほとんどのアプリでは空のままにします。 |
recordLogOptions.logCountThreshold | Int | いいえ | 1000 | セッションごとのログの最大数を設定します。 |
recordLogOptions.maxMessageLength | Int | いいえ | 2000 | ログメッセージの最大長を設定します。 |
quality | QualityProfile | いいえ | .high | キャプチャとエンコードの品質を制御します(フレームレートや画像解像度など)。 .low、.medium、または.highを使用して、再生の忠実度とパフォーマンスおよびストレージのバランスを調整します。SDKがデバイスに基づいてプロファイルを選択できるようにする場合は、QualityProfile.automaticを使用します。 |
uploadConfig | UploadConfig | いいえ | UploadConfig() | セッションリプレイがデータをアップロードするタイミングを制御します。 従量課金制ネットワーク(携帯電話など)でのアップロードを一時停止するには、UploadConfig(disableMeteredUploads: true)を使用します。 |
カスタムセッションID
iOSバージョン0.11.2以降のセッションリプレイでは、customSessionIdプロパティを通じて文字列セッションID(UUIDなど)をサポートしています。プロジェクトでAmplitude session_idの代わりにカスタムイベントプロパティを使用してセッションを定義している場合は、カスタムセッションIDを使用してください。
customSessionIdを設定した場合、この値がプラグインがAmplitude SDKから同期するセッションIDよりも優先されます。AmplitudeセッションIDの使用を再開するには、プロパティをnilに設定します。
// Keep a reference to the plugin to set the custom session ID
let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(sampleRate: 1.0)
sessionReplayPlugin.customSessionId = "ef197fc7-a46f-4e6c-a77f-8d90c17065c0"
amplitude.add(plugin: sessionReplayPlugin)
// Whenever your custom session changes
sessionReplayPlugin.customSessionId = NEW_CUSTOM_SESSION_ID
セッションリプレイがカスタムセッションと確実に一致するためには、カスタムセッションIDは次の制約に従う必要があります。
- この値に
/を含めることはできません。セッションリプレイは/をセッションリプレイIDの区切り文字として使用します。このIDの形式は<deviceId>/<sessionId>です。 - この値に使用できるのは、文字
a-z A-Z 0-9 _ - . | @ : =のみです。 - 値は、イベント時にAmplitudeに送信するセッション定義プロパティと一致している必要があります。 詳細については、セッションの照合を参照してください。
実行時にマスキングを変更します
アプリの実行中に自動マスキングレベルを変更するには、プラグインprivacyConfigに設定してください。プラグインをAmplitudeに追加する前または後に設定してください。
sessionReplayPlugin.privacyConfig = PrivacyConfig(maskLevel: .conservative)
リモート設定がマスクレベルを指定している場合、そのレベルが優先されます。 このプラグインはローカルprivacyConfig値を保持し、リモート設定がマスキングレベルを提供していない場合やリモート設定を無効にした場合に適用します。
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. 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 |
ユーザーのオプトアウト
セッションリプレイプラグインはAmplitude-Swift SDKのoptOut設定に従っており、単独ではユーザーによるオプトアウトをサポートしていません。
// Set optOut on the Amplitude SDK
let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
optOut: true,
/* other configuration */))
amplitude.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:
// Set serverZone on the Amplitude SDK
let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
serverZone: .EU,
/* other configuration */))
amplitude.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.
// This configuration samples 1% of all sessions
amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(sampleRate: 0.01))
録画品質
再生の忠実度と、パフォーマンスおよびストレージのバランスを調整するには、品質プロファイルを選択します。プロファイルが小さいほど、キャプチャフレームレートが低くなり、画像解像度も低くなります。プロファイルが高いほど、フレームレートと解像度が高くなります。SDKがデバイスに基づいてプロファイルを選択できるようにする場合は、QualityProfile.automaticを使用します(例:新しいデバイスでは高く、古いデバイスでは低くするなど)。
// Use automatic profile selection based on device
amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(
sampleRate: 0.1,
quality: .automatic
))
// Or set a fixed profile (low, medium, or high)
amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(
sampleRate: 0.1,
quality: .medium
))
従量課金制ネットワークでのアップロードを無効にする
デバイスが従量課金制ネットワークに接続されている間は、セッションリプレイのアップロードを一時停止し、ユーザーのモバイルデータの使用を避けてください。セッションリプレイは引き続きデータをローカルに記録します。デバイスがWi-Fi、またはその他の従量制ではない接続に再接続されると、アップロードが再開されます。
// Set uploadConfig through the plugin's Config initializer
let config = AmplitudeSwiftSessionReplayPlugin.Config(
sampleRate: 0.1,
uploadConfig: UploadConfig(disableMeteredUploads: true)
)
amplitude.add(plugin: AmplitudeSwiftSessionReplayPlugin(config: config))
リプレイ収集を無効にする
セッションリプレイを有効にした後は、次のいずれかの条件までアプリ上で実行されます。
- ユーザーがアプリを離れる。
sessionReplayPlugin.stop()呼び出します。- このプラグインは
amplitude.remove(plugin: sessionReplayPlugin)を使用してSDKから削除できます。
ユーザーがアプリの制限付きエリアに移動する前にsessionReplayPlugin.stop()を呼び出して、ユーザーがそのエリアにいる間のリプレイ収集を無効にします。
参照の保持
これには、SessionReplayPluginインスタンスlet sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(/* session replay options */)への参照を保持する必要があります。
ユーザーがアプリの制限のないエリアに戻ったときに、sessionReplayPlugin.start()を呼び出してリプレイ収集を再度有効にします。
特定の画面のみをキャプチャするには、起動時に起動しないようにautoStart: falseでプラグインを初期化し、ユーザーがこれらの画面に出入りするときに、start()およびstop()を呼び出します。
// Add the plugin once, without starting capture
let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(sampleRate: 1.0, autoStart: false)
amplitude.add(plugin: sessionReplayPlugin)
// Start capture when the user enters a screen you want to record
sessionReplayPlugin.start()
// Stop capture when the user leaves that screen
sessionReplayPlugin.stop()
また、Amplitude Experimentなどのフィーチャーフラグプロダクトを使用して、場所などの基準に基づいてリプレイ収集を有効または無効にするロジックを作成することもできます。たとえば、特定のユーザーグループを対象とした機能フラグを作成し、それを初期化ロジックに追加できます。
import AmplitudeSwift
import AmplitudeSwiftSessionReplayPlugin
// Your existing initialization logic with Amplitude-Swift SDK
let amplitude = Amplitude(configuration: Configuration(apiKey: API_KEY,
/* other configuration */))
if (nonEUCountryFlagEnabled) {
// Create and Install Session Replay Plugin
let sessionReplayPlugin = AmplitudeSwiftSessionReplayPlugin(sampleRate: 0.1)
amplitude.add(plugin: sessionReplayPlugin)
}
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
Session replay uses existing Amplitude tools and APIs to handle privacy and deletion requests. <!--vale off-->
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.
{
"amplitude_id": 123456789,
"app": 12345,
"event_time": "2020-02-15 01:00:00.123456",
"event_type": "first_event",
"server_upload_time": "2020-02-18 01:00:00.234567",
"device_id": "your device id",
"user_properties": { ... }
"event_properties": {
"[Amplitude] Session Replay ID": "cb6ade06-cbdf-4e0c-8156-32c2863379d6/1699922971244"
}
"session_id": 1699922971244,
}
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
Was this helpful?