Android session replay installation

  1. Install the dependency

    Required

    Add the PostHog Android SDK to your build.gradle dependencies:

    build.gradle
    dependencies {
    implementation("com.posthog:posthog-android:3.+")
    }
    SDK version

    Session replay requires PostHog Android SDK version 3.4.0 or higher. We recommend always using the latest version.

  2. Enable session recordings in project settings

    Required

    Go to your PostHog Project Settings and enable Record user sessions. Session recordings will not work without this setting enabled.

  3. Configure PostHog with session replay

    Required

    Add sessionReplay = true to your PostHog configuration. Here are all the available options:

    SampleApp.kt
    class SampleApp : Application() {
    companion object {
    const val POSTHOG_API_KEY = "<ph_project_api_key>"
    const val POSTHOG_HOST = "https://us.i.posthog.com"
    }
    override fun onCreate() {
    super.onCreate()
    val config = PostHogAndroidConfig(
    apiKey = POSTHOG_API_KEY,
    host = POSTHOG_HOST
    )
    // Enable session recording. Requires enabling in your project settings as well.
    // Default is false.
    config.sessionReplay = true
    // Whether text and text input fields are masked. Default is true.
    // Password inputs are always masked regardless
    config.sessionReplayConfig.maskAllTextInputs = true
    // Whether images are masked. Default is true.
    config.sessionReplayConfig.maskAllImages = true
    // Capture logs automatically. Default is true.
    config.sessionReplayConfig.captureLogcat = true
    // Whether replays are created using high quality screenshots. Default is false.
    // If disabled, replays are created using wireframes instead.
    // The screenshot may contain sensitive information, so use with caution
    config.sessionReplayConfig.screenshot = false
    // Throttle delay used to reduce the number of snapshots captured. Default is 1000ms
    config.sessionReplayConfig.throttleDelayMs = 1000
    PostHogAndroid.setup(this, config)
    }
    }

    For more configuration options, see the Android session replay docs.

    Requirements

    Requires Android API 26 or higher. Jetpack Compose is only supported if screenshot is enabled.

  4. Watch session recordings

    Recommended

    Visit your site or app and interact with it for at least 10 seconds to generate a recording. Navigate between pages, click buttons, and fill out forms to capture meaningful interactions.

    Watch your first recording →

  5. Next steps

    Recommended

    Now that you're recording sessions, continue with the resources below to learn what else Session Replay enables within the PostHog platform.

    ResourceDescription
    Watching recordingsHow to find and watch session recordings
    Privacy controlsHow to mask sensitive data in recordings
    Network recordingHow to capture network requests in recordings
    Console log recordingHow to capture console logs in recordings
    More tutorialsOther real-world examples and use cases

Community questions

Was this page useful?

Questions about this page? or post a community question.