Unity Session Replay installation

  1. Install the SDK

    Required

    Requires Unity 2021.3 LTS or later with .NET Standard 2.1 API compatibility level.

    In the Unity Editor, open Window > Package Manager, click the + button, select Add package from git URL, and enter:

    text
    https://github.com/PostHog/posthog-unity.git?path=com.posthog.unity

    See the Unity SDK docs for other installation methods and full setup instructions.

  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. You can also configure it via the Unity Inspector in Edit > Project Settings > PostHog.

    GameManager.cs
    using PostHogUnity;
    using PostHogUnity.SessionReplay;
    PostHog.Setup(new PostHogConfig
    {
    ApiKey = "<ph_project_token>",
    Host = "https://us.i.posthog.com",
    SessionReplay = true,
    SessionReplayConfig = new PostHogSessionReplayConfig
    {
    // Min seconds between captures (default: 1.0)
    ThrottleDelaySeconds = 1.0f,
    // JPEG quality 1-100 (default: 80)
    ScreenshotQuality = 80,
    // Resolution scale 0.1-1.0 (default: 0.75)
    ScreenshotScale = 0.75f,
    // Record HTTP request metadata (default: true)
    CaptureNetworkTelemetry = true,
    // Record console logs (default: false)
    CaptureLogs = false,
    // Log, Warning, or Error (default: Error)
    MinLogLevel = SessionReplayLogLevel.Error,
    }
    });
    How it works

    The Unity SDK captures screenshots using AsyncGPUReadback to avoid blocking the main thread. It also records touch/mouse input, network requests, and console logs alongside each screenshot. Session replay requires AsyncGPUReadback support and is automatically disabled on WebGL.

    No masking support

    The Unity SDK uses screenshot-based capture. Unlike web and mobile SDKs, there is no built-in masking for text, images, or other UI elements. Screenshots may contain sensitive information. Make sure you are not displaying personal data or secrets on screen during recorded sessions.

    Limitations

    The Unity SDK reads the Record user sessions toggle from PostHog project settings, but more granular options like CaptureNetworkTelemetry, CaptureLogs, and sampling are not remotely configurable and must be set locally in code at initialization time.

  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.