|
1 | | -# mixpanel-ios-session-replay-package |
| 1 | +# Mixpanel iOS Session Replay SDK |
| 2 | + |
| 3 | +**Session Replay for iOS lets you visually replay your user's app interactions, providing powerful qualitative insights to complement your quantitative analytics.** |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Mixpanel Session Replay enables you to quickly understand **why** users behave a certain way in your app, complementing analytics insights on **where** they drop off. |
| 10 | + |
| 11 | +⚠️ **Beta Notice:** This SDK is currently available via invite-only Beta for Mixpanel Enterprise customers. Please thoroughly test before using in production. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Requirements |
| 16 | + |
| 17 | +- Active Mixpanel account (Enterprise) |
| 18 | +- Mixpanel Swift SDK `v4.3.1` or later |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +1. **Download** the [MixpanelSessionReplay.xcframework.zip](https://www.notion.so/Mixpanel-iOS-Session-Replay-SDK-Beta-10ae0ba9256280cdb6e0f39d594cb344?pvs=21) and unzip it. |
| 25 | +2. **In Xcode**, add the `.xcframework` to your target's **Frameworks, Libraries, and Embedded Content**. Set Embed to **Embed & Sign**. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Quick Start |
| 30 | + |
| 31 | +### SwiftUI |
| 32 | + |
| 33 | +```swift |
| 34 | +import Mixpanel |
| 35 | +import MixpanelSessionReplay |
| 36 | + |
| 37 | +struct YourApp: App { |
| 38 | + @Environment(\.scenePhase) private var scenePhase |
| 39 | + |
| 40 | + var body: some Scene { |
| 41 | + WindowGroup { |
| 42 | + ContentView() |
| 43 | + } |
| 44 | + .onChange(of: scenePhase) { |
| 45 | + if scenePhase == .active { |
| 46 | + let config = MPSessionReplayConfig(wifiOnly: false, recordSessionsPercent: 100.0) |
| 47 | + MPSessionReplay.initialize(token: Mixpanel.mainInstance().apiToken, |
| 48 | + distinctId: Mixpanel.mainInstance().distinctId, |
| 49 | + config: config)?.startRecording() |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### UIKit |
| 57 | + |
| 58 | +```swift |
| 59 | +import UIKit |
| 60 | +import Mixpanel |
| 61 | +import MixpanelSessionReplay |
| 62 | + |
| 63 | +@main |
| 64 | +class AppDelegate: UIResponder, UIApplicationDelegate { |
| 65 | + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { |
| 66 | + Mixpanel.initialize(token: "YOUR_MIXPANEL_TOKEN") |
| 67 | + |
| 68 | + let config = MPSessionReplayConfig(wifiOnly: false, recordSessionsPercent: 100.0) |
| 69 | + MPSessionReplay.initialize(token: Mixpanel.mainInstance().apiToken, |
| 70 | + distinctId: Mixpanel.mainInstance().distinctId, |
| 71 | + config: config) |
| 72 | + #if DEBUG |
| 73 | + MPSessionReplay.getInstance()?.loggingEnabled = true |
| 74 | + #endif |
| 75 | + |
| 76 | + return true |
| 77 | + } |
| 78 | + |
| 79 | + func applicationDidBecomeActive(_ application: UIApplication) { |
| 80 | + MPSessionReplay.getInstance()?.startRecording() |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## Configuration |
| 88 | + |
| 89 | +Customize your session replay by modifying `MPSessionReplayConfig`: |
| 90 | + |
| 91 | +- `wifiOnly`: Restricts uploads to WiFi connections (default: `true`). |
| 92 | +- `recordSessionsPercent`: Controls session sampling from `0.0` (none) to `100.0` (all). |
| 93 | +- `autoMaskedViews`: Automatically masks sensitive views (`Image`, `Text`, `Web` by default). |
| 94 | +- `autoCapture`: Controls automatic screenshot capture: |
| 95 | + - `.enabled` (default), `.viewControllerLifecycle`, `.touch`, or `.disabled`. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Manual Screenshot Capture |
| 100 | + |
| 101 | +If auto capture is disabled, trigger screenshots manually: |
| 102 | + |
| 103 | +```swift |
| 104 | +MPSessionReplay.getInstance()?.captureScreenshot() |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## Privacy & Data Masking |
| 110 | + |
| 111 | +By default, Mixpanel automatically masks sensitive views: |
| 112 | + |
| 113 | +- All text fields (cannot be unmasked) |
| 114 | +- Images, labels, WebViews (can be manually adjusted) |
| 115 | + |
| 116 | +To manually control sensitivity: |
| 117 | + |
| 118 | +```swift |
| 119 | +// SwiftUI |
| 120 | +Image("photo").mpReplaySensitive(true) |
| 121 | + |
| 122 | +// UIKit |
| 123 | +yourUIView.mpReplaySensitive = true |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Resources |
| 129 | + |
| 130 | +- [Full Documentation](https://mixpanel.com/docs/session-replay/session-replay-web) |
| 131 | +- [Legal: Beta Terms](https://mixpanel.com/legal/session-replay-beta-service-addendum) |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## Support |
| 136 | + |
| 137 | +Questions or feedback? Contact your Mixpanel Account Manager. |
0 commit comments