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
| Field | Where it comes from | Purpose |
|---|---|---|
project_id | Path segment after /app/ in the console URL. | Scopes which experiments and configurations are loaded. |
secret_key | Settings → SDK&Key. Default key works for Quickstart. | Authenticates every request the SDK makes. |
unit_id | Your 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:
- Init once at startup — call
abc.Init(...)(Go) before the service serves traffic. The C++ entry point will beAbcService::GetInstance()->Init(...)once the SDK ships. - The SDK polls every 3 seconds — fresh configurations are pulled in the background; calls to
getExperiment/getFeatureFlagalways read the local cache, so the hot path stays sub-millisecond. - Build a user context per request —
abc.NewUserContext(unit_id)(Go) wraps the unit ID for that request; the planned C++ shape usesWithSetUnitID(unit_id). - Release on shutdown —
defer 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.
- Init once at app launch — provide
projectId,unitId,secretKey. The SDK fetches the precomputed assignment for that unit from the evaluation server. - Reads are local — subsequent
getExperiment/getFeatureFlagcalls return cached values instantly. - Polling — the SDK refreshes the cache every 10 minutes when
enableAutomaticPoll(or the per-platform equivalent) is on. - Switch unit ID — call
switchUnitIdwhen the logged-in user changes. The SDK fetches a new assignment set for the new unit. - Force refresh —
refreshExperimentre-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.
| Option | Effect |
|---|---|
| Disable automatic exposure | getExperiment no longer logs an exposure on call. You log later via LogExperimentExposure. See Exposure logging. |
| Disable polling | The SDK reads only the values it cached on init. Useful for offline tests. |
| Custom backend address | Point the SDK at a private deployment (Go: env.RegisterAddr, C++: WithSetEnv). |
| Request timeout | Cap how long a single network call waits. Default is 15 seconds. |
| User attributes / profiles | Provide attribute values for audience targeting. See User object. |
Example: 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:
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.