Mobile SDKv1.xMIT License
iOS / Swift SDK
AcaiSwift supports iOS 13+, macOS 10.15+, tvOS 13+, and watchOS 7+. Features include autocapture (screen views, interactions, network requests), offline mode, COPPA controls, and a plugin pipeline.
Installation
Swift Package Manager (recommended):
dependencies: [
.package(url: "https://github.com/your-org/Acai-Swift.git", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [.product(name: "AcaiSwift", package: "Acai-Swift")]
)
]
CocoaPods:
pod 'AcaiSwift', :git => 'https://github.com/your-org/Acai-Swift.git'
Initialise
import AcaiSwift
let acai = Acai(configuration: Configuration(
apiKey: "YOUR_API_KEY",
serverUrl: "https://events.yourdomain.com/2/httpapi",
autocapture: [
.sessions,
.screenViews,
.elementInteractions,
],
logLevel: .warn,
))
Track events
acai.track(eventType: "Button Tapped")
acai.track(eventType: "Purchase Completed", eventProperties: [
"product_id": "prod_123",
"price": 49.99,
"currency": "USD",
])
acai.flush()
Identify users
acai.identity.userId = "user_abc123"
let identify = Identify()
.set(property: "plan", value: "pro")
.setOnce(property: "signup_date", value: "2024-01-15")
.add(property: "session_count", value: 1)
.append(property: "tags", value: "power-user")
.unset(property: "trial_active")
acai.identify(identify: identify)
acai.setGroup(groupType: "company", groupName: "Acme Corp")
acai.identity.userId = nil
acai.reset()
Plugins
import AcaiSwift
class AppVersionPlugin: Plugin {
var type: PluginType = .enrichment
func execute(event: BaseEvent?) -> BaseEvent? {
guard let event else { return nil }
var props = event.eventProperties ?? [:]
props["app_version"] = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
event.eventProperties = props
return event
}
}
acai.add(plugin: AppVersionPlugin())
Config reference
| Option | Type | Default | Description |
|---|
apiKey | String | required | Your project API key. |
serverUrl | String? | nil | Custom collector endpoint. |
autocapture | AutocaptureOptions | .sessions | .sessions · .screenViews · .elementInteractions · .networkTracking |
logLevel | LogLevelEnum | .warn | .off · .error · .warn · .log · .debug |
flushQueueSize | Int | 30 | Events per batch before flush. |
flushIntervalMillis | Int | 30000 | Flush interval in ms. |
optOut | Bool | false | Disable all tracking. |
flushEventsOnClose | Bool | true | Flush on app backgrounded. |
enableCoppaControl | Bool | false | COPPA compliance — disables IDFA. |
offline | Bool? | false | Queue events locally when offline. |
maxQueuedEventCount | Int | -1 | Max queued events (-1 = unlimited). |
migrateLegacyData | Bool | true | Migrate data from older SDK versions. |