Skip to content

SDK Initialization

Every ABetterChoice SDK takes the same shape at startup: identify the project, prove the caller, optionally tune the polling and exposure behavior, then keep the instance alive for the lifetime of the process or app session.

Required fields

FieldWhere it comes fromPurpose
project_idPath segment after /app/ in the console URL.Scopes which experiments and configurations are loaded.
secret_keySettings → SDK&Key. Default key works for Quickstart.Authenticates every request the SDK makes.
unit_idYour application's stable user, session, or device ID.Decides which group the unit lands in. Same unit ID always lands in the same group.

project_id and secret_key are passed to the constructor or Init call; unit_id is set on the user context (server SDKs) or the SDK instance (client SDKs).

Server SDK lifecycle

Server SDKs run inside a long-lived process. The Go server SDK is generally available today; the C++ server SDK is Coming soon. Both follow the same recommended layout:

  1. Init once at startup — call abc.Init(...) (Go) before the service serves traffic. The C++ entry point will be AbcService::GetInstance()->Init(...) once the SDK ships.
  2. The SDK polls every 3 seconds — fresh configurations are pulled in the background; calls to getExperiment / getFeatureFlag always read the local cache, so the hot path stays sub-millisecond.
  3. Build a user context per requestabc.NewUserContext(unit_id) (Go) wraps the unit ID for that request; the planned C++ shape uses WithSetUnitID(unit_id).
  4. Release on shutdowndefer abc.Release() (Go) is enough; the SDK flushes pending exposure logs.

Total propagation delay from a console change to a server SDK is ~15 seconds (database to global config servers, then SDK poll).

Client SDK lifecycle

Client SDKs run inside an app or page session. Today all three client SDKs (Android, iOS, JavaScript) are tagged Coming soon under Settings → SDK&Key — the lifecycle below describes how those SDKs will behave once published. Until then, mobile and web clients should call the HTTP API through a thin proxy on your server.

  1. Init once at app launch — provide projectId, unitId, secretKey. The SDK fetches the precomputed assignment for that unit from the evaluation server.
  2. Reads are local — subsequent getExperiment / getFeatureFlag calls return cached values instantly.
  3. Polling — the SDK refreshes the cache every 10 minutes when enableAutomaticPoll (or the per-platform equivalent) is on.
  4. Switch unit ID — call switchUnitId when the logged-in user changes. The SDK fetches a new assignment set for the new unit.
  5. Force refreshrefreshExperiment re-fetches immediately. Use sparingly, it adds cost.

Total propagation delay from a console change to a client SDK is up to ~10 minutes by default.

Common options

These options are exposed by every SDK; the parameter names differ per language but the meaning is identical.

OptionEffect
Disable automatic exposuregetExperiment no longer logs an exposure on call. You log later via LogExperimentExposure. See Exposure logging.
Disable pollingThe SDK reads only the values it cached on init. Useful for offline tests.
Custom backend addressPoint the SDK at a private deployment (Go: env.RegisterAddr, C++: WithSetEnv).
Request timeoutCap how long a single network call waits. Default is 15 seconds.
User attributes / profilesProvide attribute values for audience targeting. See User object.

Example: Go

go
err := abc.Init(
    context.Background(),
    []string{"6666"},                          // project IDs
    abc.WithSecretKey("YOUR_API_TOKEN"),       // from Settings → SDK&Key
    abc.WithDisableReport(true),               // disable automatic exposure logging
)
defer abc.Release()

Example: HTTP API

When no SDK is available, the HTTP API plays the role of "init" and "fetch" together — every request stands alone:

bash
ak="your_secret_key_name"
token="your_api_token"
et=$(date +%s)
sig=$(echo -n "${token}${ak}${et}" | md5)

curl -X POST 'https://openapi.abetterchoice.ai/abc/get_experiments' \
  -H "Content-Type: application/json" \
  -H "X-Ak: $ak" -H "X-Et: $et" -H "X-Es: $sig" \
  -d '{"project_id":"6666","unit_id":"user_id_1"}'

The shape preview snippets on the JavaScript, Android, iOS, and C++ pages mirror this contract; those SDKs are tagged Coming soon under Settings → SDK&Key.