Browse docs

Explore by section, then jump directly into a page.

Swift SDK

Integrate the FlashAnalytics Swift SDK in native iOS apps.

Use the Swift SDK for native iOS apps with SwiftUI or UIKit. It supports product events, identity, revenue tracking, experiments, app lifecycle, deep links, screen tracking, view interactions, native crash capture, and notification lifecycle helpers.

Install

.package(
  url: "https://github.com/NextGenCreativeSolutions/flashanalytics-swift.git",
  from: "1.0.9"
)

1.0.9 is the latest published tag currently available from the standalone Swift package repo.

Initialize

import FlashAnalytics

let analytics = FlashAnalytics.configureShared(
  options: FlashAnalyticsOptions(
    appId: "YOUR_APP_ID",
    secretKey: "YOUR_SECRET_KEY",
    endpoint: "https://api.flashanalytics.app",
    captureAppLifecycle: true,
    captureDeepLinks: true,
    captureScreenViews: true,
    captureViewInteractions: true,
    captureNativeCrashes: true,
    captureVariants: CaptureVariantsOptions(modes: [.session, .profile])
  )
)

Auto capture

  • App lifecycle via captureAppLifecycle
  • UIKit screen views via captureScreenViews
  • SwiftUI screen views via flashAnalyticsScreen
  • Deep links via handleOpenURL and handleUserActivity
  • Native crashes via captureNativeCrashes or captureErrors
  • Experiment auto-assignment via captureVariants

Manual error tracking

do {
  try riskyOperation()
} catch {
  analytics.trackError(
    error,
    eventName: "payment_failed",
    properties: ["orderId": orderId]
  )
}

SwiftUI

SomeView()
  .flashAnalyticsScreen(analytics, path: "Home")
  .onOpenURL { url in
    analytics.handleOpenURL(url)
  }

Notification lifecycle

The Swift SDK supports delivered, opened, dismissed, action-clicked, and expired events. Delivery and expiry require a Notification Service Extension. Open, dismiss, and action events require UNUserNotificationCenterDelegate in the app target.

{
  "aps": {
    "mutable-content": 1
  }
}

Session access

if let session = analytics.getSession() {
  print(session.id)
  print(session.estimatedExpiresAt)
  print(session.estimatedTtlMs)
}