The OpenPanel Swift SDK allows you to integrate OpenPanel analytics into your iOS, macOS, tvOS, and watchOS applications.
- Easy-to-use API for tracking events and user properties
- Automatic collection of app states
- Support for custom event properties
- Shared instance for easy access throughout your app
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
- Xcode 12.0+
- Swift 5.3+
You can add OpenPanel to an Xcode project by adding it as a package dependency.
- From the File menu, select Add Packages...
- Enter
https://github.com/Openpanel-dev/swift-sdkinto the package repository URL text field - Click Add Package
Alternatively, if you have a Package.swift file, you can add OpenPanel as a dependency:
dependencies: [ .package(url: "https://github.com/Openpanel-dev/swift-sdk") ]
First, import the SDK in your Swift file:
import OpenPanel
Then, initialize the OpenPanel SDK with your client ID:
OpenPanel.initialize(options: .init( clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET" ))
To track an event:
OpenPanel.track(name: "Button Clicked", properties: ["button_id": "submit_form"])
To identify a user:
OpenPanel.identify(payload: IdentifyPayload( profileId: "user123", firstName: "John", lastName: "Doe", email: "[email protected]", properties: ["subscription": "premium"] ))
To set properties that will be sent with every event:
OpenPanel.setGlobalProperties([ "app_version": "1.0.2", "environment": "production" ])
To create an alias for a user:
OpenPanel.alias(payload: AliasPayload(profileId: "user123", alias: "u123"))
To increment a numeric property:
OpenPanel.increment(payload: IncrementPayload(profileId: "user123", property: "login_count"))
To decrement a numeric property:
OpenPanel.decrement(payload: DecrementPayload(profileId: "user123", property: "credits_remaining"))
You can temporarily disable tracking during initialization:
OpenPanel.initialize(options: .init( clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", disabled: true ))
You can set up custom event filtering during initialization:
OpenPanel.initialize(options: .init( clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", filter: { payload in // Your custom filtering logic here return true // or false to filter out the event } ))
The OpenPanel SDK is designed to be thread-safe. You can call its methods from any thread without additional synchronization.
The SDK automatically tracks app lifecycle events (app_opened and app_closed) if automaticTracking is set to true during initialization.