Skip to main content

Install on iOS with Swift

Use the native Swift SDK when your product is an iOS app built with Swift or SwiftUI. It is a Swift Package Manager package with no external dependencies, targeting iOS 15 and later. Enable Mobile apps traffic during Create your first property before sending events.

Install

In Xcode, choose File → Add Package Dependencies… and enter the package repository URL:

https://github.com/Nexly-App/nexly-ios

Pick the latest version and add the Nexly product to your app target.

Initialize

Initialize once, for example from your @main app's initializer:

import Nexly

@main
struct MyApp: App {
init() {
Nexly.initialize(appId: "your-app-id", key: "your-ingest-key")
}

var body: some Scene {
WindowGroup { ContentView() }
}
}

Use the App ID and Ingest key from Settings → Installation. Do not use a personal API token for SDK collection.

Track screens and events

Send a screenview when the visible screen changes:

Nexly.screenview("Settings")

Emit custom events from anywhere in the app:

Button("Checkout") {
Nexly.customEvent("checkout_started", cdata: ["cart_value_cents": 4200])
}

Engagement tracking (active seconds, heartbeats, session end) is driven automatically by app lifecycle notifications, matching the React Native SDK's behavior.

Privacy mode and identity

The Swift SDK supports the same privacy mode as the other SDKs: when enabled, it never reads or writes on-device storage for the visitor and session IDs. Unlike the JavaScript SDKs, it can be toggled at runtime — useful for a consent switch in your settings screen:

Nexly.setPrivacyMode(true)

You can also override the visitor or session ID, for example to link app events to an identity your backend already knows:

Nexly.setVisitorId("your-visitor-id")
Nexly.setSessionId("your-session-id")

Changes take effect on the next event; no reinitialization is needed.

Allowed origins

Native iOS traffic uses a dedicated SDK traffic source instead of a browser origin. Enable Mobile apps in Settings → Ingest so the collector accepts events from the SDK. See Ingest settings for details.

Verification

Use the events feed to confirm events arrive with the iOS (Swift) source. The Technology widget shows Swift traffic as browser Swift on iOS mobile devices.