Flutter Session Replay installation
Contents
- 1
Install the package
RequiredAdd the PostHog Flutter SDK to your
pubspec.yaml:pubspec.yamlSDK versionSession replay requires PostHog Flutter SDK version 4.7.0 or higher. We recommend always using the latest version.
- 2
Disable auto-init for Android
RequiredFor session replay, you need to use manual initialization. Add this to your
AndroidManifest.xmlto disable auto-init:android/app/src/main/AndroidManifest.xmlUpdate the minimum Android SDK version to 21 in
android/app/build.gradle:android/app/build.gradle - 3
Disable auto-init for iOS
RequiredAdd this to your
Info.plistto disable auto-init:ios/Runner/Info.plistUpdate the minimum platform version to iOS 13.0 in your
Podfile:Podfile - 4
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.
If you're using Flutter Web, also enable the Canvas capture setting. This is required as Flutter renders your app using a browser canvas element.
- 5
Initialize PostHog with session replay
RequiredInitialize PostHog in your
main.dartwith session replay enabled. Here are all the available options:main.dartFor more configuration options, see the Flutter session replay docs.
- 6
Wrap your app with PostHogWidget
RequiredFor Session Replay to work, wrap your app with
PostHogWidgetand add thePosthogObserver:MyApp.dartMyApp.dart - 7
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.
- 8
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
Control recording programmatically
Requires PostHog Flutter SDK version >= 5.14.0. Available on iOS, Android, and Web.
Setting config.sessionReplay = false in your PostHog configuration will prevent PostHog from automatically starting session recordings on SDK setup.
You can manually control when to start and stop session recordings using the following methods:
startSessionRecording({bool resumeCurrent = true})- Set resumeCurrent to
trueto resume a previous session recording (default). - Set resumeCurrent to
falseto start a new session recording. - To begin a completely fresh session, call stopSessionRecording() first, then startSessionRecording(resumeCurrent: false).
- Set resumeCurrent to
stopSessionRecording()- Stops/pauses the current session recording.
isSessionReplayActive()- Returns a
Future<bool>telling you whether a recording is currently active on this device. Resolves tofalsewhen session replay is off, hasn't started yet, or isn't supported on the current platform.
- Returns a
Note: Calling these methods will have no effect if session recordings are disabled in your PostHog Project Settings. Manual starts still respect project ingestion controls, including sampling and event triggers.
Pause recording on a sensitive screen
Masking hides what's drawn on screen, but the recording still includes where each touch lands. On a PIN, passcode, or card-number keypad, the tap positions alone can reveal the value entered, so stop recording while the screen is shown and resume it once the screen is dismissed:
startSessionRecording() resumes the current session by default, so the replay continues as one recording with the keypad left out. The isSessionReplayActive() check matters: on iOS, startSessionRecording() installs the replay integration if it isn't there yet, so an app that wasn't recording would start when the screen closes. Only resuming when the screen found recording active keeps that from happening.
If you want taps left out of every recording rather than one screen's, set sessionReplayConfig.captureTouches = false before setup() instead (SDK >= 5.41.0); see privacy controls.
Record or ignore specific screens
You can combine these methods with your navigation to record only certain screens, or to pause recording on sensitive ones. For example, using a NavigatorObserver, stop recording on a sensitive route and resume otherwise:
Invert the check (startSessionRecording only for screens in an allowlist, stopSessionRecording otherwise) if you'd rather record just a specific set of screens.