On this page

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.

セッションリプレイ Android プラグイン

アプリがすでにAmplitudeで計測されている場合は、Android SDKプラグインを使用してセッションリプレイをインストールしてください。製品内アナリティクスに別のプロバイダーを使用している場合は、代わりにスタンドアロンの実装を使用してください。

Session Replay and performance

Amplitude built Session Replay to minimize impact on the performance of the Android apps in which it's installed by:

  • Asynchronously capturing and processing replay data, to avoid blocking the main user interface thread. The main thread must analyze the view hierarchy, but snapshot capture scheduling and extra processing offloads to the background.
  • 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としてキャプチャします。その後、セッションリプレイは各diffを元のビューツリーに順番に適用することにより、セッションのリプレイを構築します。

セッションリプレイには最大長はありません。

問題の報告

Android用セッションリプレイに関する問題を報告される場合は、AmplitudeSessionReplay-Android GitHubリポジトリにアクセスしてください。

始める前に

使用する方法は、使用しているAmplitude Android SDKのバージョンによって異なります。

最新の Android-Kotlin SDK を使用している場合は、Android プラグインの指示に従ってください。

Session Replay Androidプラグインでは以下が必要です。

  1. このアプリケーションはAndroidベースです。
  2. デバイス識別子をSDKに提供できます。

Supported Android versions

Session replay supports down to Android 5.0 with a minimum SDK of 21 minSdk = 21. This should support over 99.6% of global Android devices according to Google's distribution data in Android Studio.

クイックスタート

プラグインの最新バージョンをプロジェクトの依存関係に追加します。

kotlin
// Install latest version from Maven Central
implementation("com.amplitude:plugin-session-replay-android:0.30.0")
// You will also need the Amplitude Analytics SDK if it's not already installed
implementation("com.amplitude:analytics-android:[1.29.0,2.0.0)")

アプリケーションコードを設定します。

kotlin
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
import com.amplitude.android.plugins.SessionReplayPlugin
// Initialize Amplitude Analytics SDK instance
val amplitude = Amplitude(
    Configuration(
        apiKey = API_KEY,
        context = applicationContext
    )
)
// Create and Install Session Replay Plugin
// Recording will be handled automatically
val sessionReplayPlugin = SessionReplayPlugin(sampleRate = 1.0)
amplitude.add(sessionReplayPlugin)

サンプルレート

これらのコードサンプルのサンプルレートは1.0です。この設定により、Amplitudeはテスト中にセッションを確実にキャプチャしますが、本番環境で超過が発生する可能性があります。

設定

セッションリプレイプラグインを初期化する際には、次のオプションを渡してください。

カスタムセッションID

Androidバージョン0.26.4以降のセッションリプレイでは、setCustomSessionIdメソッドを通じて、UUIDなどの文字列セッションIDをサポートしています。プロジェクトでAmplitude session_idの代わりにカスタムイベントプロパティを使用してセッションを定義している場合は、カスタムセッションIDを使用してください。

カスタムセッションIDを設定する場合、この値はプラグインがAmplitude SDKから同期するセッションIDよりも優先されます。 nullを渡してオーバーライドをクリアし、AmplitudeセッションIDを使用して再開します。

kotlin
// Keep a reference to the plugin to set the custom session ID
val sessionReplayPlugin = SessionReplayPlugin(sampleRate = 1.0)
sessionReplayPlugin.setCustomSessionId("ef197fc7-a46f-4e6c-a77f-8d90c17065c0")
amplitude.add(sessionReplayPlugin)
// Whenever your custom session changes
sessionReplayPlugin.setCustomSessionId(newCustomSessionId)

セッションリプレイがカスタムセッションと確実に一致するためには、カスタムセッションIDは次の制約に従う必要があります。

  • この値に/を含めることはできません。セッションリプレイは/をセッションリプレイIDの区切り文字として使用します。このIDの形式は<deviceId>/<sessionId>です。
  • この値に使用できるのは、文字a-z A-Z 0-9 _ - . | @ : =のみです。
  • 値は、イベント時にAmplitudeに送信するセッション定義プロパティと一致している必要があります。 詳細については、セッションの照合を参照してください。

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.

