@traffical/cli manages your Traffical configuration as code. You define parameters, events, and metrics in a .traffical/ directory, version-control them alongside your application, and sync with the platform with push, pull, and status.
Why config-as-code
- Single source of truth — parameter and event definitions live in your repo, reviewed in pull requests like any other code.
- No drift — definitions you push become synced: read-only in the dashboard, so the repo and the platform can’t disagree.
- Typed events — generate TypeScript types from your event schemas so invalid
track()calls fail at compile time. - CI-enforceable —
traffical statusexits non-zero on drift, so you can gate merges on the repo and platform being in sync.
Installation
Quickstart
Initialize
From your project root, scaffold the
.traffical/ directory and link a project:init logs you in, lets you pick an org and project, writes config.yaml and project.yaml, creates a public SDK key, and drops example code for your framework.Edit your config
Add or change parameters and events in
.traffical/config.yaml. See the configuration file reference for every field.Authentication
For interactive use, log in once with the browser-based device flow:~/.config/traffical/auth.json (mode 0600). The session holds a refresh token and renews access tokens automatically, so you rarely log in again.
whoami without --verify reports the cached session. A cached session can still be reported as authenticated after it has ended server-side — use --verify when you need a definitive answer.Credential precedence
The CLI resolves a bearer token in this order:--api-key <key>on the command lineTRAFFICAL_API_KEYenvironment variable (org-scoped key — the CI path)TRAFFICAL_API_TOKENenvironment variable (pre-minted JWT, for agents)- The device-flow session from
traffical login - A legacy
~/.trafficalrcprofile (--profile <name>) — deprecated
TRAFFICAL_API_KEY and skip login entirely.
Selecting a project
A repo is linked to exactly one Traffical project, recorded in.traffical/project.yaml.
--force to re-link a repo that’s already linked.
Manage orgs and projects directly:
Syncing configuration
status — see the difference
10 when there’s drift, so it doubles as a CI check.push — repo → Traffical
--dry-run— validate and print the diff without applying.--prune— archive synced definitions that have been removed from the file. Without it, removals stay on the platform.
pull — Traffical → repo
config.yaml. Dashboard-only definitions stay in the dashboard until you import them. --include-types runs generate-types afterwards.Importing dashboard definitions
Definitions created in the dashboard are dashboard-only until you adopt them into code:Type-safe events
Generate TypeScript types from your event definitions so invalid event names and properties become compile errors:TrafficalEventProperties map — event name → typed property shape. Wrap your client’s track:
pull (or in CI) to keep types in sync. See Type-safe events for the full flow.
CI/CD integration
Command reference
| Command | Description |
|---|---|
login | Authenticate via browser (OAuth device flow). |
logout | Remove the local session. |
whoami | Show the active identity and linked project. |
init | Log in, link a project, and scaffold .traffical/. |
link / unlink | Link the repo to a project / remove the link. |
org list / org use | List orgs / set the default org. |
project list / create / use | Manage projects in the active org. |
status | Show drift between local and remote. |
push | Send local definitions to Traffical. |
pull | Pull synced definitions into the repo. |
sync | Bidirectional sync (local wins on conflict). |
import param / import metrics | Adopt dashboard definitions into code. |
generate-types | Generate TypeScript types from event definitions. |
Global options
| Option | Description |
|---|---|
-c, --config <path> | Path to the config file (default .traffical/config.yaml). |
-b, --api-base <url> | Override the API endpoint. |
-j, --format <fmt> | human (default) or json. |
-q, --quiet | Suppress non-essential output. |
-p, --profile <name> | Legacy ~/.trafficalrc profile (deprecated). |
TRAFFICAL_API_KEY, TRAFFICAL_API_TOKEN, TRAFFICAL_API_BASE.
Exit codes
| Code | Meaning |
|---|---|
0 | Success. |
1 | Validation error in config. |
2 | Authentication error (not logged in / token invalid). |
3 | Network or API error. |
4 | Not linked (no project.yaml). |
10 | Drift detected (status). |
11 | Experiment needs attention. |
Next steps
Configuration file
Every field in config.yaml, project.yaml, and metrics.yaml.
Parameters
Typed values with defaults.
Type-safe events
Codegen, SDK typing, and dev-mode validation.
Quickstart
Resolve a parameter and track an event.