Android Session Replay installation
Contents
- 1
Install the dependency
RequiredAdd the PostHog Android SDK to your
build.gradledependencies:build.gradleSDK versionSession 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
RequiredGo 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
RequiredAdd
sessionReplay = trueto your PostHog configuration. Here are all the available options:SampleApp.ktFor more configuration options, see the Android session replay docs.
RequirementsRequires Android API 26 or higher. Jetpack Compose is only supported if
screenshotis enabled. - 4
Watch session recordings
RecommendedVisit 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.
- 5
Next steps
RecommendedNow that you're recording sessions, continue with the resources below to learn what else Session Replay enables within the PostHog platform.
Resource Description Watching recordings How to find and watch session recordings Privacy controls How to mask sensitive data in recordings Network recording How to capture network requests in recordings Console log recording How to capture console logs in recordings More tutorials Other real-world examples and use cases
Configure screenshot capture
Lowering screenshot resolution and using the smaller RGB_565 pixel format reduce capture time and memory use. This helps keep your app responsive while recording.
For the best balance of performance and image quality, we recommend a scale of 0.5, the RGB_565 color mode, and compression quality 30.
Use these experimental sessionReplayConfig options to control screenshot resolution, compression, and bitmap memory use independently. They only apply when sessionReplayConfig.screenshot is true. They don't enable Session Replay or affect wireframe capture.
screenshotScale(default:1.0f) – Multiplies the physical width and height of screenshots. Values are clamped to0.1–1.0. A scale of0.5captures half the width and height, or one quarter of the pixels.screenshotCompressionQuality(default:30) – WebP compression quality, as an integer clamped to0–100. Higher values generally retain more detail and produce larger payloads. This doesn't change screenshot resolution.screenshotColorMode(default:ARGB_8888) – Bitmap pixel format.ARGB_8888uses four bytes per pixel and preserves transparency and color precision before compression.RGB_565uses two bytes per pixel, with reduced color precision and no transparency.
The defaults retain full-resolution screenshots with ARGB_8888 and WebP quality 30. The SDK reuses compatible screenshot buffers automatically, including with these defaults.
Apply the recommended settings before calling PostHogAndroid.setup(this, config):
Keep these trade-offs in mind:
- Resolution – Lower scales reduce image detail. The SDK rounds each scaled dimension up to at least one pixel. Replay viewport dimensions and mask positions remain aligned with the original screen.
NaNand infinite scale values reset to1.0. - Color and transparency – With
RGB_565, transparent window regions appear black. If a device rejects this format, the SDK usesARGB_8888for later captures. - Compression – WebP compression is lossy, including at quality
100, except on Android 10 (API 29), where quality100uses lossless compression.
To capture fewer snapshots instead, increase sessionReplayConfig.throttleDelayMs. Screenshot resolution, compression quality, and color mode don't change the capture interval. Check text readability and privacy masking in your app before deploying these settings.