Developer guide: 11. Experiments

Create, run and read experiments: metrics, exposures, power and results.

Embed
Preview of the card
<a href="https://lucidace.com/help/developer-guide-experiments"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/8dceabba-c6b7-45e8-b7b1-b67ed89a72ab/social-card.svg?v=3e7ae33eec8b" alt="Developer guide: 11. Experiments" width="600" height="315"></a>

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

name

required, 1-200 chars

kind

ab (default), aa, multivariate, split_url, server, mobile, bandit, holdout; anything else is 400 invalid kind or traffic_pct

variants

[{key, allocation_pct, payload?}], 2 or more unique keys, allocation_pct >= 0 summing to 100; the first is the control

factors

full-factorial instead of variants: needs kind: "multivariate", 2-4 factors of 2-5 levels each

traffic_pct

share of eligible people enrolled, in (0, 100], default 100

metrics

`{primary:[metric id], secondary:[metric id], guardrail:[{metric:id}], groups?:[{group:id, role: primary

audience

filters (same grammar as flag filters) limiting who is enrolled

exposure

`{event?, filters?, multiple_variants?: exclude

holdout_id

an active holdout (11.5); an ended holdout is 409

namespace_id, namespace_pct

take a slice of a mutually exclusive layer; 409 when no free range

schedule

planned start and end (start_at, end_at)

requires_approval

gate start, pause, stop through the approval policy

stats_config

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

POST .../experiments/{id}/start

draft

running

turns the flag on; fails on missing required custom fields or open approval policy

POST .../pause

running

paused

POST .../resume

paused

running

POST .../stop

running, paused

stopped

flag off

POST .../ship

running, paused, stopped

shipped

winner to the flag

POST .../archive

stopped, shipped (verified from shipped)

archived

POST .../unarchive

archived

previous status

PATCH .../variants/{key} {name}

any

unchanged

renames the variant's display name (1 to 200 characters); the key stays fixed so exposures and results stay joined; audited as experiment.variant_renamed. GET .../results returns variant_names ({key: name})

POST .../duplicate

any

new draft

body {name?, flag_key?, project_id?}

POST .../request-approval?for=

change request

for is start (default), pause, stop, update or custom_code

POST .../freeze

{frozen: bool, snapshot?: bool} stop enrolling new units while metrics keep running

POST .../reset

restart analysis

POST .../rerandomize

like a flag's: {confirm, reason, reset_sticky?}

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

GET .../results?breakdown=&as_of=

full analysis

GET .../results/series?metric=

cumulative result at the end of each day: {metric, points:[{as_of, metric}]}

GET .../results/daily?metric=

per-day effect and a novelty verdict

GET .../results/distribution?metric=&bins=

per-variant histogram of per-unit values

GET .../results/slices?dimension=&metric=

per-slice results and Cochran's Q heterogeneity

GET .../checks

pre-exposure bias and A/A checks

GET .../running-time

{exposed, daily_exposure_rate, sample_size_per_variant, required_total, remaining_days, progress_pct}

GET .../interactions

concurrent experiments whose effects interact

GET .../links, POST .../links, GET .../preview_links?url=

tickets; QA links ?lc_preview=<flag>:<variant> per variant

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(the list is{data, next_cursor}), POST {p}/holdouts/{id}/end`

`GET

POST {p}/experiment-ideas, GET

`GET

POST {p}/experiment-templates, GET

`GET

POST {p}/experiment-triggers, GET

POST {p}/experiments/assets

upload an image for a web variant, answer {url} (served at /v1/experiment-assets/{project_id}/{name})

`GET

POST {p}/decisions, GET

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 a selector and a type: text (value), attr (name, value; no on* attributes, URL-checked for href src action formaction), style (styles object), hide, reorder (index), insert (html, position before|after|prepend|append; no scripts, styles, frames, forms or handlers), image (src), css, js. At most 200 changes per payload. css, js and inserted HTML need approval when the policy experiment.custom_code is 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. Condition type: 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" with stats_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/contextual returns {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. Also GET|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.

Updated