Skip to content

createAnonymousIdProvider

createAnonymousIdProvider(storage, key?): () => Promise<string>

Defined in: packages/api-client/src/core/utils/anonymousId.ts:33

Build an async getter that returns a stable anonymous id, generating one on first call and caching it inside the supplied StorageAdapter.

Behavior matches the legacy getAnonymousId:

  • Returns the existing id when present.
  • Generates and persists a new id when the key is empty.

Cross-platform: relies entirely on the injected adapter, so the same provider works for MemoryStorageAdapter (SSR), WebStorageAdapter (browser), or any consumer-supplied implementation (RN, Node CLI).

StorageAdapter

string = DEFAULT_ANONYMOUS_ID_KEY

() => Promise<string>