Amba
SDKsFeatures

Remote config

Read runtime config on the first frame from shipped defaults and an on-device cache, and fetch the project's key/value bundle to refresh it.

Remote config holds values the app reads at runtime and needs to change without a release: copy, pricing, thresholds, default selections. Config bundles hold strings, numbers, booleans and structured JSON; feature flags hold on/off gates. One bundle per project. A signed-in user's bundle has each key's segment and percentage conditions applied; before sign-in it holds each key's default value.

Two ways to read it:

  • config.getCached(key, default) returns a value at once, with no request, so the first screen can use it. It reads the last fetch, else the value the device cached on an earlier launch, else the defaults your app ships with (configDefaults), else the default you pass.
  • config.fetch() requests the bundle. Its result also refreshes what getCached returns.

Quick start

Pass the values your app ships with at configure, then read config anywhere without waiting:

import { Amba } from '@layers/amba-web';
 
await Amba.configure({
  projectId: 'proj_...',
  clientKey: 'amba_ck_...',
  configDefaults: { welcome_copy: 'Welcome!', max_items: 20 },
});
 
const copy = Amba.config.getCached('welcome_copy', 'Welcome!');
const maxItems = Amba.config.getCached('max_items', 20);

Startup values: defaults and the device cache

getCached answers from what the SDK holds, in this order:

  1. The last fetch made since launch (config.fetch(), or the background refresh below).
  2. The device cache: the last bundle a fetch returned, saved per project and per signed-in user, read back on the next launch.
  3. configDefaults: the values your app ships with, passed at configure.
  4. The default you pass to getCached.

A JSON null counts as no value. A value of another type than the default you pass (a string where the default is a number) returns your default, so a typed read never hands back the wrong type.

Background refresh. The first getCached call for each user starts one config.fetch() in the background; its result replaces the cached values, and later reads return it. That happens once after configure, and once more after a sign-in or sign-out changes who is reading, so a signed-in user's own values arrive on their next read. Configure itself sends no request, and an app that never reads cached config makes no extra one. A failed refresh (offline) leaves the cached values in place.

Kill switch. The server leaves a config switched off with its kill switch (is_active: false) out of the bundle. The next successful fetch removes that key from the cache, so getCached falls back to configDefaults and then your default. Ship the safe value as the default for any key you may switch off.

Per project and user. Each project (each client key and environment) has its own cache; one project never reads another's. Inside it, each signed-in user has their own values, and the device keeps the five most recently used users. A signed-in user reads only their own values. Before sign-in (for example a native app at launch), and for any key a user's own values don't hold yet, the SDK reads the signed-out values: the bundle fetched without a session, which holds each key's default value and nothing targeted at a user. A response the server evaluated without a session although the app was signed in (the session had expired) is saved as signed-out values and leaves the user's own untouched.

Sign-out deletes the signed-out user's cached values; getCached then returns the signed-out values, then configDefaults, until the next fetch. A response still in flight for the signed-out session is never cached.

Where the cache lives:

SDKStorage
Web, ReactlocalStorage, under the configured storage prefix (with sessionPersistence: 'memory', the page's memory)
React Native, ExpoAsyncStorage
iOS (Swift)Application Support/<bundle id>/com.layers.amba, excluded from backups
Android (Kotlin)noBackupFilesDir/com.layers.amba; pass a context to configure (without one the cache lives in memory for the process)
Flutterthe plugin's Application Support (iOS) or no-backup files (Android) directory
UnityApplication.persistentDataPath/com.layers.amba
Nodenone (server-side; fetch per request)

Before configure finishes

On Web and React Native, configure() is asynchronous. A getCached call that runs while it is still loading returns the configDefaults passed to that configure() call, then your default.

Operations

fetch()

Returns a single bundle and refreshes the cache:

{
  version: 'v42',       // version stamp set in the console
  values: {
    hero_copy: 'Welcome to amba',
    onboarding_steps: 3,
    pricing: {
      pro_monthly: 999,
      pro_annual: 9999,
    },
  },
}

The response carries Cache-Control: private, max-age=300, so in a browser a repeat config.fetch() within five minutes can return the browser's cached copy.

getCached(key, default)

SDKSignature
Web, React Native, ExpoAmba.config.getCached<T>(key: string, defaultValue?: T): T
ReactuseConfigValue<T>(key: string, defaultValue: T): T
SwiftAmba.config.getCached(key: String, default: T) -> T, and getCached(key:) -> Any?
KotlinAmba.config.getCached(key, default) for String, Boolean, Int, Long, Double; getCached(key): JsonElement?
DartAmba.config.getCached<T>(String key, T defaultValue); getCached<Object?>(key, null) for the raw value
C#Amba.Config.GetCached<T>(string key, T defaultValue), and GetCached(string key): JToken

Patterns

Per-flag vs. config

Use feature flags for on/off decisions. Use config for values like copy, pricing, thresholds:

// Flag: "is the new checkout turned on?"
const newCheckout = Amba.flags.isEnabled('new_checkout');
 
// Config: "what discount do they see today?"
const discount = Amba.config.getCached('checkout_discount', 0);

Config evaluates each key's conditions for the signed-in user (defaults before sign-in), and flags return the same project-wide set of enabled flags to every user.

Refresh

The SDK refreshes on the first cached read for each user. Call config.fetch() whenever you want current values beyond that: on app foreground, or after a known server-side update. Each successful fetch updates what getCached returns.

Reference

On this page