이 페이지에서

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 세그먼트 플러그인을 사용하여 세션 리플레이를 설치하는 방법에 대해 설명합니다. 앱이 세그먼트의 Analytics-Swift 라이브러리와 Amplitude(동작) 목적지를 사용하는 경우 이 옵션을 사용하십시오.

앱에서 Amplitude iOS SDK를 사용하는 경우, 세션 리플레이 iOS SDK 플러그인을 사용하십시오.

세그먼트를 다른 옵션과 함께 사용하는 경우 독립형 구현을 선택합니다.

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용 세션 리플레이와 관련된 문제를 리포트하려면 AmplitudeSessionReplay-ios GitHub 저장소로 이동하십시오.

시작하기 전에

세션 리플레이 iOS Segment Plugin을 사용하려면 다음이 필요합니다.

  1. 애플리케이션은 iOS 또는 iPadOS에서 실행됩니다.
  2. 수집을 위해 Segment의 Analytics-Swift 라이브러리를 사용합니다.
  3. Segment의 Amplitude (Actions) 목적지를 사용합니다.
  4. Segment의 Amplitude 플러그인을 사용합니다.

Supported iOS versions

Session Replay supports a minimum target version of iOS 13.

빠른 시작

최신 버전의 플러그인을 프로젝트 종속성에 추가합니다.

Segment 플러그인은 Swift 패키지 관리자를 통해서만 사용할 수 있습니다. 세션 리플레이를 Package.swift 파일 또는 Xcode의 패키지 목록에 종속성으로 추가하십시오.

swift
dependencies: [
    .package(url: "https://github.com/amplitude/AmplitudeSessionReplay-iOS", from: "0.12.8")
]

Analytics-Swift와 통합하려면 AmplitudeSegmentSessionReplayPlugin 타겟을 사용하십시오.

swift
.product(name: "AmplitudeSegmentSessionReplayPlugin", package: "AmplitudeSessionReplay")

애플리케이션 코드를 구성합니다.

swift
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))

구성

세션 리플레이 플러그인을 초기화할 때 다음 옵션을 전달하십시오.

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.

Privacy methods for UIKit

Session Replay provides an extension on UIView to manage privacy. Import the Session Replay library to access it.

swift
import AmplitudeSessionReplay

Privacy Modifiers for SwiftUI

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

swift
import AmplitudeSessionReplay

사용자 옵트아웃

사용자가 세션 리플레이를 거부했음을 나타내려면 플러그인에 optOut을 설정하십시오.

swift
// 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:

swift
// 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 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.
swift
// This configuration samples 1% of all sessions
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
                                                              sampleRate: 0.01))

레코딩 품질

재생 충실도와 성능 및 저장 공간의 균형을 맞추기 위해 품질 프로파일을 선택하십시오. 프로파일이 낮을수록 캡처 프레임 속도가 낮고 이미지 해상도가 낮습니다. 프로파일이 높을수록 프레임 속도가 높고 해상도가 높아집니다. SDK가 장치에 따라 프로파일을 선택하도록 허용하려면 QualityProfile.automatic 를 사용합니다. 예를 들어 SDK는 최신 기기에서는 높음을 선택하고 이전 기기에서는 낮음을 선택합니다.

swift
// 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))

사용량이 부과되는 네트워크에서 업로드 비활성화

기기가 종량제 네트워크를 사용하는 동안 세션 리플레이 업로드를 일시 중지하여 사용자의 셀룰러 데이터 사용을 방지하십시오. 세션 리플레이는 여전히 데이터를 로컬로 기록합니다. 기기가 Wi-Fi 또는 다른 종량제 제한이 없는 연결에 다시 연결되면 업로드가 재개됩니다.

swift
analytics.add(plugin: AmplitudeSegmentSessionReplayPlugin(amplitudeApiKey: API_KEY,
                                                              sampleRate: 0.1,
                                                              uploadConfig: UploadConfig(disableMeteredUploads: true)))

리플레이 수집 비활성화

세션 리플레이를 활성화한 후에는 다음 중 하나가 될 때까지 앱에서 실행됩니다.

  • 사용자가 앱을 떠납니다.
  • amplitudeSegmentSessionReplayPlugin.stop()을(를) 호출하십시오.
  • analytics.remove(plugin: amplitudeSegmentSessionReplayPlugin)를 사용하여 세그먼트에서 플러그인을 제거합니다.

사용자가 앱의 제한된 영역으로 이동하기 전에 호출하여 사용자가 해당 영역에 있는 동안 재생 수집을 비활성화하십시오amplitudeSegmentSessionReplayPlugin.stop().

참조를 유지하십시오

SessionReplayPlugin 인스턴스에 대한 참조를 유지하십시오: let amplitudeSegmentSessionReplayPlugin = AmplitudeSegmentSessionReplayPlugin(/* session replay options */).

사용자가 앱의 제한되지 않은 영역으로 돌아왔을 때 재생 수집을 다시 활성화하려면 amplitudeSegmentSessionReplayPlugin.start()를 호출하십시오.

특정 화면만 캡처하려면 플러그인이 시작될 때 시작되지 않도록 autoStart: false를 사용하여 초기화한 다음, 사용자가 해당 화면에 들어오거나 나갈 때 start() 및 stop()를 호출하십시오.

swift
// 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()

또한 Amplitude 실험과 같은 기능 플래그 제품을 사용하여 위치와 같은 기준에 따라 리플레이 수집을 활성화하거나 비활성화하는 로직을 만들 수도 있습니다. 예를 들어, 특정 사용자 그룹을 대상으로 하는 기능 플래그를 생성한 다음 해당 플래그를 초기화 논리에 추가합니다.

swift
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.

swift
// 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.

swift
// 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.

swift
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.

swift
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.

json
{
  "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

이 내용이 도움이 되었나요?