Getting Started

Initialize the SDK, configure it for your ZMP site, and control tracking opt-in.

This guide covers SDK initialization in your Application.onCreate(), the full set of ZTConfig parameters, and how to defer data collection until the user consents.

On this page

Initialize the SDK

Initialize ZetaCore during your app's launch. Pass an Application context and a ZTConfig instance to ZetaClient.initialize().

import net.zetaglobal.app.zetacore.ZTConfig
import net.zetaglobal.app.zetacore.ZetaClient
import net.zetaglobal.app.zetacore.network.ZTRegion
import net.zetaglobal.app.zetacore.common.ZTAppEnvironment

val config = ZTConfig(
    clientSecret = "your-client-secret",
    clientSiteId = "your-site-id",
    optIn = true,
    region = ZTRegion.US,
    appEnvironment = ZTAppEnvironment.PRODUCTION
)
ZetaClient.initialize(applicationContext, config)
import net.zetaglobal.app.zetacore.ZTConfig;
import net.zetaglobal.app.zetacore.ZetaClient;
import net.zetaglobal.app.zetacore.network.ZTRegion;
import net.zetaglobal.app.zetacore.common.ZTAppEnvironment;

ZTConfig config = new ZTConfig(
    "your-client-secret",          // clientSecret
    "your-site-id",                // clientSiteId
    true,                          // optIn
    ZTRegion.US,                   // region
    ZTAppEnvironment.PRODUCTION    // appEnvironment
);
ZetaClient.INSTANCE.initialize(getApplicationContext(), config);

ZTConfig parameters

ParameterRequiredDescription
clientSiteIdRequiredProvided by the ZMP console after successful app registration.
clientSecretOptionalProvided by the ZMP console. Can be supplied at init time or later via setClientSecret().
optInRequiredWhether the SDK tracks events and sends data to the backend.
regionRequiredYour ZMP region. Use a value from ZTRegion (US or EU). Region cannot be changed after your ZMP account is provisioned.
appEnvironmentOptionalZTAppEnvironment value. Defaults to PRODUCTION.

Note: Logging is configured separately via ZTLogger.setLevel() — it is not part of ZTConfig. See Advanced / Logging.

Where to initialize

Call ZetaClient.initialize() inside your Application.onCreate() or your launch Activity's onCreate(). Pass applicationContext — the SDK stores the application context internally and does not hold a reference to any Activity.

At initialization time, clientSiteId, optIn, and region are mandatory.

Setting the client secret

If you did not pass a clientSecret at init time, set it later:

ZetaClient.setClientSecret(applicationContext, "your-secret")
ZetaClient.INSTANCE.setClientSecret(getApplicationContext(), "your-secret");

Note: Do not commit clientSecret to source control. Load it from a secure source at app launch.

Reading the BSIN

BSIN (Zeta's unique user identifier) identifies the user in ZMP. Listen for BSIN changes and read the cached value:

ZetaClient.setOnBsinChange { bsin ->
    // Handle new BSIN
}
ZetaClient.INSTANCE.setOnBsinChange(bsin -> {
    // Handle new BSIN
});

Tracking opt-in and opt-out

When your app does not require the SDK to track events and user properties, use the opt-out feature. Send the opt-out state either as part of ZTConfig during initialization, or by calling a dedicated opt-out method.

If your app uses the SDK-exposed opt-in / opt-out methods, pass the same status into ZTConfig on the next launch. Otherwise the ZTConfig value may overwrite the status set at runtime.

Once opted out, the SDK:

  • Immediately stops all communication with the backend.
  • Clears any data cached in the local database.
  • Neither collects nor transmits any further data until the app opts back in.
  • Treats a subsequent opt-in as a fresh launch.

Opt out of tracking

You can disable tracking in two ways.

1. Pass optIn as false during initialization.

val config = ZTConfig(
    clientSiteId = "your-site-id",
    optIn = false,
    region = ZTRegion.US,
    appEnvironment = ZTAppEnvironment.PRODUCTION
)
ZetaClient.initialize(applicationContext, config)
ZTConfig config = new ZTConfig(null, "your-site-id", false, ZTRegion.US, ZTAppEnvironment.PRODUCTION);
ZetaClient.INSTANCE.initialize(getApplicationContext(), config);

2. Call the opt-out method at runtime.

ZetaClient.optOutFromTracking(applicationContext)
ZetaClient.INSTANCE.optOutFromTracking(getApplicationContext());

Opt in to tracking

To start tracking again, either pass optIn: true during ZetaClient.initialize() or call:

ZetaClient.optInForTracking(uid = "user-id") // uid is optional
ZetaClient.INSTANCE.optInForTracking("user-id"); // uid is optional, pass null for anonymous

The uid parameter is optional. If the app does not provide a user ID, the SDK treats the user as anonymous.

Next

See also