Prerequisites
- A Traffical account with a project created in the dashboard
- An SDK key (
traffical_sk_..., scopessdk:read+sdk:write) from your organization’s API Keys page (in the sidebar when viewing your organization, or from the account menu) - Node.js 18+
1
Install the SDK
2
Initialize the client
Create a client with your organization, project, environment, and an SDK key. The client fetches the config bundle from Traffical and caches it in memory.The
await matters — the client fetches the initial bundle before it can resolve parameters. If you can’t await at startup, use createTrafficalClientSync and call waitUntilReady() later.3
Resolve a parameter
Call The
getParams with user context and default values. Resolution is fully local — no API call is made.context object is used for two things:- Bucketing — the unit key (typically
userId) determines which allocation the user gets, and the assignment is stable across requests. - Targeting — other fields like
locale,plan, orcountryare evaluated against policy conditions.
defaults object is your safety net. The SDK returns these values when no policy matches, when the bundle hasn’t loaded yet, or when Traffical is unreachable.4
Track an event
Send a track event when a user does something you want to measure. Events are batched in the background.If you’re running an adaptive policy, the optimizer uses these events as reward signals to learn which variants perform best.
Full example
Next steps
How it works
Local resolution, evaluation modes, and the config bundle.
Parameters
Typed values with defaults.
Projects & environments
What
orgId, projectId, and env refer to.Your first experiment
The full loop — CLI, policy, SDK, results — in twenty minutes.