Skip to main content
This guide walks you through configuring the AppDNA SDK, identifying users, and tracking your first event.

1. Configure the SDK

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:
ParameterTypeDefaultDescription
flushIntervalTimeInterval30Seconds between automatic event flushes
batchSizeInt20Number of events to batch before flushing
configTTLTimeInterval300Seconds before cached config is considered stale
logLevelLogLevel.warningVerbosity of SDK console logs
billingProviderBillingProvider.storeKit2Billing integration to use

Environment

The Environment enum controls which backend environment the SDK targets:
ValueDescription
.productionProduction API and configuration
.sandboxSandbox API for testing

Log Level

The LogLevel enum controls console log verbosity:
ValueDescription
.noneNo logging
.errorErrors only
.warningErrors and warnings
.infoErrors, warnings, and info
.debugAll 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:
ValueDescription
.storeKit2Native StoreKit 2 (default)
.revenueCatRevenueCat integration
.adapty(apiKey:)Adapty integration with your API key
.noneDisable 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:
AppDNA.flush()
This is useful before the app enters the background or when you need to ensure events are sent immediately. 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:
AppDNA.reset()
This clears the identified user, generates a new anonymous ID, and flushes queued events.
You now have the SDK configured, user identification, event tracking, remote config, and experiments working. Continue to the module-specific guides for Push Notifications, Billing, Onboarding, and Paywalls.