AdvaitaADVAITA DOCS
GitHubGet started
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):

Package.swift
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:

Podfile
pod 'AcaiSwift', :git => 'https://github.com/your-org/Acai-Swift.git'

Initialise

Swift
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

Swift
acai.track(eventType: "Button Tapped")
acai.track(eventType: "Purchase Completed", eventProperties: [
"product_id": "prod_123",
"price": 49.99,
"currency": "USD",
])
acai.flush()

Identify users

Swift
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")
// Log out
acai.identity.userId = nil
acai.reset()

Plugins

Swift
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

OptionTypeDefaultDescription
apiKeyStringrequiredYour project API key.
serverUrlString?nilCustom collector endpoint.
autocaptureAutocaptureOptions.sessions.sessions · .screenViews · .elementInteractions · .networkTracking
logLevelLogLevelEnum.warn.off · .error · .warn · .log · .debug
flushQueueSizeInt30Events per batch before flush.
flushIntervalMillisInt30000Flush interval in ms.
optOutBoolfalseDisable all tracking.
flushEventsOnCloseBooltrueFlush on app backgrounded.
enableCoppaControlBoolfalseCOPPA compliance — disables IDFA.
offlineBool?falseQueue events locally when offline.
maxQueuedEventCountInt-1Max queued events (-1 = unlimited).
migrateLegacyDataBooltrueMigrate data from older SDK versions.