Initialize the SDK

Prev Next

What initialization means

Initialization is the step where you create a valid SDK configuration and pass it to Webtrekk.getInstance().init(...). From this point on, the SDK is available to the rest of your app.

Where initialization should happen

Initialize the SDK in your custom Application class. This gives the SDK an application-level context and ensures that the setup happens once during app startup.

This follows common Android startup practice for app-wide libraries: initialize them once from the application context, not lazily from individual screens.

Minimum required configuration

You must provide:

  • at least one Track ID

  • a valid Track Domain

Example

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

        val configuration = WebtrekkConfiguration.Builder(
            listOf("1111111111111111111111111"),
            "https://your-trackdomain.com"
        ).build()

        Webtrekk.getInstance().init(this, configuration)
    }
}
public class SampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        WebtrekkConfiguration configuration = new WebtrekkConfiguration.Builder(
            Arrays.asList("1111111111111111111111111"),
            "https://your-trackdomain.com"
        ).build();

        Webtrekk.getInstance().init(this, configuration);
    }
}

Register the Application class

Make sure your custom Application class is declared in the Android manifest. If your class is in the same package as the manifest, the short form below is fine. Otherwise use the fully qualified class name.

<application
    android:name=".SampleApplication">
</application>

What to verify after initialization

  • the app starts without an IllegalStateException

  • your Application class is registered in the manifest

  • the Track ID and Track Domain values are correct

  • the initialization code runs exactly once during app startup

What not to overload into this step

Keep initialization minimal. Logging, auto-tracking changes, batch support, user matching, crash tracking, and other optional behavior should be added afterwards in global configuration.

Next step

Once the SDK starts successfully, continue with Configure Global Tracking.

If the SDK is not initialized correctly, later SDK calls can fail because the required context or configuration is missing.