Product analytics for iOS
Pug ships a native Swift SDK for iOS, iPadOS, and Mac Catalyst. Initialize it once at launch and app opens, screen views, and installs are tracked from there; typed methods cover the well-known events, and anything else goes through Pug.track.
Add Pug to iOS
Four steps, start to first insight. Everything below uses the iOS SDK exactly as it ships.
-
Add the package
The SDK is a Swift package. In Xcode, choose File > Add Package Dependencies, enter the repository URL, and add the Pug library to your app’s target; in a Package.swift, add it as below. It needs iOS 15 or newer and Xcode 16, and has no runtime dependencies beyond Apple’s own frameworks.
Package.swiftdependencies: [ .package(url: "https://github.com/pug-sh/sdk-ios.git", from: "0.1.1"), ], targets: [ .target(name: "YourApp", dependencies: [.product(name: "Pug", package: "sdk-ios")]), ], -
Initialize at launch
Call Pug.initialize once, in application(_:didFinishLaunchingWithOptions:) or in your SwiftUI App’s init(), so the SDK sees the first screen and app_open of every launch. It does no disk or network work on the calling thread, so it is safe on the main thread. It throws Pug.ConfigurationError only for a blank project id, a key that is not the project’s public key (pub_…), or an endpoint that is not an http(s) URL.
MyApp.swiftimport Pug import SwiftUI @main struct MyApp: App { init() { do { try Pug.initialize( projectId: "YOUR_PROJECT_ID", options: Pug.Options(apiKey: "pub_YOUR_PUBLIC_KEY") ) } catch { assertionFailure("Pug was not started: \(error)") } } var body: some Scene { WindowGroup { ContentView() } } } -
Name your SwiftUI screens
Each of your view controllers that appears on a different screen is a screen_view, named after its type. SwiftUI views are not view controllers, so name each SwiftUI screen with .pugScreen on the view it shows, inside its NavigationStack: it is tracked as a view controller is, and later events carry it as $url, with the one before as $referrer. For a screen that is neither, such as a game level, call Pug.screen.
ProductList.swiftNavigationStack { List(products) { product in NavigationLink(product.name) { ProductView(product: product) } } .pugScreen("Products") } // A screen that is neither: Pug.screen("Level 3") -
Identify people and track events
identify() links the events tracked anonymously so far to your user id, with optional traits, and reset() on logout starts a new anonymous id and session. The generated Pug.track namespace has a method per well-known event with labeled arguments; anything custom goes through Pug.track(_:properties:). Every call returns at once, from any thread, and never throws.
Checkout.swiftPug.identify("user_123", traits: ["plan": "pro"]) // Typed method for a well-known event: Pug.track.purchase(productId: "sku-1", amount: 99.50, currency: "USD") // Anything else, by name: Pug.track("tutorial_finished", properties: ["stepCount": 4]) // On logout: Pug.reset()
What to watch for in iOS
The specifics that decide whether the numbers you see are the numbers that happened.
SwiftUI screens need a name
Automatic screen views come from your view controllers, and the SDK skips SwiftUI’s own hosting controllers, so a SwiftUI app reports a screen only once you name it with .pugScreen. A named screen follows the view controllers’ rules, sheets included, and is tracked with autoScreenViews off too.
Consent is granted by default
To wait for a banner, set defaultTrackingConsent = .denied in Pug.Options. While denied, events and identify calls are dropped rather than queued; the choice is saved across launches, and an app_install, app_open, or screen view that consent held back at launch is tracked when the user opts in.
Lifecycle and installs are automatic
app_open fires when the app comes to the foreground, and app_close when it enters the background; Control Center, a call, or a system alert in front of the app is not an exit. app_install carries installSource: com.apple for the App Store, com.apple.testflight for TestFlight and the builds Xcode installs.
Built for suspension and the first unlock
Entering the background sends what is queued inside a background task, and a send that suspension cuts short is retried with the same event ids, which the server deduplicates. Events, identity, and consent live in Application Support, excluded from backups; an app launched in the background before the device’s first unlock waits for it instead of starting a new identity.
Product analytics in your iOS app
-
Auto-tracking from initialize
app_open and app_close as the app comes and goes, a screen_view each time one of your view controllers appears on a new screen, and app_install or app_update on the first launch of each version.
-
Typed well-known events
Pug.track.purchase(…), Pug.track.search(…) and the rest are generated from the event schemas with labeled arguments; anything custom goes through Pug.track(_:properties:).
-
Consent that survives restarts
Start denied, opt in or out from your own banner, and the choice is saved. What consent held back at launch is tracked once the user says yes.
-
The same insights as web
Trends, funnels, retention, flows, and unified profiles: one project can hold your iOS app, your Android app, your website, and your backend.
Read it in the docs
The iOS SDK reference goes deeper than a setup page can: every option, every event, and the edge cases.
Which Apple platforms and Swift versions does it support?
iOS and iPadOS 15 and up, Mac Catalyst, and iPhone and iPad apps running on a Mac, built with Xcode 16 or newer. The SDK is written in Swift 6; apps in the Swift 5 language mode can use it, and Objective-C code can call it through a Swift wrapper of your own.
Is it on CocoaPods or Carthage?
No. The SDK ships through Swift Package Manager only, which resolves it from its GitHub repository: in Xcode, File > Add Package Dependencies adds it to an app target.
Do I need an App Tracking Transparency prompt?
No. The SDK reads no advertising identifier, identifierForVendor, or device name, and tracks no one across other companies’ apps. It ships a privacy manifest, which Xcode adds to your app’s privacy report; your App Store privacy answers still cover what your own events and traits carry.
Why do I see no screens in my SwiftUI app?
SwiftUI views are not view controllers, and the SDK skips SwiftUI’s hosting controllers, so name each screen with .pugScreen("Name") on the view it shows. A UIKit app gets its view controllers as screens with no code.
Does the AGPL apply to my app?
No. The SDK you ship in your app is MIT-licensed; AGPL-3.0 covers the Pug server. Self-host it and point the SDK there with endpoint in Pug.Options, or use Pug Cloud, free up to 100k events a month.
Can one project hold my iOS app, my Android app, and my website?
Yes. Call identify() with the same user id from iOS, Android, the Web SDK, and your server, and the timelines resolve to one person, so a funnel can start on your site and finish in either app.
Add Pug to your iOS app.
Create a project, add the snippet, and watch the Live view fill up. Or open the demo first: the real dashboard on a sample pet shop, with no sign-up.
Questions? Email hello@pug.sh