iOS session replay installation

  1. Install the SDK

    Required

    Add PostHog to your Podfile:

    Podfile
    pod "PostHog", "~> 3.0"

    Or install via Swift Package Manager:

    Package.swift
    dependencies: [
    .package(url: "https://github.com/PostHog/posthog-ios.git", from: "3.0.0")
    ]
    SDK version

    Session replay requires PostHog iOS SDK version 3.6.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:

    AppDelegate.swift
    import Foundation
    import PostHog
    import UIKit
    class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    let POSTHOG_API_KEY = "<ph_project_api_key>"
    let POSTHOG_HOST = "https://us.i.posthog.com"
    let config = PostHogConfig(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
    // Whether network requests are captured in recordings. Default is true
    // Only metric-like data like speed, size, and response code are captured.
    // No data is captured from the request or response body.
    config.sessionReplayConfig.captureNetworkTelemetry = true
    // Whether replays are created using high quality screenshots. Default is false.
    // Required for SwiftUI.
    // If disabled, replays are created using wireframes instead.
    // The screenshot may contain sensitive information, so use with caution
    config.sessionReplayConfig.screenshotMode = true
    PostHogSDK.shared.setup(config)
    return true
    }
    }

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

    SwiftUI support

    SwiftUI is only supported if the screenshotMode option is enabled. Custom views and WebViews also require screenshot mode for full support.

  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.