Configuring experiment analytics

From PostHog/skills · View interactive version

Configuring experiment analytics is an AI agent skill from the GitHub repository PostHog/skills. Configures the analytics side of a PostHog experiment — exposure criteria (server-resolved default exposure event vs custom exposure events), primary and secondary metrics, the supported metric types (count, sum, ratio with `math` and `math_property`, retention with `retention_window_start` and `sta

How to use this skill

Skill file

Configuring experiment analytics

This skill answers: Who is included in the analysis? and How to measure impact?

Exposure criteria

Exposure criteria determine which users are counted in the experiment analysis.

Exposure event

Two options:

  1. Default exposure event — users are included when the experiment's default exposure event fires for the experiment's flag: $feature_flag_called, or $experiment_exposure for newer experiments. Which one applies is resolved server-side — read resolved_exposure_event from experiment-get rather than assuming either name (both events carry the same properties). When it is $feature_flag_called, also read $experiment_exposure (event IN ('$feature_flag_called', '$experiment_exposure')), and count persons, not rows. This is the standard approach — it means a user is included only when they actually encounter the feature flag in your code.
  2. Custom exposure event — users are included when a specific custom event fires. Use this when you want tighter control over who enters the analysis (e.g., only users who actually visit the page where the experiment runs).

Filters on the exposure event remove individual events, not users.

A user still counts as long as one of their exposure events passes the filters.

To keep users out of the experiment, exclude them in the flag's release conditions before launch (see configuring-experiment-rollout).

Multiple variant handling

When a user is exposed to multiple variants (e.g., due to flag changes or race conditions):

behavior cannot be clearly attributed to a single variant and is not recommended unless necessary.

Bias risk on uneven splits. "Exclude from analysis" combined with an uneven variant split can

introduce bias — multi-variant users are dropped asymmetrically and the smaller variant loses a larger

fraction of its assignments. If those users behave differently from the rest, the smaller variant's

metrics will be skewed.

The right mitigation depends on experiment state:

use the overall rollout percentage to limit test-variant exposure. This removes the bias and

preserves statistical power. See configuring-experiment-rollout.

variants, which is bad for user experience and data quality. Switch this setting to "Use first

seen variant" instead — it keeps already-assigned users in their original variant (no reassignment) and

removes the asymmetric exclusion.

Filter test accounts

exposure_criteria.filterTestAccounts (default: true) — excludes internal/test users from the analysis.

Resolving experiments

Metric changes require an experiment ID. If the user refers to an experiment by name

or description (e.g. "add metrics to the checkout test"), load the finding-experiments

skill to resolve it to a concrete ID before proceeding.

Metrics

A metric reaches an experiment one of two ways, both via experiment-update:

replaces the entire inline list, so always get the current experiment first via experiment-get

to preserve existing metrics.

Attached by ID via saved_metrics_ids (this list also replaces the experiment's existing

saved-metric links, so resend the full set — see Step 1).

Prefer reusing a shared metric over duplicating it inline. Build a new inline metric only when

no suitable shared metric already exists.

Step 1: Check for an existing shared metric (REQUIRED — match by definition, not name)

Before building any new inline metric, you MUST check whether the project already has a shared

(saved) metric that measures the same thing, and reuse it. Duplicating a metric that already exists

as a shared metric fragments measurement and is exactly what we want to avoid.

**Reuse is decided by the metric _definition_ — the event or action plus the metric type — not the

name.** Saved metrics are named by each team's own conventions, which you cannot guess, so you must

compare on what each metric measures (its query), never on its title.

Workflow:

  1. Know what you're about to build first. Settle the target event(s)/action(s) and metric type

(mean / funnel / ratio / retention / quantile) before searching — see Step 2 to confirm the event exists via

read-data-schema. You can only recognize a duplicate once you know the concrete event/action,

so this check runs _after_ you've pinned down the event, not before.

  1. Search by the event, then compare each candidate's query. Call experiment-saved-metrics-list

with ?event=<the event you're measuring> to find metrics that reference it — matched directly (an

EventsNode) or via the step events of any action a metric references, so action-based metrics are

found by the event their action fires on. Then for each returned row, inspect its query (not the

name/description): a saved metric is a reuse match when its query measures the **same event or

action with the same metric_type** (and compatible math) as the metric you'd otherwise build, even

if its name is different.

the action fires on — pass that event, not the action's label.

never the underlying event or action — so it cannot find a definition match. Use search only when the

user names a specific saved metric to attach (name resolution, not a definition match).

  1. If a saved metric matches the definition — confirm the match with the user by name/description,

then attach it instead of building a new one:

existing links, so include the already-attached ones plus the new entry. Each entry has shape

{ "id": <saved-metric id>, "metadata": { "type": "primary" } } — set type to "primary" or

"secondary". metadata is optional and defaults to primary.

top-level id (the _link_ id) AND a saved_metric field (the _metric_ id). saved_metrics_ids

wants the saved_metric value, not the link id — sending the link id attaches the wrong

metric or fails validation.

  1. If nothing in the library measures the same event/action + type — build an inline metric

(Step 2+). When that inline metric is likely to be reused across experiments, offer to create it

as a shared metric instead, via experiment-saved-metrics-create, then attach it as above, so the

next experiment can reuse it.

Step 2: Discover available events (REQUIRED before building an inline metric)

Before suggesting or building any new inline metric, you MUST call read-data-schema to discover

what events actually exist in the project. Do NOT skip this step. Do NOT suggest event names

based on what you think the project might track — only use events you have confirmed exist.

(Attaching an existing shared metric from Step 1 does not need this — it already encodes its events.)

This applies even when:

Workflow:

  1. Call read-data-schema to get the project's events
  2. Present relevant events to the user based on the experiment's hypothesis
  3. User picks which events to use for metrics
  4. Configure metrics with those confirmed event names

Legitimate exception — allow_unknown_events: true:

Pass this on experiment-create / experiment-update only when the user is intentionally instrumenting an event that hasn't been ingested yet (e.g. setting up the experiment before the code change ships). Confirm this with the user — never use it as a workaround for "the event lookup didn't return what I expected".

Example:

User: "Let's add some metrics for the checkout experiment"

WRONG: "I'd suggest using purchase_completed as the primary metric..."
  (hallucinated event name — never seen the project's actual events)

RIGHT: *calls read-data-schema* → "Here are the events in your project
  related to checkout: `checkout_step_completed`, `payment_processed`,
  `order_confirmed`. Which of these represents a successful checkout?"

Step 3: Choose metric type

Start from a template in references/metric-templates.md: it maps common requests ("more revenue", "people come back") to a metric type and the defaults to set with it (window units, winsorization, goal).

There are five metric types. Each has kind: "ExperimentMetric":

| metric_type | When to use | Required fields |

| ------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |

| "mean" | Average of a numeric property per user (revenue, session duration, pageviews per user) | source |

| "funnel" | Conversion rate from exposure through one or more ordered actions | series (1 or more steps) |

| "ratio" | Rate of one event relative to another | numerator, denominator — set math: "sum" + math_property on a side to aggregate a property; filters never aggregate |

| "retention" | Do users come back after exposure? | start_event, completion_event, retention_window_start, retention_window_end, retention_window_unit, start_handling |

| "quantile" | A percentile of a numeric property across all events (p90 load time, p99 latency) | source with math_property, quantile (0.01 to 0.99, e.g. 0.9 for p90) |

Funnel metrics and the implicit exposure step

Funnel metrics automatically prepend the experiment's exposure event as step_0.

So a funnel with 1 step in series is a valid 2-step funnel: exposure → action.

This is the correct choice for measuring "what percentage of exposed users did X?"

Examples:

Mean vs funnel for the same event

Both can reference the same event — the difference is whether you care about count/magnitude (mean) or yes/no conversion (funnel).

Mean vs percentile for durations

Retention: same vs different start/completion event

The retention window is measured from the start event, so the events you pick decide what's measured:

The start occurrence never counts as its own completion (only a distinct later event does), so both shapes are valid:

See references/metric-configuration.md for the full rendered ExperimentMetric schema (all five metric types, with required fields per type) plus WRONG/RIGHT JSON pairs for the failure modes that come up most often (ratio with is_set filter instead of math: "sum" + math_property; retention without retention_window_start / start_handling). Read it before assembling a ratio or retention payload — the required fields are authoritative.

Step 4: Primary vs secondary

Interpreting results

See references/interpreting-results.md for guidance on reading experiment results, statistical significance, and when to ship vs end.

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.