iOS SDK (Swift)
The SDK is a Swift package (iOS 16+). Add it in Xcode via File → Add Package Dependencies… using the Astronaut package URL, then import Astronaut.
1. Configure once, at launch
import Astronaut
@main
struct YourApp: App {
init() {
Astronaut.shared.configure(
AstronautConfiguration(trackingId: "naut_xxxxxxxx")
)
}
// ...
}2. Track app opens
Call this when your app becomes active. The first call per install is flagged automatically, which powers install attribution.
Astronaut.shared.trackAppOpen()
3. Track purchases and trials
Astronaut.shared.trackPurchase(
revenue: 9.99,
currency: "USD"
)Revenue rolls up across the Overview, traffic source/referrer, creators, and the per-user journey, converted to a single display currency.
If you offer a free trial, report the start of it too. It carries no revenue — a trial is free, and reporting it as a zero-value purchase would be indistinguishable from a real one:
Astronaut.shared.trackTrialStart(
productId: "com.example.pro.monthly"
)Call it when the trial begins, not when it converts — the conversion is a purchase. Requires SDK 2.3.1 or newer.
Both of these are what your app observed at the moment it happened, counted once and never corrected. Connecting RevenueCat replaces them with the store’s own record — renewals, refunds and trials that lapse without ever reaching your code — and you can switch between the two sources per app in settings.
4. Custom events
Astronaut.shared.send(
eventType: "completed_onboarding",
metadata: ["plan": "pro"]
)5. Identify users (optional)
By default the dashboard shows an anonymous handle per device. Once you know who the user is (e.g. after sign-in), call identify to attach a real name/email — it then appears on the user journey. Only send identity you have a lawful basis to process; see the privacy policy.
Astronaut.shared.identify(
email: "jane@acme.com",
name: "Jane Doe",
traits: ["plan": "pro"]
)The SDK tags every event with the build environment and your app's version (CFBundleShortVersionString) automatically, so you can segment activity by release — see Environments. To send notifications, see Push notifications.
From SDK 2.4.0 it also sends the device model, as the hardware identifier iOS reports (iPhone16,2) rather than a marketing name — a name that would go stale with every device Apple ships after your build. It appears on the user journey. Events sent by older SDK versions have no model and cannot be backfilled, so treat a breakdown by device as covering only the events that reported one.