Getting started

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

Once you have installed the package and configured your native projects, the next step is to initialize the SDK. This guide will walk you through JavaScript initialization, configuration options, native initialization, and tracking opt-in/opt-out.

On this page


Initialize the SDK in JavaScript

Initialize the SDK once as early as possible in your application lifecycle, typically inside a useEffect hook in your root component (e.g., App.tsx).

import React, { useEffect } from 'react';
import ZetaClient, {
  ZTRegion,
  ZTAppEnvironment,
  ZTLogger,
  ZTLogLevel,
} from 'zetakit_reactnative';

const App = () => {
  useEffect(() => {
    // Optional: Enable logging before initialization to capture startup diagnostics
    ZTLogger.setLogLevel(ZTLogLevel.DEBUG);

    const config = {
      clientSiteId: 'your-site-id',
      clientSecret: 'your-secret',
      region: ZTRegion.US,
      appGroupId: 'group.com.example.app', // iOS only
      optIn: true,
      appEnvironment: ZTAppEnvironment.PRODUCTION,
    };

    ZetaClient.initialize(config, () => {
      console.log('Zeta SDK is ready');
    });
  }, []);

  return <YourAppRoot />;
};

export default App;

During initialization, clientSiteId, optIn, and region are mandatory.


Understand ZTConfig options

The configuration object passed to ZetaClient.initialize() supports the following properties:

ParameterRequiredDescription
clientSiteIdRequiredThe site identifier provided by the ZMP console after successful app registration.
clientSecretOptionalThe authentication token provided by the ZMP console. Required for the SDK to communicate with ZMP. Can be supplied here or set later via setClientSecret().
regionRequiredYour ZMP region. Use ZTRegion.US or ZTRegion.EU. Must match your ZMP account provisioning and cannot be changed afterward.
optInRequiredWhether the SDK is permitted to track events and send data to the backend.
appGroupIdOptional (iOS only)Used to track push notification delivery status on iOS. See the Push Notifications guide.
appEnvironmentOptionalZTAppEnvironment.PRODUCTION (default) or ZTAppEnvironment.SANDBOX. Selects the APNs environment the SDK expects on iOS.

Handle client secret updates

If you do not have the client secret available at initialization time (for example, if you fetch it from a remote configuration service), you can supply it later:

ZetaClient.setClientSecret('your-secret');

Security Note: Do not commit your clientSecret directly to source control. Always load it from a secure source at app launch.


Initialize natively (Optional)

In some advanced scenarios, you may want the SDK to be ready before the React Native JavaScript bridge loads. You can choose to initialize the SDK from the native iOS or Android layer instead of JavaScript.

If you choose native initialization, do not call ZetaClient.initialize() from JavaScript. Initialize from one layer only.

For full native initialization guides and code examples, refer to the native documentation:


Control tracking opt-in and opt-out

The SDK supports user privacy preferences with explicit opt-in and opt-out controls.

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.

Opting out of tracking

You can opt out of tracking in two ways:

  • At Initialization: Pass optIn: false in your ZTConfig object.

  • At Runtime: Call the dedicated opt-out method:

    ZetaClient.optOutFromTracking();

Opting in to tracking

To opt back in to tracking at runtime, call:

ZetaClient.optInForTracking('user-id');

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

Important: If your app uses runtime opt-in/opt-out methods, ensure you pass the same status into ZTConfig on the next launch. Otherwise, the static ZTConfig value may overwrite the runtime preference.


Next step

Now that the SDK is initialized, continue to the next step of your journey:

See also