iOS SDK

Install the Swift package and send your first private event.

Use the official AppMetricsKit Swift Package to capture onboarding, paywall, purchase, subscription, and app-health events without collecting personal data.

Install from GitHub

In Xcode, open File > Add Package Dependencies, paste the package URL, then select the AppMetricsKit product.

View package
Code
https://github.com/appmetricskit/appmetrikskit-ios-swift.git

Package details

Repository
appmetricskit/appmetrikskit-ios-swift
Product
AppMetricsKit
Platforms
iOS 15+, macOS 12+

Swift Package manifest

If your app uses its own Package.swift, add the package and product manually.

Code
.package(  url: "https://github.com/appmetricskit/appmetrikskit-ios-swift.git",  from: "0.1.2")
Code
.product(  name: "AppMetricsKit",  package: "appmetrikskit-ios-swift")

Configure once at app launch

Generate an ingest key in AppMetricsKit, then configure the SDK with your deployed ingest endpoint.

Code
import AppMetricsKitimport SwiftUI
@mainstruct ExampleApp: App {  init() {    AppMetricsKit.configure(      AppMetricsConfiguration(        ingestURL: URL(string: "https://appmetricskit.com/api/ingest")!,        ingestKey: "amk_live_...",        testMode: false,        allowedPayloadKeys: ["plan", "source", "price", "errorCode"],        blockedPayloadKeys: ["email", "phone", "name"]      )    )  }
  var body: some Scene {    WindowGroup {      ContentView()    }  }}

Track events

Event names use Namespace.action. The SDK hashes user IDs on device before sending them as anonymousUserId.

Code
AppMetricsKit.identify(userId: user.id)
AppMetricsKit.track(  "Paywall.viewed",  payload: ["plan": "pro_monthly", "source": "onboarding"])
AppMetricsKit.track(  "Purchase.completed",  payload: ["plan": "pro_monthly"],  floatValue: 29.99)

Built-in helpers

Use helper methods for the event names that power AppMetricsKit dashboards.

Code
AppMetricsKit.trackAppLaunch()AppMetricsKit.trackOnboardingStarted()AppMetricsKit.trackOnboardingCompleted()AppMetricsKit.trackPaywallViewed(plan: "pro_monthly")AppMetricsKit.trackPurchaseCompleted(plan: "pro_monthly", amount: 29.99)AppMetricsKit.trackError(name: "network_timeout")

Privacy defaults

  • Raw user IDs are hashed on device with SHA-256.
  • The bundled manifest declares product interaction and the optional hashed user ID as linked data for analytics, with tracking disabled.
  • Payloads are flat string, number, or boolean values only.
  • Blocked keys such as email, phone, name, IP, location, and IDFA are dropped.
  • Values that look like email addresses, phone numbers, or card numbers are dropped.
Review Apple privacy guidance

Offline queue and flushing

Events are persisted to disk, batched, retried for network failures, and protected by stable event IDs for safe retries.

Code
let result = await AppMetricsKit.flush()print("Delivered events:", result.delivered)