About five minutes, on the free plan, without a credit card.
1
Add the Swift package
In Xcode, choose File > Add Packages and enter the repository URL https://github.com/Openpanel-dev/swift-sdk. For a package-based project, declare it in Package.swift as shown. The package is OpenPanel's, published under the Openpanel-dev GitHub organisation.
dependencies: [
.package(url: "https://github.com/Openpanel-dev/swift-sdk")
]
2
Initialise with the Privytics API URL
Call this once at app launch, before any track calls. Setting apiUrl is what points the SDK at Privytics: left unset, it falls back to the upstream OpenPanel host and your events will not reach us. Replace YOUR_CLIENT_ID with the client ID from your project settings.
import OpenPanel
OpenPanel.initialize(options: .init(
clientId: "YOUR_CLIENT_ID",
apiUrl: "https://api.privytics.com"
))
3
Track an event
Call track from anywhere. The SDK is designed to be thread-safe, so you do not need to hop to the main queue.
OpenPanel.track(name: "Button Clicked", properties: ["button_id": "submit_form"])
4
Track screen views and app lifecycle
Set automaticTracking to true and the SDK records app_opened and app_closed for you. There is no dedicated screen view method, so send screen views as ordinary named events from onAppear or viewDidAppear. Use setGlobalProperties for values you want attached to every event.
OpenPanel.initialize(options: .init(
clientId: "YOUR_CLIENT_ID",
apiUrl: "https://api.privytics.com",
automaticTracking: true
))
OpenPanel.setGlobalProperties([
"app_version": "1.0.2",
"environment": "production"
])
// In a SwiftUI view
.onAppear {
OpenPanel.track(name: "screen_view", properties: ["screen": "Settings"])
}