Swift SDK Reference
The Databuddy Swift SDK tracks native Apple app events with the public Databuddy client ID. It is built for explicit product instrumentation: app launches, onboarding steps, searches, purchases, feature usage, and manual screen views.
Do not ship DATABUDDY_API_KEY in an Apple app. Use your public Databuddy client ID.
Installation
Add the package in Xcode with Swift Package Manager:
.package(url: "https://github.com/databuddy-analytics/databuddy.git", branch: "main")Then add the Databuddy product to your app target.
Quick Start
Configure once during app startup:
import Databuddy
Databuddy.configure(clientId: "YOUR_CLIENT_ID")Track custom events:
Databuddy.track("search_completed", properties: [
"category": "files",
"duration_ms": 124,
"query_length_bucket": "4-7",
"result_count": 12,
])Flush before a short-lived app extension exits:
await Databuddy.trackAsync("share_extension_completed", properties: [
"target": "notes",
])
let result = await Databuddy.flush()
if !result.success {
print("Databuddy flush failed: \(result.error ?? "unknown error")")
}Configuration
Databuddy.configure(
clientId: "YOUR_CLIENT_ID",
apiURL: URL(string: "https://basket.databuddy.cc")!,
source: "ios",
namespace: "app",
enabled: true,
flushAt: 10,
flushInterval: 2.0,
maxQueueSize: 1_000
)Manual Screen Views
Native apps do not have browser page views, so the SDK does not automatically infer screens. Track important views where they become visible:
Databuddy.trackScreen("settings", properties: [
"tab": "billing",
])In SwiftUI:
struct SettingsView: View {
var body: some View {
Form {
// ...
}
.task {
Databuddy.trackScreen("settings")
}
}
}Event Properties
Properties use JSON-safe values:
Databuddy.track("checkout_completed", properties: [
"plan": "pro",
"revenue": 29.0,
"seats": 3,
"trial": false,
"metadata": ["source": "settings"],
])Avoid PII, secrets, raw tokens, raw search text, full exception stacks, and large payloads. Prefer stable, low-cardinality fields like plan, source, category, result_count, and duration_ms.
How is this guide?