This guide walks you through configuring the AppDNA SDK, identifying users, and tracking your first event.
Initialize AppDNA as early as possible in your app lifecycle. For UIKit apps, place this in application(_:didFinishLaunchingWithOptions:). For SwiftUI apps, use the App initializer.
UIKit
import AppDNASDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
AppDNA.configure(
apiKey: "adn_live_xxx",
environment: .production,
options: AppDNAOptions(logLevel: .debug)
)
return true
}
}
SwiftUI
import SwiftUI
import AppDNASDK
@main
struct MyApp: App {
init() {
AppDNA.configure(
apiKey: "adn_live_xxx",
environment: .production,
options: AppDNAOptions(logLevel: .debug)
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Call AppDNA.configure(...) exactly once before using any other SDK methods. Calling it multiple times will result in undefined behavior.
Configuration Options
The AppDNAOptions struct lets you customize SDK behavior:
| Parameter | Type | Default | Description |
|---|
flushInterval | TimeInterval | 30 | Seconds between automatic event flushes |
batchSize | Int | 20 | Number of events to batch before flushing |
configTTL | TimeInterval | 300 | Seconds before cached config is considered stale |
logLevel | LogLevel | .warning | Verbosity of SDK console logs |
billingProvider | BillingProvider | .storeKit2 | Billing integration to use |
Environment
The Environment enum controls which backend environment the SDK targets:
| Value | Description |
|---|
.production | Production API and configuration |
.sandbox | Sandbox API for testing |
Log Level
The LogLevel enum controls console log verbosity:
| Value | Description |
|---|
.none | No logging |
.error | Errors only |
.warning | Errors and warnings |
.info | Errors, warnings, and info |
.debug | All messages including debug |
Use .debug during development to see all SDK activity. Switch to .warning or .none for production builds.
Billing Provider
The BillingProvider enum specifies which billing system to use:
| Value | Description |
|---|
.storeKit2 | Native StoreKit 2 (default) |
.revenueCat | RevenueCat integration |
.adapty(apiKey:) | Adapty integration with your API key |
.none | Disable billing module |
2. Wait for Ready State
The SDK fetches remote configuration asynchronously. Use onReady to know when the SDK is fully initialized:
AppDNA.onReady {
print("SDK ready — remote config loaded")
}
3. Identify Users
Once a user signs in, call identify to associate events with their user ID:
AppDNA.identify(
userId: "user-123",
traits: [
"plan": "premium",
"signup_date": "2025-01-15"
]
)
Traits are merged with any previously set traits. You do not need to pass all traits on every call — only the ones that have changed.
4. Track Events
Track user actions with track:
AppDNA.track(
event: "workout_completed",
properties: [
"duration": 45,
"type": "strength"
]
)
Events are batched and flushed automatically based on your flushInterval and batchSize settings.
5. Flush Events Manually
Force an immediate flush of all queued events:
This is useful before the app enters the background or when you need to ensure events are sent immediately.
6. Set User Consent
Control whether the SDK collects and sends analytics data:
AppDNA.setConsent(analytics: true)
When analytics is set to false, events are silently dropped and not queued. No data is sent to AppDNA servers until consent is granted.
7. Remote Config and Feature Flags
Retrieve server-side configuration values:
let welcomeMessage = AppDNA.getRemoteConfig(key: "welcome_message")
Check whether a feature flag is enabled:
let darkModeEnabled = AppDNA.isFeatureEnabled(flag: "dark_mode")
8. Experiments
Get the variant assigned to a user for an experiment:
let variant = AppDNA.getExperimentVariant(experimentId: "paywall_test")
Check if the user is in a specific variant:
let isInVariantB = AppDNA.isInVariant(
experimentId: "paywall_test",
variantId: "b"
)
9. Reset on Logout
When a user signs out, call reset to clear the user identity and flush any remaining events:
This clears the identified user, generates a new anonymous ID, and flushes queued events.