Skip to main content

Configuration

Use the methods in this guide to configure the behavior of the Adtrace Android SDK.

The SDK supports two kinds of configuration:

TypeWhen you set itCan change after init?
Read-onlyOn AdTraceConfig before AdTrace.onCreate()No
DynamicOn AdTrace at any time after the SDK startsYes

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

ParameterTypeDescription
contextContextThe Android context where your app is running. Pass your Application or Activity context (for example this in Application.onCreate).
appTokenStringYour Adtrace app token from the Adtrace panel.
environmentStringSDK environment. Use AdTraceConfig.ENVIRONMENT_SANDBOX for testing, or AdTraceConfig.ENVIRONMENT_PRODUCTION for release.
allowSuppressLogLevelbooleanOptional fourth argument. Set true if you want to allow LogLevel.SUPPRESS. Set false (or omit) to keep normal logging.

Example

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);
}
}

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.