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 미들웨어
Early access SDK
As an Alpha release, this SDK may contain bugs and cause crashes. Before you enable in production, thoroughly test your app in a controlled environment. For more information about best practices for developer preview SDKs, see SDK Maintenance and Support.
이 문서에서는 iOS SDK 미들웨어를 통한 세션 리플레이 설치에 대해 설명합니다. 앱이 이미 (유지 관리) Amplitude SDK를 사용하는 경우, 이 옵션을 사용하십시오.
앱에서 이미 (최신) iOS Swift SDK를 사용하는 경우 세션 리플레이 iOS SDK 플러그인을 선택하십시오.
Analytics-Swift SDK 및 Amplitude(액션) 목적지를 통해 세그먼트를 사용하는 경우 세그먼트 플러그인을 선택하십시오.
제품 내 분석을 위해 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.
시작하기 전에
세션 리플레이 미들웨어의 요구사항은 다음과 같습니다.
- 애플리케이션은 iOS 또는 iPadOS에서 실행됩니다.
- (유지 보수)Amplitude iOS SDK
8.22.0이상을 사용하고 있습니다. - SDK에 장치 ID를 제공할 수 있습니다.
Supported iOS versions
Session Replay supports a minimum target version of iOS 13.
빠른 시작
최신 버전의 미들웨어를 프로젝트 종속성에 추가하십시오.
세션 리플레이를 Package.swift 파일이나 Xcode의 패키지 목록에 의존성으로 추가하십시오.
dependencies: [
.package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", from: "0.12.8")
]
Amplitude-iOS와의 통합을 위해 AmplitudeiOSSessionReplayMiddleware 타겟을 사용하십시오.
.product(name: "AmplitudeiOSSessionReplayMiddleware", package: "AmplitudeSessionReplay")
애플리케이션 코드를 구성합니다.
import Amplitude
import AmplitudeiOSSessionReplayMiddleware
// Initialize Amplitude Analytics SDK instance
let amplitude = Amplitude.instance()
// Although not required, we recommend enabling session start and end events when enabling Session Replay
amplitude.defaultTracking.sessions = true
// Create and Install Session Replay Middleware
// Recording will be handled automatically
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(sampleRate: 0.1))
amplitude.initializeApiKey(API_KEY)
구성
세션 리플레이 미들웨어를 초기화할 때 다음 옵션을 전달하십시오.
| 옵션 | 유형 | 필수 | 기본값 | 설명 |
|---|---|---|---|---|
sampleRate | Float | 아니요 | 0 | 리플레이 수집을 위해 선택할 세션 수를 제어합니다. 0에서 1 사이의 소수를 사용하십시오(예: 0.4, 리플레이 수집을 위해 무작위로 선택된 세션의 비율을 나타냄). 많은 수의 세션 중에서 0.4는 해당 세션의 40%을 선택합니다. 자세한 내용은 샘플링 속도를 참조하십시오. |
enableRemoteConfig | Bool | 아니요 | true | 이 세션 리플레이 인스턴스에 대한 원격 구성을 활성화하거나 비활성화합니다. |
autoStart | Bool | 아니요 | true | 세션 리플레이가 초기화될 때 자동으로 캡처를 시작할지 여부를 제어합니다. |
maskLevel | MaskLevel | 아니요 | .medium | 세션 리플레이가 화면상의 콘텐츠를 얼마나 많이 마스킹할지 설정합니다. .light, .medium 또는 .conservative을 사용하십시오. 자세한 내용은 마스크 수준을 참조하십시오. |
captureWebViews | Bool | 아니요 | false | 웹 보기 콘텐츠를 캡처할 수 있습니다. 기본적으로 세션 리플레이는 웹 뷰를 차단합니다. |
webviewMappings | [String: String] | 아니요 | [:] | 캡처된 웹 뷰 콘텐츠의 하위 문자열을 대체 값에 매핑합니다. captureWebViews을 활성화하면 세션 리플레이는 업로드하기 전에 웹 뷰 기록 데이터에 각 항목을 대소문자를 구분하지 않는 검색 및 바꾸기로 적용합니다. 이것은 고급옵션입니다. 대부분의 앱은 비워 둡니다. |
recordLogOptions.logCountThreshold | Int | 아니요 | 1000 | 세션당 최대 로그 수를 설정합니다. |
recordLogOptions.maxMessageLength | Int | 아니요 | 2000 | 로그 메시지의 최대 길이를 설정합니다. |
quality | QualityProfile | 아니요 | .high | 캡처 및 인코딩 품질(예: 프레임 속도 및 이미지 해상도)을 제어합니다. .low, .medium 또는 .high을 사용하여 재생 충실도와 성능 및 저장 용량의 균형을 맞출 수 있습니다. SDK가 장치에 따라 프로파일을 선택하도록 하려면 QualityProfile.automatic를 사용합니다. |
uploadConfig | UploadConfig | 아니요 | UploadConfig() | 세션 리플레이가 데이터를 업로드하는 시점을 제어합니다. 종량제 네트워크(예: 셀룰러)에서 업로드를 일시 중지하려면 UploadConfig(disableMeteredUploads: true)를 사용하십시오. |
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-iOS SDK의 optOut 설정에 따르며 자체적으로 사용자 옵트아웃을 지원하지 않습니다.
// Set optOut on the Amplitude SDK
amplitude.optOut = true
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(/* 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
amplitude.setServerZone(.EU)
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(/* 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.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(sampleRate: 0.01))
레코딩 품질
재생 충실도와 성능 및 저장 공간의 균형을 맞추기 위해 품질 프로파일을 선택하십시오. 프로파일이 낮을수록 캡처 프레임 속도가 낮고 이미지 해상도가 낮습니다. 프로파일이 높을수록 프레임 속도가 높고 해상도가 높아집니다. SDK가 장치에 따라 프로파일을 선택하도록 허용하는 데 사용합니다(예: 최신 장치에서는 높음, 이전 장치에서는 낮음)QualityProfile.automatic.
// Use automatic profile selection based on device
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(
sampleRate: 0.1,
quality: .automatic
))
// Or set a fixed profile (low, medium, or high)
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(
sampleRate: 0.1,
quality: .medium
))
사용량이 부과되는 네트워크에서 업로드 비활성화
장치가 요금제 기반 네트워크에 있는 동안 세션 리플레이 업로드를 일시 중지하여 사용자의 휴대폰 데이터 사용을 방지하십시오. 세션 리플레이는 여전히 데이터를 로컬로 기록합니다. 기기가 Wi-Fi 또는 다른 종량제 제한이 없는 연결에 다시 연결되면 업로드가 재개됩니다.
amplitude.addEventMiddleware(AmplitudeiOSSessionReplayMiddleware(
sampleRate: 0.1,
uploadConfig: UploadConfig(disableMeteredUploads: true)
))
리플레이 수집 비활성화
활성화된 후에는 다음 중 하나가 발생할 때까지 세션 리플레이가 앱에서 실행됩니다.
- 사용자가 앱을 떠납니다.
sessionReplayMiddleware.stop()을(를) 호출하십시오.amplitude.removeEventMiddleware(sessionReplayMiddleware)를 사용하여 SDK에서 미들웨어를 제거합니다.
사용자가 앱의 제한된 영역으로 이동하기 전에 호출하여 사용자가 해당 영역에 있는 동안 재생 수집을 비활성화하십시오sessionReplayMiddleware.stop().
참조 유지
이 작업에는 세션 리플레이 미들웨어 인스턴스에 대한 참조를 유지하는 것이 필요합니다 let sessionReplayMiddleware = AmplitudeiOSSessionReplayMiddleware(/* session replay options */).
사용자가 앱의 제한되지 않은 영역으로 돌아왔을 때 재생 수집을 다시 활성화하려면 sessionReplayMiddleware.start()를 호출하십시오.
특정 화면만 캡처하려면 실행 시 시작되지 않도록 미들웨어를 autoStart: false로 초기화한 다음, 사용자가 해당 화면에 들어오고 나갈 때 start() 및 stop()를 호출하십시오.
// Add the middleware once, without starting capture
let sessionReplayMiddleware = AmplitudeiOSSessionReplayMiddleware(sampleRate: 1.0, autoStart: false)
amplitude.addEventMiddleware(sessionReplayMiddleware)
// Start capture when the user enters a screen you want to record
sessionReplayMiddleware.start()
// Stop capture when the user leaves that screen
sessionReplayMiddleware.stop()
또한 Amplitude 실험과 같은 기능 플래그 제품을 사용하여 위치와 같은 기준에 따라 리플레이 수집을 활성화하거나 비활성화하는 로직을 만들 수도 있습니다. 예를 들어, 특정 사용자 그룹을 대상으로 하는 기능 플래그를 생성하고 이를 초기화 논리에 추가할 수 있습니다.
import Amplitude
import AmplitudeiOSSessionReplayMiddleware
// Your existing initialization logic with Amplitude-iOS SDK
let amplitude = Amplitude.instance()
if (nonEUCountryFlagEnabled) {
// Create and Install Session Replay Middleware
let sessionReplayMiddleware = AmplitudeiOSSessionReplayMiddleware(sampleRate: 0.1)
amplitude.addEventMiddleware(sessionReplayMiddleware)
}
amplitude.initializeApiKey(API_KEY)
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
이 내용이 도움이 되었나요?