Mask on-screen data

The Session Replay SDK offers four ways to mask user input, text, and other view components.

Mask level

Session Replay for Android supports three levels of masking, set through the privacyConfig option with PrivacyConfig(maskLevel = MaskLevel.MEDIUM). The default level is medium.

Use this option in the Session Replay configuration.

Privacy tags in layout XML

Use this option in your application's layout XML.

Privacy methods on the Session Replay SDK

Import the SessionReplay class, then call one of the methods below from your application's code.

kotlin
import com.amplitude.android.sessionreplay.SessionReplay

Privacy modifiers in Jetpack Compose

For composables, use the privacy modifiers instead of layout XML tags or the SessionReplay methods. These modifiers require version 0.21.0 or higher of the Session Replay Android SDK or plugin.

Import the modifier you need from com.amplitude.android.sessionreplay.compose, then add it to the composable's modifier chain.

kotlin
import com.amplitude.android.sessionreplay.compose.ampMask
import com.amplitude.android.sessionreplay.compose.ampUnmask
import com.amplitude.android.sessionreplay.compose.ampBlock
kotlin
// Mask text that Session Replay captures by default
Text(
    text = "Account number: 123456789",
    modifier = Modifier.ampMask(),
)

// Unmask an input field that Session Replay masks by default
TextField(
    value = username,
    onValueChange = { username = it },
    modifier = Modifier.ampUnmask(),
)

// Block a composable and everything it contains
Box(modifier = Modifier.ampBlock()) {
    Text("Session Replay doesn't capture this content")
}

A privacy modifier applies to the composable you add it to and to everything nested inside it. When a nested composable has its own privacy modifier, that modifier takes precedence for that composable and its descendants.

ユーザーのオプトアウト

セッションリプレイプラグインはAndroid SDKのoptOut設定に従っており、単独ではユーザーによるオプトアウトをサポートしていません。

