What you’ll need
- A Traffical account with a project created in the dashboard
- A Node.js 18+ project to drop code into (or you can start fresh)
- About twenty minutes
1. Install the CLI
2. Initialize the project
From the root of your repo:- Detects your framework (Express, Next.js, Svelte, etc.)
- Creates a
.traffical/config.yaml - Creates a public SDK key in the dashboard
- Writes an example file showing how to call the SDK in your framework
traffical login (device login) — or paste a management-scoped key (traffical_sk_... with mgmt scope) from the dashboard’s Settings → API keys. The CLI uses this to talk to Traffical; it stays on your machine.
You’ll end up with something like:
3. Define the parameter you want to test
Open.traffical/config.yaml and add the parameter we’ll experiment on:
#1E6EFB.
4. Add an event definition for the goal metric
We need a way to measure success. Add apurchase event:
5. Wire the SDK into your code
Install the Node SDK:#1E6EFB because no policy is overriding it yet. That’s fine; we’re confirming the wire-up works.
6. Track the goal event
Wherever your code knows a purchase happened, fire a track event:7. Create the experiment policy
Now the fun part. In the dashboard:- Open Layers and pick the base layer (created automatically). Or create a new layer if you want this experiment in its own pool.
- Click New policy.
- Configure it:
- Kind: Static
- State: Draft (we’ll flip it to Running in a moment)
- Allocations:
control— bucket range0–4999— leavecheckout.button.colorunset (it’ll use the parameter default)treatment— bucket range5000–9999—checkout.button.color: "#22C55E"(a green)
- Save.
- Set the state to Running.
The bucket count for your project is typically 10000. If yours is different (you can check in Settings → Hashing), adjust the allocation ranges proportionally.
8. Watch it work
Within 60 seconds the SDK will refresh its bundle and pick up the new policy. From this point on,getParams returns one of the two colours depending on the user’s bucket.
To verify locally without waiting:
- Pass different
userIdvalues togetParamsand you’ll see the two colours alternate. - Open the DevTools bookmarklet on a page running the SDK to see the current assignment for the current user.
9. Configure the goal metric
For the dashboard to show results, you need to tell it which event to measure and how:- In the dashboard, open your policy.
- Click Add goal metric.
- Pick the
purchaseevent. - Aggregation: conversion rate (we want to know which colour produces more purchases per exposed user).
10. Read the results
After enough traffic accumulates, the policy detail page will show:- Exposures per allocation
- Conversion rate per allocation (purchases / exposed users)
- Confidence interval on each
- A significance indicator when the result becomes statistically meaningful
11. Decide and ship
When you have a winner:- Update the parameter default. In the dashboard or in
.traffical/config.yaml, setcheckout.button.colorto the winning value. Push. - Complete the policy. In the dashboard, mark the policy
completed. It stops being evaluated. - Done. Every user now gets the winning value via the new default. Your application code doesn’t change.
What’s next
You’ve now seen the whole loop. From here:- Add more variants. A static policy can have any number of allocations.
- Promote to a rollout. Instead of flipping straight to the new default, attach a rollout that ramps the winner gradually with health checks.
- Try adaptive. Replace the static policy with an adaptive one — the engine will shift traffic toward the winner automatically.
- Layer experiments. Run a second experiment on a different parameter at the same time. Put it in a different layer and they won’t contaminate each other.
- Type your events. Generate TypeScript types for your event definitions so the compiler catches bad track calls. See Type-safe events.
Common stumbles
- “Bundle not loading” — check your
apiKeyis for the right project and environment, and that you awaitcreateTrafficalClient. - “All users in one allocation” — confirm the
userIdfield actually varies. A common bug is passing a hardcoded string in early testing. - “Events not appearing” — track events batch by default. Either wait ~30s or call
await traffical.flushEvents()in tests. - “Bucket count looks wrong” — verify your project’s bucket count in Settings. Defaults to 10000.
Reference
- Quickstart — the bare minimum to integrate
- CLI — all commands and flags
- Policies — kinds, states, allocations
- Experiment design — hypothesis, metrics, sizing
- Canonical experiments — patterns for other shapes