How the Apple SDK works
One Swift package for iOS, iPadOS, macOS, tvOS, watchOS, and visionOS, with a core and a library for each optional part. Set it up once with the parts you added and installs, opens, screens, taps, links, notifications, purchases, crashes, and hangs are captured with no other code.
| Setting | Value |
|---|---|
| Host | Your project's tracking hostname, such as https://m.example.com, from Setup |
| Key | The ingest key (mpk_) of an iOS or Apple source, from Setup. It ships in the app, so it can only send events. |
| Systems | iOS 13, macOS 10.15, tvOS 13, watchOS 6, and visionOS 1 or later. Purchases need iOS 15. |
| Delivery | Queued on the device, sent every 10 seconds, at 50 events, and when the app goes to the background, retried with the same event ids so nothing is lost or counted twice |
Install and set up
Add the package by its address and the libraries you want, then call setup with their parts as early as the app starts, so the first screen and a link that opened the app are seen.
// Package.swift .package(url: "https://gotmode.com/sdk/swift/ModeMetrics.git", from: "0.1.0") // and in your app's target, the core and each part it uses .product(name: "ModeMetrics", package: "ModeMetrics"), .product(name: "ModeMetricsAutocapture", package: "ModeMetrics"), .product(name: "ModeMetricsCrashes", package: "ModeMetrics"),
In Xcode, choose File, Add Package Dependencies, paste https://gotmode.com/sdk/swift/ModeMetrics.git in the search field and add the libraries your app uses. The core is all an app needs. Each part is a library of its own, so an app compiles only the parts it adds.
| Library | Part | What it adds |
|---|---|---|
ModeMetrics | the core | Installs, opens, sessions, your own events, people, feature flags, consent, handled errors, and the links and notifications your app hands over |
ModeMetricsAutocapture | .autocapture | Screens and taps from UIKit, AppKit, and SwiftUI, and the .modeScreen modifier |
ModeMetricsLinks | .links | Custom scheme and universal links, found in the app and scene delegates |
ModeMetricsPush | .push | Notifications received and opened, the push token, and the notification permission |
ModeMetricsPurchases | .purchases | App Store purchases from StoreKit 2, and Mode.capturePurchase |
ModeMetricsCrashes | .crashes | Crashes from uncaught exceptions and fatal signals, and MetricKit hangs and terminations |
Mode serves its SDKs itself, not from a public package registry. The package is a git repository on gotmode.com. Each version is a tag that never moves, and Package.resolved pins its commit.
| Package | Version |
|---|---|
https://gotmode.com/sdk/swift/ModeMetrics.git | 0.1.0 |
import ModeMetrics import ModeMetricsAutocapture import ModeMetricsCrashes @main struct ShopApp: App { init() { Mode.setup(ModeConfig(key: "YOUR_INGEST_KEY", host: URL(string: "https://m.example.com")!), parts: [.autocapture, .crashes]) } var body: some Scene { WindowGroup { HomeView() } } }
In a UIKit app, call it at the top of application(_:didFinishLaunchingWithOptions:).
What is captured on its own
Every event lands in the same reports as your site's, with the same people and sessions.
| Event | Part | When |
|---|---|---|
$app_installed | core | The first launch, with the version and build, and the Apple Ads campaign, ad group, keyword, and ad when a search ad brought the install |
$app_updated | core | The first launch of a new version or build, with the previous one |
$app_opened | core | A cold launch, with how long it took to start, and every return to the foreground, with how long the app was away and the link or notification that opened it |
$app_backgrounded | core | The app left the screen, with how long it was in use |
$screen | .autocapture | A screen appeared. UIKit screens by their view controller, SwiftUI screens by their view or navigation title, Mac windows by their content, with the screen before it and how long it was shown |
$click, $rage_click | .autocapture | A tap on a button, switch, segmented control, slider, bar button, list row, or SwiftUI button or link, and three fast taps in one place |
$deep_link_opened | .links | A custom scheme link or a universal link opened the app or reached it while open. Its UTM parameters, the Mode click id, and sub ids are kept, so later signups and purchases are credited to the campaign |
$push_received, $push_opened | .push | A notification arrived while the app was open, or the person opened one, with its message id, campaign, action, category, and thread. A notification handed over twice counts once, and one the app scheduled itself is not push |
$push_registered, $permission_change | .push | The app registered for notifications, and the notification permission changed |
$purchase, $subscription_started, $trial_started, $refund | .purchases | App Store purchases, renewals on any device, Ask to Buy, offer codes, and refunds, each stored once even when App Store Server Notifications report it too |
$exception | .crashes | Crashes from uncaught exceptions and fatal signals, hangs, CPU and disk write terminations, and watchdog kills, with the screens and events before them |
The first event of each session also carries the device (system, model, display, dark mode, text size, accessibility settings, battery, network, and how the app was installed). Every event carries the screen it happened on.
Your own events and people
Add what only your app knows, and tie the device to the person once they sign in.
Mode.capture("order_placed", properties: ["plan": "pro", "items": 3]) Mode.identify("user_123", set: ["plan": "pro"]) Mode.group("company", key: "acme") Mode.register(["app_flavor": "pro"]) Mode.reset() // on sign out
A different user on the same device starts a new person, two users are never merged. setPersonProperties and unsetPersonProperties change the person before or after sign in. registerOnce and registerForSession keep properties on every event, once, or for the session. Name a screen yourself with Mode.screen("Checkout"), or a SwiftUI screen with .modeScreen("Checkout") from ModeMetricsAutocapture. Mode.captureException(error) sends a handled error, and Mode.openURL, Mode.pushOpened, and Mode.registerPushToken hand over what the links and push parts would otherwise find.
Consent and opting out
Wait for the person's answer before anything is stored, or start everyone opted out.
var config = ModeConfig(key: "YOUR_INGEST_KEY", host: URL(string: "https://m.example.com")!) config.consent = .pending // hold events in memory until setConsent config.optOut = true // or start opted out until optIn Mode.setup(config) Mode.setConsent(.granted) Mode.optOut() // stops capture and deletes the queue, remembered across launches
With ad storage denied, ad click ids and the Mode click id are left out of every event.
Session replay
Watch what people saw in your app, next to what they did, on iOS, iPadOS, tvOS, and visionOS.
ModeMetricsReplay library yet, so no app can record sessions today. Its setup steps will be listed here once it is published.Once published, the replay library will send a wireframe of each screen about once a second, never a screenshot. Each view will become a box with its frame, colors, and font, and touches will show where people tapped and dragged. Text, images, and input values will be masked until you unmask them, secure fields will always stay masked, and the keyboard will never be recorded.
Feature flags
Read your project's flags in the app. They load at launch, after sign in, and after group and property changes, and are kept for the next launch.
if Mode.isFeatureEnabled("new-checkout") { ... } let variant = Mode.featureFlag("price-test") as? String Mode.onFeatureFlags { flags in ... }
Values your server already knows can be given at setup in config.bootstrap, so the first screen uses them.
Purchases
With the purchases part, App Store purchases are captured on their own. To record one the moment it happens, pass the transaction too, and it is still stored once.
import ModeMetricsPurchases if case .success(.verified(let transaction)) = try await product.purchase() { Mode.capturePurchase(transaction) await transaction.finish() }
A consumable the app finishes at once is seen only this way, or when the app's Info.plist sets SKIncludeConsumableInAppPurchaseHistory.
Settings
| Setting | Default | What it does |
|---|---|---|
captureScreens, captureTaps, captureLifecycle, captureDeepLinks, capturePush, capturePurchases, captureCrashes | on | Each kind of automatic capture, of the parts the app turned on |
maskText | off | Leaves the visible text of controls out of taps |
swizzling | on | Off disables method swapping in the autocapture, links, and push parts. Notifications, manual calls, and SwiftUI modifiers still work |
appGroup | none | Shares the person and the queue between the app and its extensions |
beforeSend | none | A last look at every event, return nil to drop it |
debug | off | Logs what is captured and sent |
The source's settings in Mode can turn screens and taps off and sample sessions with no app release.
What is never sent
Nothing typed is sent, and taps, links, and notifications keep only what the tables above list.
Never sent, the content of any text field or secure entry, notification titles and bodies, advertising identifiers, contacts, location, or a property whose name reads as a secret. Links lose sign in tokens, codes, passwords, and keys before they are kept, and email addresses become [email].