SDK API Reference
Methods exposed by the published Layers SDKs.
This reference covers the JavaScript family of SDKs (@layers/client,
@layers/react-native, @layers/expo, @layers/node). No native Swift
/ Kotlin / Dart / C# SDK is published — the APIs they would expose are
not part of this reference yet.
LayersClient (@layers/client, @layers/node)
import { LayersClient, type LayersConfig } from '@layers/client';
const layers = new LayersClient(config);
await layers.init();| Method | Signature | Notes |
|---|---|---|
| constructor | new LayersClient(config: LayersConfig) | See initialization. |
init() | () => Promise<void> | Fetches remote config, hydrates queue. |
track() | (eventName: string, properties?: object) => Promise<void> | Queue an event. |
screen() | (screenName: string, properties?: object) => Promise<void> | Screen / page view. |
setUserProperties() | (properties: object) => Promise<void> | POSTs to /users/properties. |
setConsent() | ({ advertising?: boolean; analytics?: boolean }) => Promise<void> | Updates local and server consent state. |
getConsentState() | () => { advertising: boolean; analytics: boolean } | Local snapshot. |
isAnalyticsEnabled() | () => boolean | Current analytics consent. |
isAdvertisingEnabled() | () => boolean | Current advertising consent. |
setAppUserId() | (appUserId: string | undefined) => void | Attach authenticated user ID. |
getAppUserId() | () => string | undefined | |
getSessionId() | () => string | |
startNewSession() | () => void | Force a new session_id. |
setOnlineState() | (isOnline: boolean) => void | Manual online/offline override. |
setDeviceInfo() | (info: Partial<BaseEvent>) => void | Override device metadata (platform, os_version, etc.). |
flush() | () => Promise<void> | Force-send queued events. |
getRemoteConfig() | () => RemoteConfig | null | Last-fetched server config. |
getRemoteConfigVersion() | () => string | undefined | ETag of last config fetch. |
getConfig() | () => LayersConfig | Initial config passed in. |
Deprecated aliases: setUserId / getUserId — use setAppUserId /
getAppUserId.
Layers (@layers/react-native, @layers/expo)
@layers/react-native exports a singleton Layers object that wraps
LayersClient with React Native-specific surfaces:
import Layers from '@layers/react-native';
await Layers.init(config);Core methods (same semantics as LayersClient):
Layers.track(event, properties?)Layers.screen(name, properties?)Layers.setUserProperties(properties)Layers.setConsent({ advertising?, analytics? })Layers.setAppUserId(id)/Layers.clearAppUserId()Layers.isReady()Layers.destroy()Layers.getClient()— access the underlyingLayersClient.
Native surfaces (alpha, may change):
Layers.att.request()/getStatus()/isSupported()— App Tracking Transparency.Layers.skan.setPreset(name)/setRules(rules)/getCurrentConversionValue()/getMetrics()— SKAdNetwork conversion value management.Layers.deepLinks.configure(config)/addListener(listener)/getMetrics()/parseUrl(url)/clearAttribution().Layers.connectors.*— per-network (Meta, TikTok, Snap, Google) connector wiring. Note that Layers does NOT bundle the native Meta / TikTok pixel SDKs; CAPI is server-side.Layers.debug.*— overlay, metric dumps. Development only.Layers.requestTracking(options?)— shortcut for ATT.
Helpers for Expo Router:
useLayersExpoRouterTracking(usePathname, useGlobalSearchParams)<LayersExpoRouter usePathname={...} useGlobalSearchParams={...} />
What's NOT in the API
These were described in earlier versions of this reference but do NOT exist:
Layers.configure(...)— useinit()/new LayersClient().Layers.identify(userId, traits)— usesetAppUserId+setUserProperties.Layers.reset()— usesetAppUserId(undefined)(orclearAppUserId()on React Native).Layers.sha256(value)— the server hashes PII for you; if you need local hashing, use Nodecrypto/SubtleCrypto.Layers.setSampling(name, rate)— sampling is configured server-side via remote config, not per-SDK.Layers.lastEventId— not exposed.Layers.setATTStatus(status)— useLayers.att.request()orLayers.requestTracking().
Versioning
All published packages follow semver. Current versions are alpha
(2.x) — expect breaking changes before a 1.0 API is committed to.
Pin to an exact version if predictability matters more than upgrades.