Getting Started
Initialize the SDK, configure it for your ZMP site, and control tracking opt-in.
This guide covers the first code you write after installing ZetaKit: creating a configuration, initializing the SDK at app launch, reading the BSIN, and managing opt-in/opt-out state.
On this page
- Initialize the SDK
ZTConfigparameters- Where to initialize
- Reading the BSIN
- Tracking opt-in and opt-out
Initialize the SDK
Initialize ZetaKit during your app's launch. Pass a ZTConfig instance to ZetaClient.shared.initialize(config:).
import ZetaCore
let zetaConfig = ZTConfig(
clientSiteId: Environment.clientSiteId,
clientSecret: Environment.clientSecret,
region: .US,
appGroupId: "group.xyz.app",
optIn: true,
appEnvironment: .PRODUCTION
)
ZetaClient.shared.initialize(config: zetaConfig)
@import ZetaCore;
ZTConfig *config = [[ZTConfig alloc]
initWithClientSiteId:Environment.clientSiteId
clientSecret:Environment.clientSecret
region:ZTRegionUS
appGroupId:@"group.xyz.app"
optIn:YES
appEnvironment:ZTAppEnvironmentPRODUCTION];
[[ZetaClient shared] initializeWithConfig:config completionBlock:^{}];
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. Required for the SDK to communicate with the server. Can be supplied at init time or later via setClientSecret(_:). |
region | Required | Your ZMP region. Use a value from ZTRegion (.US or .EU). Region cannot be changed after your ZMP account is provisioned. |
optIn | Required | Whether the SDK tracks events and sends data to the backend. |
appGroupId | Optional | Used to track notification delivery status. See Push Notifications / NSE. |
appEnvironment | Optional | ZTAppEnvironment value. Defaults to .PRODUCTION. Selects the APNs environment the SDK expects. |
Note: Logging is configured separately via
ZTLogger.setLogLevel(_:)— it is not part ofZTConfig. See Advanced / Logging.
Where to initialize
Call ZetaClient.shared.initialize(config:) inside application(_:didFinishLaunchingWithOptions:).
At initialization time, clientSiteId, optIn, and region are mandatory. If you did not pass a clientSecret at init time, set it later:
ZetaClient.shared.setClientSecret(Environment.clientSecret)
[[ZetaClient shared] setClientSecret:Environment.clientSecret];
Initialization is safe to call on the main thread — heavy work runs on a background queue.
Reading the BSIN
BSIN (Zeta's unique user identifier) identifies the user in ZMP.
let bsin = ZetaClient.shared.getCachedBSIN()
// Listen to BSIN lifecycle changes
ZetaClient.shared.user?.setIdentityDelegate(delegate: self)
NSString *bsin = [[ZetaClient shared] getCachedBSIN];
[[ZetaClient shared].user setIdentityDelegateWithDelegate:self];
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 locally cached data.
- 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.
let zetaConfig = ZTConfig(
clientSiteId: Environment.clientSiteId,
clientSecret: Environment.clientSecret,
region: .US,
appGroupId: "group.xyz.app",
optIn: false,
appEnvironment: .PRODUCTION
)
ZetaClient.shared.initialize(config: zetaConfig)
ZTConfig *config = [[ZTConfig alloc]
initWithClientSiteId:Environment.clientSiteId
clientSecret:Environment.clientSecret
region:ZTRegionUS
appGroupId:@"group.xyz.app"
optIn:NO
appEnvironment:ZTAppEnvironmentPRODUCTION];
[[ZetaClient shared] initializeWithConfig:config completionBlock:^{}];
2. Call the opt-out method at runtime.
ZetaClient.shared.optOutFromTracking()
[[ZetaClient shared] optOutFromTracking];
Note: The opt-out status is maintained locally on the device. It is not communicated to the backend. The backend may continue to attempt push notifications; the SDK will not process them while in the opted-out state.
Opt in to tracking
To start tracking again, either pass optIn: true during ZetaClient.shared.initialize(config:) or call:
ZetaClient.shared.optInForTracking(uid: uid)
[[ZetaClient shared] optInForTrackingWithUid:uid];
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-manifest details.
See also
- Platform support -- feature availability by platform and SDK version.
