Configuration
Use the methods in this guide to configure the behavior of the Adtrace Android SDK.
The SDK supports two kinds of configuration:
| Type | When you set it | Can change after init? |
|---|---|---|
| Read-only | On AdTraceConfig before AdTrace.onCreate() | No |
| Dynamic | On AdTrace at any time after the SDK starts | Yes |
Create an AdTraceConfig instance
Read-only options live on an AdTraceConfig object. Create that object, set the options you need, then pass it to AdTrace.onCreate().
Method signature
public AdTraceConfig(
Context context,
String appToken,
String environment,
boolean allowSuppressLogLevel
)
You can also use the three-argument constructor when you do not need suppress logging:
public AdTraceConfig(Context context, String appToken, String environment)
Required parameters
| Parameter | Type | Description |
|---|---|---|
context | Context | The Android context where your app is running. Pass your Application or Activity context (for example this in Application.onCreate). |
appToken | String | Your Adtrace app token from the Adtrace panel. |
environment | String | SDK environment. Use AdTraceConfig.ENVIRONMENT_SANDBOX for testing, or AdTraceConfig.ENVIRONMENT_PRODUCTION for release. |
allowSuppressLogLevel | boolean | Optional fourth argument. Set true if you want to allow LogLevel.SUPPRESS. Set false (or omit) to keep normal logging. |
Example
- Java
- Kotlin
- Javascript
import android.app.Application;
import io.adtrace.sdk.AdTrace;
import io.adtrace.sdk.AdTraceConfig;
public class GlobalApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String appToken = "{YourAppToken}";
String environment = AdTraceConfig.ENVIRONMENT_SANDBOX;
AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
// Configure read-only options on `config` here, then:
AdTrace.onCreate(config);
}
}
import android.app.Application
import io.adtrace.sdk.AdTrace
import io.adtrace.sdk.AdTraceConfig
class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
val appToken = "{YourAppToken}"
val environment = AdTraceConfig.ENVIRONMENT_SANDBOX
val config = AdTraceConfig(this, appToken, environment)
// Configure read-only options on `config` here, then:
AdTrace.onCreate(config)
}
}
let appToken = "{YourAppToken}";
let environment = AdTraceConfig.EnvironmentSandbox;
let config = new AdTraceConfig(appToken, environment);
// Configure read-only options on `config` here, then:
AdTrace.onCreate(config);
Replace {YourAppToken} with your app token from the Adtrace panel.
Read-only configuration
Read-only options are set on your AdTraceConfig instance before SDK initialization. They cannot be changed while the SDK is running.
You must configure any options you need before calling AdTrace.onCreate().
Dynamic configuration
Dynamic configuration options can change after the SDK has started. Call these methods on AdTrace at any time during the SDK lifecycle, for example when a user opts out of tracking or your app needs to pause network traffic.
Unlike read-only options on AdTraceConfig, you do not need to restart the SDK to apply a dynamic change.
Next steps
After you configure AdTraceConfig, initialize and test your integration in Getting started with the Android SDK, then track actions with Event tracking.