Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(experiments): use exact page filters in creating-experiments setup call (#104143)

posthog[bot]ebafd18d3c59
diff --git a/products/experiments/skills/creating-experiments/SKILL.md b/products/experiments/skills/creating-experiments/SKILL.md
index b25bff45611c..43f3049f3f12 100644
--- a/products/experiments/skills/creating-experiments/SKILL.md
+++ b/products/experiments/skills/creating-experiments/SKILL.md
@@ -18,10 +18,36 @@ Choose settings from the project's facts rather than asking, and say which choic
The right bucketing, metric and running time depend on the project: who sees the page, which SDKs evaluate the flag, how often the metric event happens.
Read that before configuring anything.
-1. From the request, infer the **target** (the event that marks someone reaching the change, usually `$pageview` plus a URL fragment for a page) and a **candidate metric event**.
+1. From the request, infer the **target** (the event that marks someone reaching the change, usually `$pageview` for a page) and a **candidate metric event**.
Confirm both exist with `read-data-schema`. Don't ask the user for event names you can find.
-2. If the `experiment-setup-context` tool is available, call it once with `target_event`, `target_url_contains` (for a page) and `metric_event`.
- If it is not available, continue without it and treat every choice below as a best guess. Never call a tool you can't see.
+ For a page, read `event_property_values` for `$host` and `$pathname` on the target event as well.
+ The response samples the values rather than listing them all, so read it for the shape the project records (a trailing slash, a `www.` prefix, the casing) rather than as proof that a value is absent.
+ An exact filter has to carry that shape: `/pricing` matches nothing where every pageview says `/pricing/`, and `example.com` matches nothing where the host is `www.example.com`.
+2. If the `experiment-setup-context` tool is available, call it once with `target_event` and `metric_event`.
+ For a web surface, add `target_properties` with an exact `$host`.
+ Add an exact `$pathname` as well when the surface is one page.
+ `target_url_contains` is a substring match on `$current_url`.
+ A bare domain matches any host that contains it, `notexample.com` included, and a homepage path matches every page under it.
+ Both overstate the traffic and the exposure rate.
+ For a surface that spans several pages, keep the exact `$host` and put only the path fragment in `target_url_contains`.
+ Add `metric_properties` in the same call when the candidate metric counts only some occurrences of its event.
+ If the tool is not available, continue without it and treat every choice below as a best guess. Never call a tool you can't see.
+
+ Each filter needs a `type` of `event` or `person`, a `key`, an `operator` and a `value`.
+ The call rejects the `flag_evaluates_to` operator with a 400 that names it.
+ For the homepage of one domain:
+
+ ```json
+ {
+ "target_event": "$pageview",
+ "target_properties": [
+ { "key": "$host", "type": "event", "operator": "exact", "value": ["www.example.com"] },
+ { "key": "$pathname", "type": "event", "operator": "exact", "value": ["/"] }
+ ],
+ "metric_event": "your_conversion_event"
+ }
+ ```
+
3. Apply [references/setup-decisions.md](references/setup-decisions.md) to the result. It maps each fact to a choice (bucketing, where the flag is evaluated, exposure, primary metric, running time, precedent) and to a tier for the summary.
4. Carry those choices into steps 1 to 3.
diff --git a/products/experiments/skills/creating-experiments/references/setup-decisions.md b/products/experiments/skills/creating-experiments/references/setup-decisions.md
index d3003fbfff09..8eec3f2daced 100644
--- a/products/experiments/skills/creating-experiments/references/setup-decisions.md
+++ b/products/experiments/skills/creating-experiments/references/setup-decisions.md
@@ -61,6 +61,9 @@ Keep the test-account filter on (creation turns it on by default) and say so. If
- If it doesn't, build an inline metric.
3. Otherwise pick a shape from the metric templates in `configuring-experiment-analytics` (`references/metric-templates.md`). Tier: best guess.
+If the metric counts only some occurrences of its event, for example a purchase with one payment method, pass those filters as `metric_properties` on the setup-context call. Use the same filters on the metric you build.
+Without them, `candidate_metric` reports a baseline for every occurrence of the event, and the running time below is too optimistic. `candidate_metric.metric_properties` echoes the filters the tool read.
+
Every conversion window carries a unit (`conversion_window_unit`). A window without a unit is ignored.
## Feasibility and running time
@@ -81,7 +84,13 @@ When `candidate_metric.status` is `ok` and it has baseline stats:
The estimate assumes people are exposed on the target surface. If the flag is evaluated more widely (across the whole app, or on a page before the one that changes), the exposed population is larger and converts less. The baseline and the running time are then too optimistic. Say so, and consider a custom exposure on the surface event.
-`target_url_contains` is a substring match on the URL: a bare domain matches every page on it and overstates the page's traffic. Pass the most specific fragment you can.
+Check how the call scoped the target surface before you trust these numbers. `target_surface.target_properties` and `target_surface.target_url_contains` echo the filters the tool read.
+`target_url_contains` is a substring match on `$current_url`, so a bare domain matches any host that contains it, and a homepage path matches every page under it. Both overstate the page's traffic and the exposure rate.
+If the echo came back wider than the surface under test, the numbers here are too optimistic.
+Correct the scope and call the tool once more: an exact `$host` and an exact `$pathname` in `target_properties` for one page, or an exact `$host` with only the path fragment in `target_url_contains` for a wider surface.
+Read the numbers from the second response.
+A `persons_reached` of 0 straight after an exact filter usually means the value is not the one the project records, such as `/pricing` against `/pricing/`.
+Read the shape back with `read-data-schema` (`event_property_values`, a sample of the values) and correct the filter, rather than widening it.
Tier: confident on the arithmetic, best guess on the inputs (the baseline is an estimate over `candidate_metric.window_days`).