This guide walks you through configuring the AppDNA SDK, identifying users, and tracking your first event in a React Native application.
Initialize AppDNA as early as possible in your app lifecycle. Place the call in your root component or app entry point:
import { AppDNA } from '@appdna/react-native-sdk';
await AppDNA.configure("adn_live_xxx", "production", {
logLevel: "debug",
});
Call AppDNA.configure(...) exactly once before using any other SDK methods. Calling it multiple times will result in undefined behavior.
Configuration Options
The AppDNAOptions interface lets you customize SDK behavior:
| Parameter | Type | Default | Description |
|---|
flushInterval | number | 30 | Seconds between automatic event flushes |
batchSize | number | 20 | Number of events to batch before flushing |
configTTL | number | 300 | Seconds before cached config is considered stale |
logLevel | AppDNALogLevel | 'warning' | Verbosity of SDK console logs |
billingProvider | AppDNABillingProvider | undefined | Billing integration to use |
Environment
The AppDNAEnvironment type controls which backend environment the SDK targets:
| Value | Description |
|---|
'production' | Production API and configuration |
'staging' | Staging API for testing |
Log Level
The AppDNALogLevel type 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 AppDNABillingProvider type specifies which billing system to use:
| Value | Description |
|---|
'storeKit2' | Native StoreKit 2 (iOS) / Google Play (Android) |
'revenueCat' | RevenueCat integration |
'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:
await AppDNA.onReady();
console.log("SDK ready -- remote config loaded");
3. Identify Users
Once a user signs in, call identify to associate events with their user ID:
await AppDNA.identify("user-123", {
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:
await AppDNA.track("workout_completed", {
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:
await AppDNA.setConsent(true);
When consent 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
Adjust the log level without reconfiguring the SDK:
AppDNA.setLogLevel("debug");
setLogLevel is the only synchronous method on the AppDNA class. All other methods return Promises and should be awaited.
8. Remote Config and Feature Flags
Retrieve server-side configuration values:
const welcomeMessage = await AppDNA.getRemoteConfig("welcome_message");
Check whether a feature flag is enabled:
const darkModeEnabled = await AppDNA.isFeatureEnabled("dark_mode");
9. Experiments
Get the variant assigned to a user for an experiment:
const variant = await AppDNA.getExperimentVariant("paywall_test");
Check if the user is in a specific variant:
const isInVariantB = await AppDNA.isInVariant("paywall_test", "b");
10. Web Entitlements
Retrieve the current web entitlement for the user:
const entitlement = await AppDNA.getWebEntitlement();
Listen for web entitlement changes:
const unsubscribe = AppDNA.onWebEntitlementChanged((entitlement) => {
console.log("Web entitlement changed:", entitlement);
});
// Later, when you no longer need the listener:
unsubscribe();
11. Deferred Deep Links
Check for a deferred deep link that led to the app install:
const link = await AppDNA.checkDeferredDeepLink();
if (link) {
console.log("Deep link:", link);
}
12. 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.
13. Shutdown
When your app is terminating or you need to fully tear down the SDK: