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

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

ParameterRequiredDescription
clientSiteIdRequiredProvided by the ZMP console after successful app registration.
clientSecretOptionalProvided by the ZMP console. Required for the SDK to communicate with the server. Can be supplied at init time or later via setClientSecret(_:).
regionRequiredYour ZMP region. Use a value from ZTRegion (.US or .EU). Region cannot be changed after your ZMP account is provisioned.
optInRequiredWhether the SDK tracks events and sends data to the backend.
appGroupIdOptionalUsed to track notification delivery status. See Push Notifications / NSE.
appEnvironmentOptionalZTAppEnvironment value. Defaults to .PRODUCTION. Selects the APNs environment the SDK expects.

Note: Logging is configured separately via ZTLogger.setLogLevel(_:) — it is not part of ZTConfig. 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

See also