Developer guide: 11. Experiments
Create, run and read experiments: metrics, exposures, power and results.
11. Experiments
An experiment splits people across variants of a flag it owns, measures metrics against exposures, and reports with a stats engine. Flow: metric, create, start, send exposures and events, read results, stop, ship or archive. All calls below were run live. Scopes: experiment:read, experiment:write.
11.1 Prerequisites: metrics and create
Metrics live under {p}/metrics (created with POST {p}/metrics; a new one has status: "proposed" until the catalog is approved, and it is usable in experiments right away). kind: "proportion" is 1 when an event follows exposure; other kinds usable in experiments: mean, ratio, funnel, retention, quantile, threshold. Names match ^[a-z][a-z0-9_]{0,62}$.
M1=$(lc -X POST "$P/metrics" -d '{"name":"signup_conversion","kind":"proportion",
"definition":{"event":{"source":{"type":"event","name":"signed_up"}},"window_days":7}}' | jq -r .id)
M2=$(lc -X POST "$P/metrics" -d '{"name":"page_error_rate","kind":"proportion",
"definition":{"event":{"source":{"type":"event","name":"error_shown"}},"window_days":7}}' | jq -r .id)
EXP_ID=$(lc -X POST "$P/experiments" -d '{
"name":"Pricing page test","hypothesis":"Shorter page lifts signups","flag_key":"pricing-test",
"variants":[{"key":"control","allocation_pct":50},{"key":"test","allocation_pct":50}],
"traffic_pct":100,
"metrics":{"primary":["'$M1'"],"secondary":[],"guardrail":[{"metric":"'$M2'"}]},
"stats_config":{"engine":"frequentist","alpha":0.05,"cuped":false}}' | jq -r .id)201 with the experiment; header x-lucida-flag-key carries the flag key. Body fields:
Field | Rules |
|---|---|
| required, 1-200 chars |
|
|
|
|
| full-factorial instead of |
| share of eligible people enrolled, in (0, 100], default 100 |
| `{primary:[metric id], secondary:[metric id], guardrail:[{metric:id}], groups?:[{group:id, role: primary |
| filters (same grammar as flag filters) limiting who is enrolled |
| `{event?, filters?, multiple_variants?: exclude |
| an active holdout (11.5); an ended holdout is |
| take a slice of a mutually exclusive layer; |
| planned start and end ( |
| gate start, pause, stop through the approval policy |
| see below |
Flag ownership: the experiment creates and owns its flag. flag_key omitted = a slug of the name. flag_key must be new, or an existing multivariate flag whose variants match and that no other running experiment owns; a boolean flag answers 409 flag_key names a boolean flag; an experiment needs a multivariate flag. While the experiment is running, edit the flag only through the experiment.
stats_config (partial; missing keys come from experiment-defaults): engine (frequentist default, bayesian, sequential, hybrid), alpha (0.05), power (0.8), mde (0.05 relative), cuped (false), cuped_window_days (14), cuped_covariates (metric ids), correction (none, bonferroni, holm, bh), one_sided, guardrail_alpha, bayes_threshold (0.95), stratify (property), baseline_variant, cluster_by (group:<0-4>, person_property:<key>, property:<key>), planned_days (for hybrid), prior, metric_overrides, tau2, and for bandits bandit (below).
Other routes: GET {p}/experiments?limit=&q=&cursor=, DELETE {p}/experiments/{id} (experiment:write; 204, or 409 while the experiment is running: stop it first), GET|PATCH {p}/experiments/{id} (PATCH takes name, hypothesis, audience, traffic_pct, variants, metrics, exposure, schedule, stats_config, requires_approval; changing metrics, stats config or exposure of a started experiment needs "confirm_running_change": true, else 409 running_change), GET .../experiments/{id}/checklist ({items:[{key,label,status: pass|warn|fail,detail}], ready}), POST {p}/experiments/traffic-preview (people per day an audience would enrol), GET {p}/experiments/timeline?from=&to=, GET {p}/experiments/health, GET {p}/experiments/program, GET {p}/experiments/meta-analysis?metric=&alpha=.
11.2 Lifecycle
Route | From status | To | Notes |
|---|---|---|---|
|
|
| turns the flag on; fails on missing required custom fields or open approval policy |
|
|
| |
|
|
| |
|
|
| flag off |
|
|
| winner to the flag |
|
|
| |
|
| previous status | |
| any | unchanged | renames the variant's display name (1 to 200 characters); the |
| any | new | body |
| change request |
| |
|
| ||
| restart analysis | ||
| like a flag's: |
A wrong transition is 409 cannot <action> an experiment that is <status>; an unknown action is 404. Ship body: {"winner":"test","scope":"audience|everyone|population","population":[filters],"conclusion":"...","holdback_pct":10}. winner must be a variant key (400). scope defaults to audience; population needs population filters. holdback_pct (above 0, at most 50, winner must not be the control) keeps a share on the control to measure long-term effect: GET .../holdback reads it and POST .../holdback/end serves the winner to everyone. Ship stores a results snapshot in the experiment.
lc -X POST "$P/experiments/$EXP_ID/start"
# exposures + goal events from your app (public key, capture host)
curl -sS -X POST "$LUCIDA_CAPTURE/v1/batch" -H "Content-Type: application/json" -d '{"api_key":"'"$PK"'","batch":[
{"uuid":"0192f4c4-0000-7000-8000-000000000001","event":"$exposure","distinct_id":"u1","properties":{"$feature_flag":"pricing-test","$feature_flag_response":"test"}},
{"uuid":"0192f4c4-0000-7000-8000-000000000002","event":"signed_up","distinct_id":"u1"}]}'
lc "$P/experiments/$EXP_ID/results" | jq '{status, srm, guardrail_breached, metrics: .segments[""].metrics}'
lc -X POST "$P/experiments/$EXP_ID/stop"
lc -X POST "$P/experiments/$EXP_ID/ship" -d '{"winner":"test","scope":"everyone","conclusion":"test wins"}'
lc -X POST "$P/experiments/$EXP_ID/archive"11.3 Results and diagnostics
Route | Purpose |
|---|---|
| full analysis |
| cumulative result at the end of each day: |
| per-day effect and a |
| per-variant histogram of per-unit values |
| per-slice results and Cochran's Q heterogeneity |
| pre-exposure bias and A/A checks |
|
|
| concurrent experiments whose effects interact |
| tickets; QA links |
results shape: {experiment_id, status, meta:{control, start, end, stats_config}, srm:{observed, chi2, p_value, flagged} (null until at least 100 units are exposed), switched_units, exposure_health:{exposed_units, multi_exposed_units, flagged}, guardrail_breached, segments:{"": {srm, metrics:[...]}}}. Each metric has id, name, role (primary, secondary, guardrail) and variants[] with units, conversions, mean, diff, relative_lift, ci_low, ci_high, p_value, p_adjusted, significant, chance_to_win, expected_loss. Fields that need a baseline are null for the control. Each variants[] row names its variant in variant. Treat srm.flagged: true (a sample ratio mismatch) as a broken assignment and do not trust the lift. Results reflect events within a few seconds. breakdown and slices.dimension accept device_type, country, browser, os, channel, property:<key>, person_property:<key> (anything else is 400 unknown breakdown).
11.4 Power, checklist, defaults
POST {p}/experiments/power (scope experiment:read): body {baseline, mde, kind?: proportion|mean, absolute?, sd?, alpha?, power?, variants?, daily_traffic?, traffic_fraction?}. baseline is the control mean or rate, mde is relative unless absolute: true, sd is required for mean. Answer {sample_size_per_variant, duration_days} (duration_days when daily_traffic is sent). Reverse mode: send units_per_variant (or days with daily_traffic) and read mde_absolute and mde_relative. An unknown kind is 400 with the detail "unknown kind, valid values are proportion and mean".
lc -X POST "$P/experiments/power" -d '{"baseline":0.2,"mde":0.1,"kind":"proportion","daily_traffic":500}'
# {"sample_size_per_variant":6510,"duration_days":27,...}GET|PUT {p}/experiment-defaults: a partial stats_config merged under every experiment created afterwards ({"alpha":0.05,"power":0.8,"cuped":true}); keys given on the experiment win.
11.5 Holdouts, ideas, templates, triggers, assets, decisions
Route | Purpose |
|---|---|
`GET | POST {p}/holdouts |
`GET | POST {p}/experiment-ideas |
`GET | POST {p}/experiment-templates |
`GET | POST {p}/experiment-triggers |
| upload an image for a web variant, answer |
`GET | POST {p}/decisions |
lc -X POST "$P/holdouts" -d '{"name":"global-holdout","percentage":5,"filters":{}}'
lc -X POST "$P/experiment-ideas" -d '{"title":"Shorter checkout","hypothesis":"Fewer fields lift conversion","tags":["checkout"],"score":{"impact":7,"confidence":5,"ease":8}}'
lc -X POST "$P/experiment-templates" -d '{"name":"Std A/B","from_experiment":"'$EXP_ID'"}'
lc -X POST "$P/decisions" -d '{"title":"Ship shorter pricing page","kind":"decision","status":"accepted","body":"test +17% signups","tags":["pricing"],"links":[{"kind":"experiment","id":"'$EXP_ID'"}]}'Decision kind is decision or learning; status is proposed, accepted, rejected or superseded; link kind is experiment, flag, insight or dashboard with a uuid id. Idea score is a free object and a new idea is scored.
11.6 Web experiments, triggers, bandits, other designs
Web experiment: put a visual change list in a variant payload as
lc_changes. Each change has aselectorand atype:text(value),attr(name,value; noon*attributes, URL-checked forhref src action formaction),style(stylesobject),hide,reorder(index),insert(html,positionbefore|after|prepend|append; no scripts, styles, frames, forms or handlers),image(src),css,js. At most 200 changes per payload.css,jsand inserted HTML need approval when the policyexperiment.custom_codeis on.POST {p}/experiments/{id}/goals{name, selector, url?, text?, role?}creates a click action, a metric and attaches it.Activation trigger in every variant payload as
lc_trigger:{"op":"and|or","conditions":[...]}, groups nest 3 deep, 1-20 conditions. Conditiontype:time_on_page(seconds, max 3600),time_in_session(seconds, max 86400),pages_viewed(count, max 100),scroll(percent, 1-100),exit_intent,manual,element_visible(selector),custom_event(event). Reuse with{"lc_trigger":{"saved_id":"<experiment-triggers id>"}}.Bandit:
kind: "bandit"withstats_config.bandit{min_weight (default 0.05), top_two (false), contextual?: {property|properties[], alpha, lambda, bins?}}. An hourly job rebalances variant percentages by Thompson sampling.GET .../experiments/{id}/bandit/contextualreturns{choices, importance, properties}(empty until data).Preview-only designs (no experiment needed):
POST {p}/experiments/designs/{assign, did, did-events, geo-lift, synthetic, switchback/schedule, switchback/analyze, switchback/analyze-events}. Details: Experiment designs. AlsoGET|POST {p}/experiments/surrogates,POST .../surrogates/{id}/train,GET .../experiments/{id}/surrogates/{model_id}.Related:
POST|GET|PUT|DELETE .../experiments/{id}/variants/{variant}/screenshot,POST .../variants/{variant}/cohort,GET {p}/replays/{session_id}/experiment-markers. More: Experiments over the API, Experiment ideas, Web experiment triggers.