Record User Session in your App
PostHog has introduced an amazing new (beta) feature that will make you feel like a KGB agent. It's called session recordings. Basically, it records the user's screen and interactions with the app, so you can see exactly how they use your application.
How to Enable Session Recordings
To enable session recordings, you need to set the sessionReplay
property to true
in the PostHogConfig
object during initialization.
We do that in the initPostHog
that is called by the AppDelegate when the app launches.
SwiftyLaunch sets it to true
by default, but if you want to disable it, you can do so by setting it to false
.
Additionally, we have set the screenshotMode
property to true
, which is required for session recordings to work in SwiftUI, and disabled
automatic masking of all text inputs and images.
Make sure to mask any sensitive data before enabling session recordings, as they will be recorded as well. Refer to Masking and Redacting in Session Replays (opens in a new tab)
extension Analytics {
static public func initPostHog() {
do {
// ... initial setup
config.sessionReplay = true
config.sessionReplayConfig.screenshotMode = true
config.sessionReplayConfig.maskAllImages = false
config.sessionReplayConfig.maskAllTextInputs = false
PostHogSDK.shared.setup(config)
} catch {
print("[ANALYTICS] PostHog Init Error: \(error.localizedDescription)")
return
}
}
}