Skip to main content
@traffical/cli manages your Traffical configuration as code. You define parameters, context attributes, 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 and context — generate TypeScript types from your event schemas and attribute registry so invalid track() calls and misspelled context keys fail at compile time.
  • CI-enforceabletraffical status exits non-zero on drift, so you can gate merges on the repo and platform being in sync.
Policies, allocations, and lifecycle decisions still live in the dashboard — the CLI owns the definitions, not the rollout state.

Installation

Requires Node.js 18+.

Quickstart

1

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.
2

Edit your config

Add or change parameters, attributes, and events in .traffical/config.yaml. See the configuration file reference for every field.
3

Push to Traffical

4

Check for drift

Authentication

For interactive use, log in once with the browser-based device flow:
This opens your browser, asks you to confirm a code, and stores a session at ~/.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:
  1. --api-key <key> on the command line
  2. TRAFFICAL_API_KEY environment variable (org-scoped key — the CI path)
  3. TRAFFICAL_API_TOKEN environment variable (pre-minted JWT, for agents)
  4. The device-flow session from traffical login
  5. A legacy ~/.trafficalrc profile (--profile <name>) — deprecated
For CI, set TRAFFICAL_API_KEY and skip login entirely.

Selecting a project

A repo is linked to exactly one Traffical project, recorded in .traffical/project.yaml.
When a flag is omitted, the CLI prompts: a select list for ≤10 options, a search box beyond that. Pass --force to re-link a repo that’s already linked. Manage orgs and projects directly:

Syncing configuration

1

status — see the difference

Shows what’s synced, what has local changes to push, and what exists only in the dashboard. Exits with code 10 when there’s drift, so it doubles as a CI check.
The Attributes section lists user-managed attributes only; $-prefixed system attributes are never shown. Local-only attributes (in the file, not yet pushed) count as drift.
2

push — repo → Traffical

Creates new definitions and updates existing synced ones. Pushed definitions become read-only in the dashboard. Attributes go first — before parameters, property groups, events, and metrics — so policies validated later in the run already see the registry.
  • --dry-run — validate and print the diff without applying.
  • --prune — archive synced parameters and attributes that have been removed from the file. Without it, removals stay on the platform. An attribute still referenced by a policy condition is skipped — reported, not archived — so pruning never breaks a running policy. A file with no attributes: block at all leaves the project’s attributes alone.
3

pull — Traffical → repo

Downloads synced parameters, events, and property groups into config.yaml. Dashboard-only parameters, events, and metrics stay in the dashboard until you import them; attributes are the exception — every active user-managed attribute is written, synced or not. System attributes ($-prefixed) are never written. --include-types runs generate-types afterwards.
4

sync — both directions

Pushes local changes and pulls new remote definitions in one pass. On conflict, local wins. --all syncs every config file in the repo.

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:
This emits a TrafficalEventProperties map — event name → typed property shape. Wrap your client’s track:
Run it after every pull (or in CI) to keep types in sync. See Type-safe events for the full flow.

Typed context

When the repo is linked and you are logged in, generate-types also reads the project’s attribute registry and emits a TrafficalContext interface plus a TrafficalAttributeKey union in the same file:
  • One optional property per active attribute, system attributes included; $-prefixed and dotted keys are quoted.
  • stringstring, enum → a union of its values, numbernumber, booleanboolean, timestampnumber (epoch milliseconds).
  • The trailing index signature keeps unregistered keys compiling; TrafficalAttributeKey is the union of registered keys only.
The summary line reports Attributes: N. If the repo is not linked, you are not logged in, or the attribute registry is unavailable on the server, the context types are left out and the summary prints a note instead of failing — the parameter and event types are still generated.

CI/CD integration

Command reference

Global options

Environment variables: TRAFFICAL_API_KEY, TRAFFICAL_API_TOKEN, TRAFFICAL_API_BASE.

Exit codes

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.