kotlin
// Set optOut on the Amplitude SDK
val amplitude = Amplitude(Configuration(
    apiKey = API_KEY,
    optOut = true,
    /* other configuration */
))
amplitude.add(SessionReplayPlugin(/* 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:

kotlin
// Set serverZone on the Amplitude SDK
val amplitude = Amplitude(Configuration(
    apiKey = API_KEY,
    serverZone = ServerZone.EU,
    /*, other configuration */
))
amplitude.add(SessionReplayPlugin(/* 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.
kotlin
// This configuration samples 1% of all sessions
amplitude.add(SessionReplayPlugin(sampleRate = 0.01))

リプレイ収集を無効にする

セッションリプレイを有効にした後は、次のいずれかの条件までアプリ上で実行されます。

  • ユーザーがアプリを離れる。
  • sessionReplayPlugin.stop()呼び出します。
  • このプラグインはamplitude.remove(sessionReplayPlugin)を使用してSDKから削除できます。

ユーザーがアプリの制限付きエリアに移動する前にsessionReplayPlugin.stop()を呼び出して、ユーザーがそのエリアにいる間のリプレイ収集を無効にします。

参照の保持

これには、SessionReplayPluginインスタンスへの参照を保持する必要があります:val sessionReplayPlugin = SessionReplayPlugin(/* session replay options */)

ユーザーがアプリの制限のないエリアに戻ったときに、sessionReplayPlugin.start()を呼び出してリプレイ収集を再度有効にします。

特定の画面のみをキャプチャするには、起動時に起動しないようにautoStart = falseでプラグインを初期化し、ユーザーがこれらの画面に出入りするときに、start()およびstop()を呼び出します。

kotlin
// Add the plugin without starting capture
val sessionReplayPlugin = SessionReplayPlugin(sampleRate = 1.0, autoStart = false)
amplitude.add(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 などのフィーチャーフラグプロダクトを使用して、場所などの基準に基づいてリプレイ収集を有効または無効にすることもできます。たとえば、特定のユーザーグループを対象としたフィーチャーフラグを作成し、それを初期化ロジックに追加できます。

kotlin
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
import com.amplitude.android.plugins.SessionReplayPlugin
// Your existing initialization logic with Android SDK
val amplitude = Amplitude(Configuration(apiKey = API_KEY /*, ... other configuration */))
if (nonEUCountryFlagEnabled) {
  // Create and Install Session Replay Plugin
  val sessionReplayPlugin = SessionReplayPlugin(sampleRate = 0.5)
  amplitude.add(sessionReplayPlugin)
}

WebView and MapView support (Beta)

By default, Session Replay blocks web views and map views in a capture. To enable capture of these components, use the settings described in Mask on-screen data.

Web view session replay injects JavaScript into the rendered page. To enable this, the SDK sets javaScriptEnabled to true on the unmasked web view.

Log Recording

Availability

Log recording is available in Session Replay Android 0.22.0 and later.

Session Replay supports recording logs in Android applications. To enable log recording, send log messages through the recordLog(level, message, timestamp) API and configure the limits through recordLogOptions parameter while initializing Session Replay.

kotlin
import com.amplitude.android.plugins.SessionReplayPlugin
import com.amplitude.android.sessionreplay.config.RecordLogLevel
import com.amplitude.android.sessionreplay.config.RecordLogOptions

val sessionReplayPlugin = SessionReplayPlugin(
    recordLogOptions = RecordLogOptions(
        logCountThreshold = 2000,
        maxMessageLength = 4000
    )
)
amplitude.add(sessionReplayPlugin)

sessionReplayPlugin.recordLog(RecordLogLevel.Error, "This is an error log")

// You can also create custom log levels
sessionReplayPlugin.recordLog(RecordLogLevel("debug"), "This is a debug log")

Session Replay supports predefined log levels (Error, Warn, Log) and custom log levels. Create custom log levels by passing any string value to RecordLogLevel(...).

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.

Timber

If you use Timber, you can integrate it with a custom tree.

kotlin
import com.amplitude.android.plugins.SessionReplayPlugin
import com.amplitude.android.sessionreplay.config.RecordLogLevel
import timber.log.Timber

class AmplitudeLogRecordTree(private val plugin: SessionReplayPlugin) : Timber.Tree() {
    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
        val recordLevel = when (priority) {
            android.util.Log.ERROR -> RecordLogLevel.Error
            android.util.Log.WARN -> RecordLogLevel.Warn
            android.util.Log.INFO -> RecordLogLevel.Log
            android.util.Log.DEBUG -> RecordLogLevel("debug")
            android.util.Log.VERBOSE -> RecordLogLevel("verbose")
            else -> return
        }
        plugin.recordLog(recordLevel, message)
    }
}

val sessionReplayPlugin = SessionReplayPlugin()
amplitude.add(sessionReplayPlugin)

Timber.plant(AmplitudeLogRecordTree(sessionReplayPlugin))

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 of tracking in your app, use the optOut configuration option to disable replay collection for that user.

The SDK stores replay data locally. It retries transient upload failures, subject to retry and storage limits.

Amplitudeは、アプリ終了ごとにセッションデータをサーバーに送信するようにflushEventsOnClose = trueAmplitude SDK設定(デフォルト)で設定することを推奨しています。

Jetpack Compose Support (Alpha)

Session Replay supports Jetpack Compose for Android applications. This feature is currently in Alpha. To use Jetpack Compose with Session Replay, ensure you use version 0.20.4 or higher of the Session Replay Android SDK or plugin.

To control what Session Replay captures in a composable, use the privacy modifiers in Jetpack Compose. Masking support for Compose requires 0.21.0 or higher.

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 can't capture the following Android views:

    • Canvas Views

複数のAmplitudeインスタンス

セッションリプレイは、Amplitude SDKの単一インスタンスへの接続をサポートしています。アプリケーションに複数のインスタンスが実装されている場合は、プロジェクトに関連性の高いインスタンスでセッションリプレイを開始してください。

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 Android 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
  • The app process ends or you shut down the SDK before pending replay data uploads.
  • Sampling

Lack of connectivity

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

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.

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.
  • Page instrumentation. If Session Replay isn't implemented on all pages a user visits, their session may not capture properly.
  • Replays older than the set retention period (defaults to 90 days).

Report an Issue

If you encounter any issues with Session Replay that aren't covered in the troubleshooting guide above, please report them on our GitHub repository.

When creating an issue, please include:

  • A clear description of the problem
  • Steps to reproduce the issue
  • Expected vs actual behavior
  • SDK version you're using
  • Any relevant error messages or logs

キャプチャされたセッションには限られた情報しか含まれていません

Amplitudeは、セッションリプレイがセッションをキャプチャするときに[Amplitude] Replay Capturedイベントを自動的に作成します。実装でこのイベントが表示されない場合、ファネル分析、セグメンテーション、ジャーニーチャートなどのAmplitudeの分析ツールでリプレイが正しく表示されない可能性があります。セッションリプレイは、引き続きセッションリプレイホームページまたはユーザープロフィールページで確認できます。

このイベントが表示されない理由には、次のようなものがあります。

  • ユーザーがオプトアウトしたか、現在のsampleRateによるサンプルセットに含まれていません。より多くのセッションをキャプチャするにはsampleRateを増やしてください。
  • セッション用のoptOutの設定を有効にしました。 optOutおよびsampleRate設定にそのセッションが含まれていることを確認してください。
  • アプリがイベントを計測するために Android SDK 以外のメソッドを使用しています。 Android 用の セッションリプレイ Standalone SDK の使用を検討してください。

これらの設定を確認してもイベントが表示されない場合は、Amplitude サポートにお問い合わせください。

リプレイの長さとセッション時間が一致しません

場合によっては、リプレイの長さが[Amplitude] Start Sessionおよび[Amplitude] End Sessionイベント間の時間を超えることがあります。この状況は、[Amplitude] End Sessionイベント発生後、Android SDK と セッションリプレイ プラグインがイベントを処理できるようになる前にユーザーがアプリを閉じた場合に発生します。ユーザーがアプリを再度使用すると、SDKとプラグインがイベントを処理し、リプレイとともにそのイベントをAmplitudeに送信します。このシナリオを検証するには、End Session Client Event TimeClient Upload Timeの間に矛盾がないか確認してください。

セッションリプレイがAmplitudeに表示されない

セッション再生は、次の理由によりAmplitudeに表示されないことがあります:

  • ネットワーク接続がありません。アプリがインターネットにアクセスできることを確認してから、もう一度試してみてください。
  • アプリを終了する前に録画のフラッシュに失敗しています。
  • 現在のセッションでは、Android SDK を介して送信されたイベントはありません。
  • [Amplitude] Replay Capturedイベントがありません。 レビューでキャプチャされたセッションに含まれる情報は限られています。
  • サンプリング

サンプリング

セッションリプレイのデフォルトsampleRate値は0です。レートをより高い数値に更新してください。 詳細については、サンプリングレートを参照してください。

セッションリプレイ処理エラー

リプレイは、取り込みから数分以内に利用可能になる必要があります。 遅延やエラーは、次のいずれかまたは複数の原因によって発生することがあります。

  • API キーまたはデバイス ID が一致しません。 この不一致は、セッションリプレイと標準イベント計測が異なる API キーまたはデバイス ID を使用している場合に発生します。
  • セッションリプレイが間違ったプロジェクトを参照しています。
  • 短いセッション。 ユーザーが初期化から数秒以内にアプリを閉じると、SDK はリプレイデータをアップロードする時間がありません。
  • ページ計測。 ユーザーが訪問するすべてのページにセッションリプレイを実装していない場合、セッションが正しくキャプチャされない可能性があります。
  • 設定されたリテンション期間(デフォルトは90日)よりも古いリプレイ。

Was this helpful?