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
ZTConfigparameters- Where to initialize
- Setting the client secret
- Reading the BSIN
- Tracking opt-in and opt-out
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
ZTConfig parameters| Parameter | Required | Description |
|---|---|---|
clientSiteId | Required | Provided by the ZMP console after successful app registration. |
clientSecret | Optional | Provided by the ZMP console. Can be supplied at init time or later via setClientSecret(). |
optIn | Required | Whether the SDK tracks events and sends data to the backend. |
region | Required | Your ZMP region. Use a value from ZTRegion (US or EU). Region cannot be changed after your ZMP account is provisioned. |
appEnvironment | Optional | ZTAppEnvironment value. Defaults to PRODUCTION. |
Note: Logging is configured separately via
ZTLogger.setLevel()— it is not part ofZTConfig. 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
clientSecretto 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
- Identify the user and track events: Contact Management.
- Receive push notifications: Push Notifications.
- See also: Data & Privacy for opt-in/out, data-rights, and privacy details.
See also
- Platform support -- feature availability by platform and SDK version.
