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. Place the configuration call in your Application.onCreate() method:
import ai.appdna.sdk.AppDNA
import ai.appdna.sdk.AppDNAOptions
import ai.appdna.sdk.Environment
import ai.appdna.sdk.LogLevel
import android.app.Application

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()

        AppDNA.configure(
            context = this,
            apiKey = "adn_live_xxx",
            environment = Environment.PRODUCTION,
            options = AppDNAOptions(logLevel = LogLevel.DEBUG)
        )
    }
}
Call AppDNA.configure(...) exactly once before using any other SDK methods. Calling it multiple times will result in undefined behavior. Always call it in Application.onCreate(), not in an Activity.

Configuration Options

The AppDNAOptions data class lets you customize SDK behavior:
ParameterTypeDefaultDescription
flushIntervalLong30L (seconds)Seconds between automatic event flushes
batchSizeInt20Number of events to batch before flushing
configTTLLong300L (seconds)Seconds before cached config is considered stale
logLevelLogLevelLogLevel.WARNINGVerbosity of SDK console logs

Environment

The Environment enum controls which backend the SDK targets:
ValueEndpointDescription
Environment.PRODUCTIONhttps://api.appdna.aiProduction API and configuration
Environment.SANDBOXhttps://sandbox-api.appdna.aiSandbox API for testing

Log Level

The LogLevel enum controls Logcat log verbosity:
ValueRaw ValueDescription
LogLevel.NONE0No logging
LogLevel.ERROR1Errors only
LogLevel.WARNING2Errors and warnings
LogLevel.INFO3Errors, warnings, and info
LogLevel.DEBUG4All messages including debug
Use LogLevel.DEBUG during development to see all SDK activity in Logcat. Switch to LogLevel.WARNING or LogLevel.NONE for production builds.

2. Wait for Ready State

The SDK fetches remote configuration asynchronously. Use onReady to know when the SDK is fully initialized:
AppDNA.onReady {
    Log.d("AppDNA", "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 = mapOf(
        "plan" to "premium",
        "signup_date" to "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 = mapOf(
        "duration" to 45,
        "type" to "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. Change Log Level at Runtime

You can adjust the log level after configuration without restarting the app:
AppDNA.setLogLevel("debug")
Accepted values: "none", "error", "warning", "info", "debug".

8. Remote Config and Feature Flags

Retrieve server-side configuration values:
val welcomeMessage = AppDNA.getRemoteConfig("welcome_message")
Check whether a feature flag is enabled:
val darkModeEnabled = AppDNA.isFeatureEnabled("dark_mode")

9. Experiments

Get the variant assigned to a user for an experiment:
val variant = AppDNA.getExperimentVariant("paywall_test")
Check if the user is in a specific variant:
val isInVariantB = AppDNA.isInVariant("paywall_test", "b")

10. 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.