Quick Start — iOS SDK
Prerequisites
- Installation complete
- Your CDP API key
Step 1 — Initialize
import OpenCDP
@main
struct MyApp: App {
init() {
let config = OpenCDPConfig(
cdpApiKey: "YOUR_CDP_API_KEY",
debug: true,
autoTrackScreens: true,
trackApplicationLifecycleEvents: true
)
OpenCDP.shared.initialize(config: config)
}
var body: some Scene {
WindowGroup { ContentView() }
}
}
Step 2 — Identify a user
OpenCDP.shared.identify(
identifier: "user_123",
properties: [
"email": "[email protected]",
"plan": "pro",
]
)
identifier must not be an email address.
Step 3 — Track an event
OpenCDP.shared.track(
eventName: "purchase",
properties: ["amount": 99.9]
)
Step 4 — Track a screen view
With autoTrackScreens: true, view controller appearances are tracked automatically (preferring title). For SwiftUI or stable page-rule ids, call explicitly:
OpenCDP.shared.trackScreenView(
title: "/product-details",
properties: ["sku": "ABC-001"]
)
See Screen tracking.
Step 5 — Register device token (push)
In AppDelegate:
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
OpenCDP.shared.registerDeviceToken(token)
}
Step 6 — Test push from console
Use the same person ID in Test push notification → Test by User ID.
See Identity and devices.
Gateway request timeout
cdpRequestTimeout is in seconds. The built-in default is 30. The SDK clamps any value below 5 up to 5 seconds, and any value above 120 down to 120 seconds.
The timeout is how long the SDK waits for one gateway host to answer a single request. On a timeout, a network error, or a non-success status, the SDK tries the next host immediately:
https://api.opencdp.io/gateway/data-gatewayhttps://api.open-cdp.com/gateway/data-gatewayhttps://api.open-cdp.xyz/gateway/data-gateway
Leave cdpRequestTimeout unset to keep the 30 second default. To wait 20 seconds on each host:
let config = OpenCDPConfig(
cdpApiKey: "YOUR_CDP_API_KEY",
cdpRequestTimeout: 20
)
Verify it worked
With debug: true, Xcode console shows successful identify/track POSTs.