Session replay installation

Last updated:

|Edit this page

Session replay enables you to record users navigating through your website or mobile app and play back the individual sessions to watch how real users use your product.

🚧 NOTE: Android is considered beta and is free while in beta. We are keen to gather as much feedback as possible so if you try this out please let us know. You can send feedback via the in-app support panel or one of our other support options.

Step one: Add PostHog to your app

The best way to install the PostHog Android library is with a build system like Gradle. This ensures you can easily upgrade to the latest versions.

All you need to do is add the posthog-android module to your App's build.gradle or build.gradle.kts:

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

Configuration

The best place to initialize the client is in your Application subclass.

Kotlin
import android.app.Application
import com.posthog.android.PostHogAndroid
import com.posthog.android.PostHogAndroidConfig
class SampleApp : Application() {
companion object {
const val POSTHOG_API_KEY = "<ph_project_api_key>"
// usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
const val POSTHOG_HOST = "https://us.i.posthog.com"
}
override fun onCreate() {
super.onCreate()
val config = PostHogAndroidConfig(
apiKey = POSTHOG_API_KEY,
host = POSTHOG_HOST
)
PostHogAndroid.setup(this, config)
}
}

Session replay requires PostHog Android SDK version >= 3.4.0, and it's recommended to always use the latest version.

Step two: Configure replay settings

Add sessionReplay = true to your PostHog configuration alongside any of your other configuration options:

Android
val config = PostHogAndroidConfig(apiKey = "<ph_project_api_key>").apply {
// Enable session recording. Requires enabling in your project settings as well.
// Default is false.
sessionReplay = true
// Whether text and text input fields are masked. Default is true.
// Password inputs are always masked regardless
sessionReplayConfig.maskAllTextInputs = true
// Whether images are masked. Default is true.
sessionReplayConfig.maskAllImages = true
// Capture logs automatically. Default is true.
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
sessionReplayConfig.screenshot = false
// Deboucer delay used to reduce the number of snapshots captured and reduce performance impact. Default is 1000ms
// Ps: it was 500ms (0.5s) by default until version 3.8.2
sessionReplayConfig.debouncerDelayMs = 1000
}

Limitations

  • Requires Android API >= 26.
  • Jetpack Compose is only supported if screenshotMode is enabled.
  • Custom views are partly supported, and only fully supported if screenshotMode is enabled.
  • WebView is not supported. A placeholder will be shown.
  • Keyboard is not supported. A placeholder will be shown.

