Client SDKs
Configuration
How to initialize and configure the AudienceLab Android SDK
Initialization
Initialize the SDK as early as possible, typically in Application.onCreate() or your main bootstrap activity:
import app.geeklab.audiencelab.sdk.AudienceLabSDK
import app.geeklab.audiencelab.sdk.AudienceLabOptions
AudienceLabSDK.initialize(
context = applicationContext,
apiKey = BuildConfig.AUDIENCELAB_API_KEY,
options = AudienceLabOptions(
isSdkEnabled = true,
isMetricsEnabled = true,
isDebugEnabled = BuildConfig.DEBUG,
isDevelopmentMode = BuildConfig.DEBUG,
appVersion = "2.5.1",
)
)Prop
Type
On initialization, the SDK:
- Collects device info (OS version, device model, screen size, timezone)
- Resolves identity fields (Android ID and optional GAID/App Set ID)
- Sends
POST /fetch-token - Stores the returned creative token in
SharedPreferences - Starts a new session and sends a retention event if needed
BuildConfig Example
android {
defaultConfig {
buildConfigField("String", "AUDIENCELAB_API_KEY", "\"replace-with-your-api-key\"")
}
}Use isDevelopmentMode to control whether events are sent as development traffic or release traffic:
AudienceLabOptions(
isDevelopmentMode = BuildConfig.DEBUG,
isDebugEnabled = BuildConfig.DEBUG
)Identity Providers
The SDK supports provider injection for GAID and App Set ID when your app already has those values available synchronously:
import app.geeklab.audiencelab.sdk.AdvertisingInfo
AudienceLabSDK.setAdvertisingIdProvider { context ->
AdvertisingInfo(
advertisingId = cachedAdvertisingId,
limitAdTracking = cachedLimitAdTracking
)
}
AudienceLabSDK.setAppSetIdProvider { context ->
cachedAppSetId
}You can also set identity values manually:
AudienceLabSDK.setAdvertisingId("GAID-UUID-STRING")
AudienceLabSDK.setAppSetId("APP-SET-ID-UUID")
AudienceLabSDK.setLimitAdTracking(false)
AudienceLabSDK.clearAdvertisingId()
AudienceLabSDK.clearAppSetId()If the host app already includes the relevant Google Play Services support, the SDK also attempts automatic GAID/App Set ID lookup without adding a hard dependency path for consumers.
SDK Toggles
AudienceLabSDK.setSDKEnabled(true)
AudienceLabSDK.toggleMetricsCollection(true)
AudienceLabSDK.setDebugEnabled(false)| Method | Description |
|---|---|
setSdkEnabled(Boolean) / setSDKEnabled(Boolean) | Master toggle. When disabled, no events are sent. |
toggleMetricsCollection(Boolean) | Enable/disable data collection. |
setDebugEnabled(Boolean) | Enables/disables local SDK debug behavior. |
setDebugEnabled(...) does not control the backend dev flag. Use AudienceLabOptions(isDevelopmentMode = ...) to choose development vs release traffic.