traffical
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTraffical
Traffical
Traffical is a parameter-first experimentation and optimization platform. It unifies feature flags, A/B testing, and contextual bandits into a single system. SDKs resolve parameters locally at the edge — no per-request API calls, sub-millisecond latency, works offline.
Traffical是一款以参数为核心的实验与优化平台。它将功能标志、A/B测试和上下文多臂老虎机整合到单一系统中。SDK在边缘节点本地解析参数——无需每次请求调用API,延迟低于毫秒级,支持离线使用。
Mental Model
核心思路
Traffical is parameter-first. You define parameters with defaults, and Traffical handles the rest.
┌─────────────────────────────────────────────────────────────────────┐
│ Your Code │
│ │
│ 1. Define parameters with defaults │
│ 2. Use the resolved values │
│ 3. Track events on conversion │
└─────────────────────────────────────────────────────────────────────┘
▲
│ (hidden from you)
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Traffical │
│ │
│ • Layers & policies for mutual exclusivity │
│ • Bucket assignment & deterministic hashing │
│ • Thompson Sampling & contextual bandits │
│ • Statistical analysis & optimization │
└─────────────────────────────────────────────────────────────────────┘Key insights:
- Parameters, Not Experiments — You define parameters with defaults. Experiments, feature flags, and optimizations are policies that control parameter assignment. Your code doesn't need to know which.
- Resolution Is Local — The SDK fetches a config bundle once and caches it. Every resolution call is synchronous from cache — no network latency, no render flicker.
- Decisions Are Tracked Automatically — When you call or
useTraffical(), a decision event is automatically sent to Traffical (enabled by default viadecide()). This connects parameter resolution to conversion events for intent-to-treat analysis. No manual setup needed.trackDecisions: true - Track Events for Learning — Call when valuable actions happen (purchase, signup, etc.). Traffical uses this data for adaptive optimization.
track()
Traffical的核心是以参数为优先。你只需定义带默认值的参数,剩下的由Traffical处理。
┌─────────────────────────────────────────────────────────────────────┐
│ 你的代码 │
│ │
│ 1. 定义带默认值的参数 │
│ 2. 使用解析后的参数值 │
│ 3. 在转化节点跟踪事件 │
└─────────────────────────────────────────────────────────────────────┘
▲
│ (对你透明的底层逻辑)
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Traffical │
│ │
│ • 用于互斥性的层级与策略机制 │
│ • 用户分组与确定性哈希算法 │
│ • 汤普森采样与上下文多臂老虎机算法 │
│ • 统计分析与自动优化 │
└─────────────────────────────────────────────────────────────────────┘核心要点:
- 参数优先,而非实验优先——你只需定义带默认值的参数。实验、功能标志和优化都是控制参数分配的策略,你的代码无需关心具体是哪种策略。
- 本地解析参数——SDK会一次性获取配置包并缓存。所有解析请求直接从缓存同步读取——无网络延迟,无页面闪烁。
- 自动跟踪决策事件——当你调用或
useTraffical()时,决策事件会自动发送到Traffical(默认通过decide()启用)。这会将参数解析与转化事件关联,用于意向治疗分析,无需手动配置。trackDecisions: true - 跟踪事件以实现优化——当用户完成有价值的操作(如购买、注册)时调用。Traffical会利用这些数据进行自适应优化。
track()
When to Use Traffical
适用场景
| Scenario | Action |
|---|---|
| Adding a new feature | Wrap in feature flag for gradual rollout |
| Changing existing UI | A/B test against current implementation |
| Modifying conversion paths | Experiment with success metrics |
| Updating algorithms/logic | Test impact before full rollout |
| Anything affecting revenue | Always experiment first |
| 场景 | 操作 |
|---|---|
| 新增功能 | 用功能标志包裹,逐步推出 |
| 修改现有UI | 与当前实现进行A/B测试 |
| 调整转化路径 | 针对成功指标进行实验 |
| 更新算法/逻辑 | 全面推出前测试影响 |
| 任何影响营收的变更 | 务必先进行实验 |
Recommended Workflow
推荐工作流
Always use the Traffical CLI to manage parameters. The CLI is the primary tool for setting up and syncing configuration. Do not skip it.
- Initialize — Run to set up the project non-interactively (or check for an existing
npx @traffical/cli init --api-key <management-key> --framework <name> --yesdirectory). The user must provide a Management Key or Full Access key from the dashboard. Always pass.traffical/and--frameworkto avoid interactive prompts.--yes - Define parameters — Add parameters and events to
.traffical/config.yaml - Sync — Run to sync parameters to the Traffical platform
npx @traffical/cli push - Install SDK — Add the appropriate SDK package to your project
- Use in code — Resolve parameters and track events using the SDK
- Verify — Run to confirm everything is in sync
npx @traffical/cli status
请始终使用Traffical CLI管理参数。CLI是设置和同步配置的主要工具,请勿跳过这一步。
- 初始化——运行以非交互式方式设置项目(或检查是否存在
npx @traffical/cli init --api-key <management-key> --framework <name> --yes目录)。用户必须提供来自控制台的管理密钥或全权限密钥。请始终传入.traffical/和--framework以避免交互式提示。--yes - 定义参数——在中添加参数和事件
.traffical/config.yaml - 同步——运行将参数同步到Traffical平台
npx @traffical/cli push - 安装SDK——为项目添加对应的SDK包
- 代码中使用——使用SDK解析参数并跟踪事件
- 验证——运行确认所有内容已同步
npx @traffical/cli status
The Traffical CLI
Traffical CLI
The CLI () is how you initialize projects, define parameters, and keep local config in sync with the Traffical platform. You can run it via (no global install required):
@traffical/clinpxbash
npx @traffical/cli <command>Or install globally for shorter commands:
bash
npm install -g @traffical/cli
traffical <command>CLI()用于初始化项目、定义参数,并保持本地配置与Traffical平台同步。你可以通过运行它(无需全局安装):
@traffical/clinpxbash
npx @traffical/cli <command>或全局安装以使用更短的命令:
bash
npm install -g @traffical/cli
traffical <command>Check for existing setup
检查现有配置
Look for a directory or in the project root. If it exists, the project is already initialized — check the config for existing parameters before creating new ones.
.traffical/traffical.yaml在项目根目录查找目录或文件。如果存在,说明项目已初始化——在创建新参数前,请检查现有配置。
.traffical/traffical.yamlInitialize a new project
初始化新项目
If no directory exists, initialize Traffical:
.traffical/Important: Theflag requires a real Management Key or Full Access key. Never fabricate or guess API keys. If no key is available in environment variables (--api-key) orTRAFFICAL_API_KEY, ask the user to provide one from https://app.traffical.io/settings/api-keys.~/.trafficalrc
bash
undefined如果不存在目录,请初始化Traffical:
.traffical/重要提示:标志需要有效的管理密钥或全权限密钥。请勿伪造或猜测API密钥。如果环境变量(--api-key)或TRAFFICAL_API_KEY中没有可用密钥,请让用户从https://app.traffical.io/settings/api-keys获取。~/.trafficalrc
bash
undefinedBasic init (will auto-detect framework and prompt if needed):
基础初始化(会自动检测框架,必要时提示):
npx @traffical/cli init --api-key <management-key>
npx @traffical/cli init --api-key <management-key>
Fully non-interactive init (recommended for AI agents and CI/CD):
完全非交互式初始化(推荐AI Agent和CI/CD使用):
npx @traffical/cli init --api-key <management-key> --framework react --yes
**Available flags for `init`:**
| Flag | Description |
|------|-------------|
| `--api-key <key>` | Management or Full Access key (falls back to `TRAFFICAL_API_KEY` env var or `~/.trafficalrc`) |
| `--framework <name>` | Skip framework detection. Values: `react`, `nextjs`, `svelte`, `sveltekit`, `vue`, `nuxt`, `node` |
| `--project <id>` | Use a specific project (skips project selection prompt, useful with org-scoped keys) |
| `-y, --yes` | Auto-accept all detected defaults — no interactive prompts |
| `--no-sdk-key` | Skip automatic SDK key creation |
> **For AI agents:** Always pass `--framework` and `--yes` to avoid interactive prompts that will hang in non-TTY environments.
This creates:
.traffical/
├── config.yaml # Parameter and event definitions (committed)
├── .env # TRAFFICAL_API_KEY=... (gitignored, auto-generated SDK key)
├── .gitignore # Ensures .env is never committed
├── AGENTS.md # AI agent integration guide (project-specific)
└── TEMPLATES.md # Framework-specific code templates
The CLI auto-detects your framework (React, Next.js, Svelte, SvelteKit, Vue, Nuxt, Node.js) and generates appropriate templates. Existing synced parameters and events are imported into `config.yaml` automatically.
**After init**, add `TRAFFICAL_API_KEY` from `.traffical/.env` to your project's `.env` or hosting environment for runtime SDK use. The auto-generated key has `sdk:read` and `sdk:write` scopes — just enough for parameter resolution and event tracking.npx @traffical/cli init --api-key <management-key> --framework react --yes
**`init`命令可用标志:**
| 标志 | 描述 |
|------|-------------|
| `--api-key <key>` | 管理密钥或全权限密钥(优先从环境变量`TRAFFICAL_API_KEY`或`~/.trafficalrc`读取) |
| `--framework <name>` | 跳过框架检测。可选值:`react`, `nextjs`, `svelte`, `sveltekit`, `vue`, `nuxt`, `node` |
| `--project <id>` | 使用指定项目(跳过项目选择提示,适用于组织级密钥) |
| `-y, --yes` | 自动接受所有检测到的默认值——无交互式提示 |
| `--no-sdk-key` | 跳过自动创建SDK密钥 |
> **针对AI Agent:**请始终传入`--framework`和`--yes`,避免在非TTY环境中出现交互式提示导致进程挂起。
初始化后会创建以下文件:
.traffical/
├── config.yaml # 参数和事件定义(需提交到版本控制)
├── .env # TRAFFICAL_API_KEY=...(自动生成的SDK密钥,已加入.gitignore)
├── .gitignore # 确保.env不会被提交
├── AGENTS.md # 项目专属的AI Agent集成指南
└── TEMPLATES.md # 框架专属的代码模板
CLI会自动检测你的框架(React、Next.js、Svelte、SvelteKit、Vue、Nuxt、Node.js)并生成对应的模板。已同步的参数和事件会自动导入到`config.yaml`中。
**初始化完成后**,将`.traffical/.env`中的`TRAFFICAL_API_KEY`添加到项目的`.env`或托管环境变量中,供运行时SDK使用。自动生成的密钥拥有`sdk:read`和`sdk:write`权限——刚好满足参数解析和事件跟踪的需求。Managing parameters with the CLI
使用CLI管理参数
After initialization, use the CLI to keep local config and the Traffical platform in sync:
bash
undefined初始化完成后,使用CLI保持本地配置与Traffical平台同步:
bash
undefinedAfter adding or modifying parameters in config.yaml — push to platform
在config.yaml中添加或修改参数后——推送到平台
npx @traffical/cli push
npx @traffical/cli push
Before writing code — check what parameters exist and their sync status
编写代码前——检查已存在的参数及其同步状态
npx @traffical/cli status
npx @traffical/cli status
Pull latest parameters from the platform into local config
从平台拉取最新参数到本地配置
npx @traffical/cli pull
npx @traffical/cli pull
Bidirectional sync (local wins for conflicts)
双向同步(冲突时本地配置优先)
npx @traffical/cli sync
npx @traffical/cli sync
Import specific parameters from the dashboard (supports wildcards)
从控制台导入指定参数(支持通配符)
npx @traffical/cli import "ui.*"
npx @traffical/cli import "ui.*"
Validate config without pushing (dry run)
验证配置但不推送(试运行)
npx @traffical/cli push --dry-run
**Always run `npx @traffical/cli push` after modifying `.traffical/config.yaml`.** This syncs your changes to the platform and prevents drift.npx @traffical/cli push --dry-run
**修改`.traffical/config.yaml`后,请务必运行`npx @traffical/cli push`**。这会将你的变更同步到平台,避免配置漂移。Authentication
认证机制
Traffical uses different API key types for different purposes:
| Key Type | Prefix | Purpose | Scopes |
|---|---|---|---|
| SDK Key | | Runtime SDKs — fetch config, send events | |
| Management Key | | CLI, CI/CD — create/modify entities, push/pull/sync | |
| Full Access Key | | Administrative — all operations | |
Traffical为不同场景使用不同类型的API密钥:
| 密钥类型 | 前缀 | 用途 | 权限范围 |
|---|---|---|---|
| SDK密钥 | | 运行时SDK——获取配置、发送事件 | |
| 管理密钥 | | CLI、CI/CD——创建/修改实体、推送/拉取/同步 | |
| 全权限密钥 | | 管理员操作——所有权限 | |
How init handles keys
初始化流程中的密钥处理
- You provide a Management Key (or Full Access key) via or
--api-key~/.trafficalrc - The CLI authenticates and selects org/project
- The CLI auto-creates a project-scoped SDK key via the API and saves it to
.traffical/.env - The is created/updated to ensure
.traffical/.gitignoreis never committed.env
This means:
- The Management Key stays in (for CLI operations like push/pull/sync)
~/.trafficalrc - The SDK Key goes into (for runtime use in your app)
.traffical/.env - Only the least-privileged key (SDK) is used at runtime — no risk of leaking management access
- 你通过或
--api-key提供管理密钥(或全权限密钥)~/.trafficalrc - CLI完成认证并选择组织/项目
- CLI通过API自动创建项目级SDK密钥,并保存到
.traffical/.env - 创建/更新,确保
.traffical/.gitignore不会被提交.env
这意味着:
- 管理密钥存储在中(用于CLI的推送/拉取/同步操作)
~/.trafficalrc - SDK密钥存储在中(用于应用运行时)
.traffical/.env - 运行时仅使用权限最低的SDK密钥——无泄露管理权限的风险
SDK key location
SDK密钥位置
The SDK key auto-generated by is stored in:
init.traffical/.envinit.traffical/.envContains: TRAFFICAL_API_KEY=traffical_sk_...
内容:TRAFFICAL_API_KEY=traffical_sk_...
Copy this value to your project's `.env` or hosting environment variables for your SDK to use at runtime.
请将该值复制到项目的`.env`或托管环境变量中,供SDK运行时使用。SDK configuration values
SDK配置参数
After , the contains and . Use these values (along with an like ) when initializing the SDK. The SDK key is in as .
traffical init.traffical/config.yamlproject.idproject.orgIdenv"production".traffical/.envTRAFFICAL_API_KEYtraffical init.traffical/config.yamlproject.idproject.orgIdenv"production".traffical/.envTRAFFICAL_API_KEYInstall an SDK
安装SDK
| Package | Use case |
|---|---|
| React and Next.js apps |
| Svelte and SvelteKit apps |
| Server-side Node.js (Express, Fastify, etc.) |
| Any browser environment |
bash
undefined| 包名 | 适用场景 |
|---|---|
| React和Next.js应用 |
| Svelte和SvelteKit应用 |
| 服务端Node.js(Express、Fastify等) |
| 任何浏览器环境 |
bash
undefinedPick the one matching your framework
选择与你的框架匹配的包
npm install @traffical/react
npm install @traffical/react
or
或
npm install @traffical/svelte
npm install @traffical/svelte
or
或
npm install @traffical/node
undefinednpm install @traffical/node
undefinedSDK Usage
SDK使用示例
React / Next.js
React / Next.js
Provider setup (wrap your app once):
tsx
import { TrafficalProvider } from "@traffical/react";
function App() {
return (
<TrafficalProvider
config={{
orgId: "org_xxx",
projectId: "proj_xxx",
env: "production",
apiKey: "pk_live_your_public_key",
}}
// Optional: provide unitKeyFn for logged-in users
// unitKeyFn: () => currentUser.id,
>
<MyApp />
</TrafficalProvider>
);
}Use in components:
tsx
import { useTraffical } from "@traffical/react";
function CheckoutButton() {
const { params, track } = useTraffical({
defaults: {
"checkout.button.color": "#1E6EFB",
"checkout.button.label": "Buy now",
},
});
return (
<button
style={{ backgroundColor: params["checkout.button.color"] }}
onClick={() => track("checkout_click")}
>
{params["checkout.button.label"]}
</button>
);
}Provider配置(仅需在应用根组件包裹一次):
tsx
import { TrafficalProvider } from "@traffical/react";
function App() {
return (
<TrafficalProvider
config={{
orgId: "org_xxx",
projectId: "proj_xxx",
env: "production",
apiKey: "pk_live_your_public_key",
}}
// 可选:为已登录用户提供unitKeyFn
// unitKeyFn: () => currentUser.id,
>
<MyApp />
</TrafficalProvider>
);
}组件中使用:
tsx
import { useTraffical } from "@traffical/react";
function CheckoutButton() {
const { params, track } = useTraffical({
defaults: {
"checkout.button.color": "#1E6EFB",
"checkout.button.label": "立即购买",
},
});
return (
<button
style={{ backgroundColor: params["checkout.button.color"] }}
onClick={() => track("checkout_click")}
>
{params["checkout.button.label"]}
</button>
);
}Svelte / SvelteKit
Svelte / SvelteKit
Layout setup:
svelte
<!-- src/routes/+layout.svelte -->
<script>
import { setTrafficalContext } from "@traffical/svelte";
setTrafficalContext({
orgId: "org_xxx",
projectId: "proj_xxx",
env: "production",
apiKey: "pk_live_your_public_key",
context: { userId: data.user?.id ?? "anonymous" },
});
</script>
<slot />Use in components ( and are Svelte stores — use prefix):
paramstrack$svelte
<script>
import { getTraffical } from "@traffical/svelte";
const { params, track } = getTraffical({
defaults: {
"checkout.button.color": "#1E6EFB",
"checkout.button.label": "Buy now",
},
});
</script>
<button
style="background-color: {$params['checkout.button.color']}"
on:click={() => $track("checkout_click")}
>
{$params["checkout.button.label"]}
</button>布局配置:
svelte
<!-- src/routes/+layout.svelte -->
<script>
import { setTrafficalContext } from "@traffical/svelte";
setTrafficalContext({
orgId: "org_xxx",
projectId: "proj_xxx",
env: "production",
apiKey: "pk_live_your_public_key",
context: { userId: data.user?.id ?? "anonymous" },
});
</script>
<slot />组件中使用(和是Svelte存储对象——需加前缀):
paramstrack$svelte
<script>
import { getTraffical } from "@traffical/svelte";
const { params, track } = getTraffical({
defaults: {
"checkout.button.color": "#1E6EFB",
"checkout.button.label": "立即购买",
},
});
</script>
<button
style="background-color: {$params['checkout.button.color']}"
on:click={() => $track("checkout_click")}
>
{$params["checkout.button.label"]}
</button>Node.js (Server-side)
Node.js(服务端)
typescript
import { createTrafficalClient } from "@traffical/node";
const traffical = await createTrafficalClient({
orgId: "org_xxx", // from .traffical/config.yaml
projectId: "proj_xxx", // from .traffical/config.yaml
env: "production",
apiKey: process.env.TRAFFICAL_API_KEY!, // from .traffical/.env
});
// Resolve parameters (synchronous, from cached bundle)
const params = traffical.getParams({
context: { userId: "user_789", locale: "en-US" },
defaults: {
"checkout.button.color": "#1E6EFB",
"pricing.discount_pct": 0,
},
});
// Track events (value goes in properties, unitKey in options)
traffical.track("purchase", { value: 49.99 }, { unitKey: "user_789" });typescript
import { createTrafficalClient } from "@traffical/node";
const traffical = await createTrafficalClient({
orgId: "org_xxx", // 来自.traffical/config.yaml
projectId: "proj_xxx", // 来自.traffical/config.yaml
env: "production",
apiKey: process.env.TRAFFICAL_API_KEY!, // 来自.traffical/.env
});
// 解析参数(同步操作,从缓存读取)
const params = traffical.getParams({
context: { userId: "user_789", locale: "en-US" },
defaults: {
"checkout.button.color": "#1E6EFB",
"pricing.discount_pct": 0,
},
});
// 跟踪事件(值放在properties中,unitKey放在options中)
traffical.track("purchase", { value: 49.99 }, { unitKey: "user_789" });Node.js (CLI / Scripts)
Node.js(CLI / 脚本)
For non-web contexts like CLI tools, batch jobs, or scripts, you can use without a web server. Use a machine or job identifier instead of a user ID:
@traffical/nodetypescript
import { createTrafficalClient } from "@traffical/node";
const traffical = await createTrafficalClient({
orgId: "org_xxx", // from .traffical/config.yaml
projectId: "proj_xxx", // from .traffical/config.yaml
env: "production",
apiKey: process.env.TRAFFICAL_API_KEY!,
});
const params = traffical.getParams({
context: { unitKey: "batch-job" },
defaults: {
"feature.new_algorithm": false,
"processing.batch_size": 100,
},
});
if (params["feature.new_algorithm"]) {
// Use new algorithm
}对于CLI工具、批处理任务或脚本等非Web场景,你可以在不启动Web服务器的情况下使用。请使用机器或任务标识符替代用户ID:
@traffical/nodetypescript
import { createTrafficalClient } from "@traffical/node";
const traffical = await createTrafficalClient({
orgId: "org_xxx", // 来自.traffical/config.yaml
projectId: "proj_xxx", // 来自.traffical/config.yaml
env: "production",
apiKey: process.env.TRAFFICAL_API_KEY!,
});
const params = traffical.getParams({
context: { unitKey: "batch-job" },
defaults: {
"feature.new_algorithm": false,
"processing.batch_size": 100,
},
});
if (params["feature.new_algorithm"]) {
// 使用新算法
}track() API
track() API
The signature differs between client-side and server-side SDKs:
track()- React/Svelte (client-side): — The
track(event, properties?)anddecisionIdare automatically bound from the provider context. Just callunitKey.track("purchase", { value: 49.99 }) - Node.js (server-side): — You must provide
track(event, properties?, options?)in the third argument:unitKey. Optionally passtraffical.track("purchase", { value: 49.99 }, { unitKey: userId })for explicit attribution.decisionId
客户端与服务端SDK的签名有所不同:
track()- React/Svelte(客户端):——
track(event, properties?)和decisionId会自动从Provider上下文中获取。只需调用unitKey即可。track("purchase", { value: 49.99 }) - Node.js(服务端):——你必须在第三个参数中提供
track(event, properties?, options?):unitKey。也可以传入traffical.track("purchase", { value: 49.99 }, { unitKey: userId })进行显式归因。decisionId
Config-as-Code
即码配置(Config-as-Code)
Parameters and events are defined in (or ). This file is the source of truth — version-control it alongside your code.
.traffical/config.yamltraffical.yamlyaml
version: "1.0"
project:
id: proj_xxx
orgId: org_xxx
parameters:
checkout.button.color:
type: string
default: "#1E6EFB"
description: Primary CTA button color
checkout.show_trust_badges:
type: boolean
default: false
pricing.discount_pct:
type: number
default: 0
events:
purchase:
valueType: currency
unit: USD
description: User completes a purchase
add_to_cart:
valueType: count
description: User adds item to cart参数和事件定义在(或)中。该文件是唯一可信源——请与代码一起提交到版本控制。
.traffical/config.yamltraffical.yamlyaml
version: "1.0"
project:
id: proj_xxx
orgId: org_xxx
parameters:
checkout.button.color:
type: string
default: "#1E6EFB"
description: 主CTA按钮颜色
checkout.show_trust_badges:
type: boolean
default: false
pricing.discount_pct:
type: number
default: 0
events:
purchase:
valueType: currency
unit: USD
description: 用户完成购买
add_to_cart:
valueType: count
description: 用户将商品加入购物车Parameter types
参数类型
| Type | Use case |
|---|---|
| Colors, labels, URLs, template names |
| Prices, percentages, thresholds, timeouts |
| Feature flags, simple toggles |
| Structured config (multiple related settings) |
| 类型 | 适用场景 |
|---|---|
| 颜色、标签、URL、模板名称 |
| 价格、百分比、阈值、超时时间 |
| 功能标志、简单开关 |
| 结构化配置(多个相关设置) |
Event value types
事件值类型
| Value Type | Use case |
|---|---|
| Monetary values (revenue, order value) |
| Numeric counts (clicks, items, views) |
| Percentages or ratios |
| Binary events (happened or not) |
| 值类型 | 适用场景 |
|---|---|
| 货币价值(收入、订单金额) |
| 数值计数(点击、商品数量、浏览量) |
| 百分比或比率 |
| 二元事件(发生或未发生) |
Adding events to config.yaml
在config.yaml中添加事件
Define events in the block of :
events:.traffical/config.yamlyaml
events:
purchase:
valueType: currency
unit: USD
description: User completes a purchase
signup:
valueType: boolean
description: User creates an account
page_view:
valueType: count
description: User views a pageEach event has:
- (required):
valueType,currency,count, orrateboolean - (optional): unit label for currency events (e.g.,
unit,USD)EUR - (optional but recommended): human-readable explanation
description
After adding events, run to sync them to the platform.
npx @traffical/cli pushEvents discovered at runtime (via calls) will appear in the dashboard even without config definitions, but defining them in config gives you descriptions, value types, and keeps the config file as the source of truth.
track()在的区块中定义事件:
.traffical/config.yamlevents:yaml
events:
purchase:
valueType: currency
unit: USD
description: 用户完成购买
signup:
valueType: boolean
description: 用户创建账户
page_view:
valueType: count
description: 用户浏览页面每个事件包含:
- (必填):
valueType,currency,count或rateboolean - (可选):货币事件的单位(如
unit,USD)EUR - (可选但推荐):人类可读的说明
description
添加事件后,请运行同步到平台。
npx @traffical/cli push即使未在配置中定义,运行时通过调用的事件也会显示在控制台中,但在配置中定义事件可以添加说明、值类型,确保配置文件作为唯一可信源,避免与控制台出现配置漂移。
track()Namespaces
命名空间
Namespaces are optional organizational groupings for parameters. They help organize parameters in the dashboard but do not affect how you use them in code.
yaml
parameters:
bookmarks.max_stored:
type: number
default: 100
namespace: bookmarks # optional organizational grouping
description: Maximum bookmarks per user- The namespace is the default and is omitted from config
"main" - When parameters are imported from the dashboard (via or during
npx @traffical/cli pull), they may includeinit— this is normalnamespace: <name> - Namespace is independent of dot-notation naming (e.g., can be in namespace
bookmarks.max_stored, but this is a convention, not enforced)bookmarks - You do not need to specify a namespace when creating new parameters — they will use the default namespace
命名空间是可选的参数组织方式,可帮助在控制台中整理参数,但不影响代码中的使用方式。
yaml
parameters:
bookmarks.max_stored:
type: number
default: 100
namespace: bookmarks # 可选的组织分组
description: 用户可存储的最大书签数量- 默认命名空间为,在配置中可省略
main - 从控制台导入参数时(通过或初始化),参数可能包含
npx @traffical/cli pull——这是正常现象namespace: <name> - 命名空间与点符号命名无关(例如可属于
bookmarks.max_stored命名空间,但这只是约定,并非强制要求)bookmarks - 创建新参数时无需指定命名空间——将使用默认命名空间
Parameter Naming Conventions
参数命名规范
Use dot notation:
category.subcategory.name| Category | Examples | Use case |
|---|---|---|
| | Feature flags (boolean) |
| | Visual variations |
| | Pricing experiments |
| | Copywriting tests |
| | Explicit variant names |
请使用点符号:
category.subcategory.name| 分类 | 示例 | 适用场景 |
|---|---|---|
| | 功能标志(布尔类型) |
| | 视觉变体 |
| | 定价实验 |
| | 文案测试 |
| | 显式变体名称 |
Best Practices
最佳实践
-
Always use the CLI — Runafter editing config. Run
npx @traffical/cli pushto check sync state. Never skip the CLI — it is the bridge between your config files and the Traffical platform.npx @traffical/cli status -
Check existing parameters first — Look in(or
.traffical/config.yaml) before creating new ones. Runtraffical.yamlto see what's already defined. Reuse existing parameters where possible.npx @traffical/cli status -
Define parameters in config, then push — Add new parameters toand run
.traffical/config.yamlto sync them. This keeps the config file as the source of truth and prevents drift with the dashboard.npx @traffical/cli push -
Always provide in-code defaults — Defaults appear in two places: in(the source of truth for the dashboard and experiment setup) and in your
config.yaml/getParams()calls (the offline fallback). In-code defaults are what the SDK returns when the config bundle hasn't loaded yet or is unreachable. The bundle's resolved value always takes precedence when available.useTraffical() -
Track events at conversion points — Callon purchases, signups, and other valuable actions. This enables adaptive optimization.
track() -
Group related parameters — Keep correlated params in one/
useTraffical()/getTraffical()call for proper attribution.getParams() -
Use meaningful param names — Follow dot notation:. Be descriptive.
category.subcategory.name
-
始终使用CLI——编辑配置后运行。运行
npx @traffical/cli push检查同步状态。请勿跳过CLI——它是连接配置文件与Traffical平台的桥梁。npx @traffical/cli status -
先检查现有参数——在创建新参数前,请查看(或
.traffical/config.yaml)。运行traffical.yaml查看已定义的参数。请尽可能复用现有参数。npx @traffical/cli status -
先在配置中定义参数,再推送——在中添加新参数,然后运行
.traffical/config.yaml同步到平台。这确保配置文件作为唯一可信源,避免与控制台出现配置漂移。npx @traffical/cli push -
始终在代码中提供默认值——默认值出现在两个地方:中(控制台和实验设置的可信源),以及
config.yaml/getParams()调用中(离线回退值)。代码中的默认值是SDK在配置包未加载或不可用时返回的值。当配置包可用时,解析后的值将优先使用。useTraffical() -
在转化节点跟踪事件——在用户完成购买、注册等有价值的操作时调用。这是实现自适应优化的前提。
track() -
分组相关参数——将相关参数放在同一个/
useTraffical()/getTraffical()调用中,以确保正确归因。getParams() -
使用有意义的参数名称——遵循点符号规范:。名称应具有描述性。
category.subcategory.name
What You Don't Need to Know
无需关注的内部细节
These are internal concepts handled by Traffical automatically:
- Layers, policies, allocations — Experiment infrastructure is managed in the dashboard
- Bucket assignment and hashing — Deterministic user assignment happens automatically
- Whether an A/B test vs. optimization is running — Your code is the same either way
- Statistical significance calculations — Traffical handles analysis in the background
- Decision deduplication — Multiple resolution calls are handled efficiently
Just parametrize your app, track conversions, and let Traffical handle the rest.
以下是Traffical自动处理的内部概念,你无需关心:
- 层级、策略、分配机制——实验基础设施由控制台管理
- 用户分组与哈希算法——确定性用户分组自动完成
- 当前运行的是A/B测试还是优化——你的代码无需区分
- 统计显著性计算——Traffical在后台自动处理分析
- 决策去重——多次解析请求会被高效处理
只需将你的应用参数化,跟踪转化事件,剩下的交给Traffical即可。
Documentation
文档
- Quickstart: https://docs.traffical.io/quickstart
- How It Works: https://docs.traffical.io/how-it-works
- Parameters: https://docs.traffical.io/concepts/parameters
- React SDK: https://docs.traffical.io/sdks/react
- Svelte SDK: https://docs.traffical.io/sdks/svelte
- Node.js SDK: https://docs.traffical.io/sdks/node
- CLI: https://docs.traffical.io/tools/cli
- API Overview: https://docs.traffical.io/api/overview
- Dashboard: https://app.traffical.io
- 快速开始: https://docs.traffical.io/quickstart
- 工作原理: https://docs.traffical.io/how-it-works
- 参数: https://docs.traffical.io/concepts/parameters
- React SDK: https://docs.traffical.io/sdks/react
- Svelte SDK: https://docs.traffical.io/sdks/svelte
- Node.js SDK: https://docs.traffical.io/sdks/node
- CLI: https://docs.traffical.io/tools/cli
- API概览: https://docs.traffical.io/api/overview
- 控制台: https://app.traffical.io ",