Questions?

  • Robin
    9 days ago

    PostHogAndroid can't SessionReplay when instantiated using with()

    I'm working with PostHogAndroid and I have session replay and events setup. I noticed I was not getting any session replays if I instantiated PostHogAndroid using the with() function provided in the SDK. Is there anyway to get around this, I'd like to not refactor our analytics service in order to accommodate session replays.

  • Jayven
    12 days ago

    Wireframe mode for React Native

    Hi, I'm working on implementing session replay in a React Native app and noticed that while Android and iOS support wireframe mode, Ract Native doesn't. May I know what's the reason for this?

    Going into the implementation via RN, I assume that it uses the Android and iOS SDKs to power it. Some clarifications on how this SDK is implemented would be great and whether the wireframe mode is in the pipeline for RN (performance is important for mobile as the beautiful blog post written pointed out by PostHog).

    Thank you!

  • Nilanjan
    Edited 14 days ago

    'react/renderer/animations/primitives.h' file not found

    Hi, I'm encountering an issue while integrating session replay into my app. After installing posthog-react-native-session-replay and building the app, I get the error: 'react/renderer/animations/primitives.h' file not found. I'm using Expo prebuild. Has anyone faced a similar issue or have any insights on how to resolve this?!Group 1.png

    • Ioannis
      13 days ago

      Hey Nilanjan,

      Apologies for that! Please see this related issue here.

      Make sure that you are on version 0.1.9 for posthog-react-native-session-replay plugin, and the build errors should be resolved.

      We are currently working on a proper fix for this which should be out soon.

      Best, Ioannis

  • Zeeshan
    19 days ago

    Start/Stop session recording functions not available for React Native SDK

    Hi, is there any way to enable/disable session recording manually via posthog for React native SDK.

    https://posthog.com/tutorials/limit-session-recordings

    The functions mentioned here are not available in React Native SDK.

    • Manoel(he/him)
      15 days ago

      Hello,

      Not yet, there's an issue here already, feel free to upvote so we can eventually prioritize it.

      Thanks, Manoel

  • Akshay
    2 months ago

    PostHog Debug Session replay session id not rotated, sessionId 019xxxxxxxxxxxx01 and currentSessionId undefined.

    import React, { useEffect } from "react"; import { Stack } from "expo-router"; import { SafeAreaProvider } from "react-native-safe-area-context"; import { useRouter } from "expo-router"; import { AuthProvider, useAuth } from "../src/context/auth"; import { ActivityIndicator, AppState, View } from "react-native"; import { ThemeProvider } from "./ThemeContext"; import { usePostHog, PostHogProvider } from 'posthog-react-native'

    function RootLayoutNav() { const { isLoggedIn, token, isLoading } = useAuth(); const router = useRouter();

    useEffect(() => { if (!isLoading) { if (isLoggedIn && token) { router.replace("/(home)/home"); } else { router.replace("/(auth)/login"); } } }, [isLoggedIn, token, isLoading, router]);

    if (isLoading) { return ( <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> ); }

    return ( <Stack screenOptions={{ headerShown: false }}> <Stack.Screen name="(auth)" /> ); }

    export default function RootLayout() {

    const posthog = usePostHog();

    useEffect(() => { const handleAppStateChange = (nextAppState) => { if (nextAppState === 'active') { posthog?.capture('App Became Active'); } else if (nextAppState === 'background') { posthog?.flush(); } };

    const subscription = AppState.addEventListener('change', handleAppStateChange);
    return () => {
    subscription.remove();
    };

    }, [posthog]);

    return ( <PostHogProvider apiKey="phc_5I....kjj" options={{ host: 'https://us.i.posthog.com', enableSessionReplay: true, }} autocapture={true} debug >

    • Tim
      7 days ago

      The fix is in 3.6.2 of posthog-react-native. Get the latest and you should be good. If you do want to see more info btw, then you can set debug to true in the PostHogProvider.

  • Yarik
    2 months ago

    Session recording

    I use a paid subscription. • How can I increase the session replay retention to one year? • I know that I can download a session using the specific API, but my question is: how can I replay this session? For instance, if I download the session from the API and save it in my database, how can I replay it later?

  • Naresh
    2 months ago

    Activity logs but not able see the recordings

    I have disabled the recording session for my project, but I am unable to see the recording session. I got the message "Recording not found. It might be lost in space." I am not able to figure out what to do. Could you please help me understand what I did wrong?

    • Naresh
      Author2 months agoSolution

      Sorry Correction --> recording session is unabled even i am not able to see the recordings.

    • 2 months ago
      This answer was marked as unhelpful.

      To enable session recordings, you need to follow these steps:

      1. First, ensure session recordings are enabled in your PostHog Project Settings (1)

      2. Make sure disable_session_recording is not set to true in your PostHog initialization. Here's how to properly initialize with recordings enabled:

      posthog.init('<ph_project_api_key>', {
      api_host: 'https://us.i.posthog.com',
      disable_session_recording: false,
      })

      (1)

      1. Verify your domain is added to the authorized domains list in your project settings (2)

      If you're still not seeing recordings after these steps, check that:

      • Users haven't opted out of event capturing (users who opt out won't have their sessions recorded) (1)
      • You're not using Segment's SDK (Session Replay doesn't work with Segment's SDK) (1)

      If you need more specific control over which sessions to record, you can use features like:

      • URL trigger conditions (2)
      • Event trigger conditions (2)
      • Feature flags (2)
      • Sampling (2)
  • Ross
    3 months ago

    Session Replay's Not working

    Hi, I followed the setup guide to enable session replays in our expo react native app and enabled session replays in our posthog project configuration. We have autocapture enabled but mainly use custom events / screen captures. We have installed the session replay package and enabled it within posthog. Then we pushed to test flight and open testing for the play store to test the setup and session recording features, but sadly no session replays have been recorded. I'm wondering if you are able to help me understand why the sessions are not being recorded in the app.

    If I can provide any further info let me know. Looking forward to your help!

    • Manoel(he/him)
      3 months agoSolution

      Hello Ross,

      I noticed you are using the RN SDK 3.1.1, as you can see in the linked docs:

      Requires PostHog React Native SDK version >= 3.2.0, and it's recommended to always use the latest version.

      Please upgrade the SDK to the latest version and try again.

      Also, enable the debug mode by calling posthog.debug() and check out the logs, that may help find what is going on, thanks.

  • Eduardo
    3 months ago

    Recordings with custom fonts

    Hello hi! I noticed that the sessions recordings do not load correctly the font used for the website, is there some configuration needed so that we can see the session more in line with the experience of the website? btw amazing product, liking it so far :)

    • Jared
      20 days ago

      Following with the same issue!

  • Guy
    4 months ago

    Is there support for recording electron apps?

    I can send events, but is there an option to record an electron app session?

    • Benjamin
      3 months ago

      i am able to record on development version of my electron app

  • ERICK
    4 months ago

    Session replay react-native web

    Hello

    Is there a plan for session replay to be released for react-native web?

    • Manoel(he/him)
      4 months ago

      Hello, not in the near future but upvote this issue so we can get a feeling if many people would need it.

  • Tyler
    4 months ago

    How to Un-Hide Form Inputs

    We appreciate that PostHog takes privacy seriously - but there are a couple fields in our platform that don't have sensitive information but instead are key configuration settings on our platform - so we need to see what users are typing so we can troubleshoot when it doesn't work. It seems like every user input field in screen recording is censored. How can we modify this? Is it something to do with the "attributes" of the input field in our Website code or is it a setting in PostHog?

    Thanks! Love the product so far!

    • Zeeshan
      20 days ago

      Same question from me regarding Session replay Masking of custom sensitive inputs for React Native.

      "ph-no-capture" is not working is we give autoCapture = true in the Posthog config.

  • Rajiv
    4 months ago

    Is Event Autocapture required for Session Replay?

    Is it possible to use Session Replay if Event Autocapture is disabled?

    • Paul(he/him)
      4 months agoSolution

      Hey Rajiv,

      You can use session replay without autocapture of events.

      If you have autocaptured events you can use them to search for sessions and can see their information alongside the recordings in the inspector

      But you can use them separately!

    • Rajiv
      Author4 months ago

      Hi Paul,

      Good to know. Thank you!

  • Suraj
    4 months ago

    Is session replay available for React native?

    I can see it's in beta for Android and IOS but couldn't find doc for React native. Is it available or any chance would be available in future for React native?

  • Rob
    4 months ago

    Query Session Replays by Console Output

    Is it possible to query session replays by console in order to, for instance, watch all replays which have a particular error?

  • Vincent
    5 months ago

    Session recording gets restarted on each link leave

    I'm using remix, which is SSR, it looks like on each link it's generating a new posthog id. This kind of started once I started using identify instead of just setPersonProperties.

    • Vincent
      Author5 months ago

      So previously, (on localhost), I'm able to record the entire session with different link and even logging in and out. Problem is if I log out and log in with a different email it will replace that session entirely with the new user (which is okay but not the best). Then I tried using identify, which might've triggered the merge restriction and started to produce different session ids? Now the recordings are all chopped up that every link click starts a new recording.

    • Vincent
      Author5 months agoSolution

      Ah crap, I was calling reset on every render by accident.

  • Zuhayr
    7 months ago

    Session Replays for New Users

    Is there a way I can trigger session recording to start after a specific event? I want to have session recording turned on for new users who signed up for our platform to monitor our onboarding process performance

  • Zaeem
    7 months ago

    Session Replay Restriction

    I am trying to restrict some session recordings to some specific member in the organization.

  • Tacos
    8 months ago

    posthog-js-lite

    Does posthog-js-lite support session replay?

    • Manoel(he/him)
      8 months ago

      Hello Tacos,

      Sadly not, only the JS SDK.

      Thanks.

      Best, Manoel

    • Tacos
      Author8 months ago

      Bummer. The main JS SDK is astronomically huge – it causes a 100KB increase in my bundle sizes :(

  • John
    10 months ago

    How to filter session replay based on mouse click and keyboard input counts?

    In the session replay interface, there are small icons with counts for clicks and keyboard inputs.

    How do I filter by those in the interface?

    • Paul(he/him)
      10 months ago

      Great, thanks for sharing!

      In this ordering "active duration" is determined by user activity... so it might be a four hour reecording but only have an hour of activity, but the most active would be first - it is only a workaround for you though :)

Was this page useful?

Next article

How to watch recordings

To watch recordings, you can visit the Replay page. When watching replays, you can change the playback speed, as well as select the option 'skip inactivity' - this skips parts of the recording where the user was inactive on the page. You can also watch recordings by clicking on any data point in an insight. This opens a list of persons and displays a "watch recording" button if available. This is especially useful in funnels , where you can drill down and watch recordings of users who…

Read next article

PostHog.com doesn't use third party cookies - only a single in-house cookie.

No data is sent to a third party.

Ursula von der Leyen, President of the European Commission