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.

feat(experiments): add winsorization for ratio metrics (#60120)

Andersfc0f6ed29cd5
diff --git a/.semgrep/rules/hogql-no-fstring.py b/.semgrep/rules/hogql-no-fstring.py
index 2cbf43b4eb85..0de843c95be3 100644
--- a/.semgrep/rules/hogql-no-fstring.py
+++ b/.semgrep/rules/hogql-no-fstring.py
@@ -333,6 +333,13 @@ class TestFstringSafeComputedFragments:
# ok: hogql-fstring-audit
parse_expr(f"{metric_value_field}")
+ def test_value_field(self):
+ value_field = "numerator_value"
+ # ok: hogql-fstring-audit
+ parse_expr(f"min(entity_metrics.{value_field})")
+ # ok: hogql-fstring-audit
+ parse_expr(f"max(entity_metrics.{value_field})")
+
def test_default_breakdown_selector(self):
default_breakdown_selector = "breakdown_value"
# ok: hogql-fstring-audit
diff --git a/.semgrep/rules/hogql-no-fstring.yaml b/.semgrep/rules/hogql-no-fstring.yaml
index 823d281ed93a..a0a6bd0cab59 100644
--- a/.semgrep/rules/hogql-no-fstring.yaml
+++ b/.semgrep/rules/hogql-no-fstring.yaml
@@ -104,7 +104,7 @@ rules:
# Computed expression names (safe: internally built SQL fragments)
- pattern-not-regex: "\\{timestamp_expr\\}|\\{array_merge_operation\\}"
# Experiment query builder (safe: internally-computed CTE strings and hardcoded aliases)
- - pattern-not-regex: "\\{common_ctes\\}|\\{ctes_sql\\}|\\{events_alias\\}|\\{column_ref\\}"
+ - pattern-not-regex: "\\{common_ctes\\}|\\{ctes_sql\\}|\\{events_alias\\}|\\{column_ref\\}|\\{value_field\\}"
# Date filter patterns (safe: computed from internal date range)
- pattern-not-regex: "\\{date_to_filter\\}|\\{date_from_filter\\}"
# Inline ternary conditions (safe: boolean conditions creating constant strings)
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 9a23b7bf7e76..1a686fa04e54 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -16895,6 +16895,23 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "$ref": "#/definitions/ExperimentMetricMathType",
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'.",
+ "enum": [0, 1, 2, 3, 4],
+ "type": "number"
+ },
+ "math_hogql": {
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum.",
+ "type": "string"
+ },
+ "math_property": {
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue').",
+ "type": "string"
+ },
"properties": {
"description": "Event property filters to narrow which events are counted.",
"items": {
@@ -16958,14 +16975,28 @@
"$ref": "#/definitions/ExperimentApiEventSource",
"description": "For ratio metrics: denominator source."
},
+ "denominator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling",
+ "description": "For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped."
+ },
"goal": {
"$ref": "#/definitions/ExperimentMetricGoal",
"description": "Whether higher or lower values indicate success."
},
+ "ignore_zeros": {
+ "description": "For mean metrics: exclude zero values when computing the winsorization percentile thresholds.",
+ "type": "boolean"
+ },
"kind": {
"const": "ExperimentMetric",
"type": "string"
},
+ "lower_bound_percentile": {
+ "description": "For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.",
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
"metric_type": {
"$ref": "#/definitions/ExperimentMetricType"
},
@@ -16977,6 +17008,10 @@
"$ref": "#/definitions/ExperimentApiEventSource",
"description": "For ratio metrics: numerator source."
},
+ "numerator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling",
+ "description": "For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds."
+ },
"retention_window_end": {
"$ref": "#/definitions/integer"
},
@@ -17005,6 +17040,12 @@
"enum": ["first_seen", "last_seen"],
"type": "string"
},
+ "upper_bound_percentile": {
+ "description": "For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.",
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
"uuid": {
"description": "Unique identifier. Auto-generated if omitted.",
"type": "string"
@@ -17623,6 +17664,9 @@
"type": "string"
},
"lower_bound_percentile": {
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
},
"metric_type": {
@@ -17642,6 +17686,9 @@
"$ref": "#/definitions/ExperimentMetricSource"
},
"upper_bound_percentile": {
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
},
"uuid": {
@@ -17662,6 +17709,9 @@
"type": "boolean"
},
"lower_bound_percentile": {
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
},
"metric_type": {
@@ -17672,6 +17722,9 @@
"$ref": "#/definitions/ExperimentMetricSource"
},
"upper_bound_percentile": {
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
}
},
@@ -17741,9 +17794,15 @@
"type": "boolean"
},
"lower_bound_percentile": {
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
},
"upper_bound_percentile": {
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).",
+ "maximum": 1,
+ "minimum": 0,
"type": "number"
}
},
@@ -18052,6 +18111,9 @@
"denominator": {
"$ref": "#/definitions/ExperimentMetricSource"
},
+ "denominator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling"
+ },
"fingerprint": {
"type": "string"
},
@@ -18075,6 +18137,9 @@
"numerator": {
"$ref": "#/definitions/ExperimentMetricSource"
},
+ "numerator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling"
+ },
"response": {
"type": "object"
},
@@ -18098,12 +18163,18 @@
"denominator": {
"$ref": "#/definitions/ExperimentMetricSource"
},
+ "denominator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling"
+ },
"metric_type": {
"const": "ratio",
"type": "string"
},
"numerator": {
"$ref": "#/definitions/ExperimentMetricSource"
+ },
+ "numerator_outlier_handling": {
+ "$ref": "#/definitions/ExperimentMetricOutlierHandling"
}
},
"required": ["metric_type", "numerator", "denominator"],
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 9772f0edf64c..4a767bd08237 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -3540,6 +3540,17 @@ export interface ExperimentApiEventSource {
event?: string
/** Action ID. Required for ActionsNode. */
id?: integer
+ /** How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with
+ * math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order.
+ * Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'. */
+ math?: ExperimentMetricMathType
+ /** Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue'). */
+ math_property?: string
+ /** HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently
+ * falls back to a plain count/sum. */
+ math_hogql?: string
+ /** Group type index to aggregate over. Required when math is 'unique_group'. */
+ math_group_type_index?: 0 | 1 | 2 | 3 | 4
/** Event property filters to narrow which events are counted. */
properties?: EventPropertyFilter[]
}
@@ -3565,6 +3576,26 @@ export interface ExperimentApiMetric {
numerator?: ExperimentApiEventSource
/** For ratio metrics: denominator source. */
denominator?: ExperimentApiEventSource
+ /** For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01
+ * for the 1st percentile). Per-user values below this percentile are clamped to it before
+ * aggregation.
+ * @minimum 0
+ * @maximum 1 */
+ lower_bound_percentile?: number
+ /** For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99
+ * for the 99th percentile). Per-user values above this percentile are clamped to it before
+ * aggregation.
+ * @minimum 0
+ * @maximum 1 */
+ upper_bound_percentile?: number
+ /** For mean metrics: exclude zero values when computing the winsorization percentile thresholds. */
+ ignore_zeros?: boolean
+ /** For ratio metrics: winsorization applied to the numerator aggregate, independently of the
+ * denominator and each with its own percentile thresholds. */
+ numerator_outlier_handling?: ExperimentMetricOutlierHandling
+ /** For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a
+ * binomial-style denominator, which is never clamped. */
+ denominator_outlier_handling?: ExperimentMetricOutlierHandling
/** For retention metrics: start event. */
start_event?: ExperimentApiEventSource
/** For retention metrics: completion event. */
@@ -3631,7 +3662,13 @@ export interface ExperimentMetricBaseProperties extends Node {
}
export type ExperimentMetricOutlierHandling = {
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).
+ * @minimum 0
+ * @maximum 1 */
lower_bound_percentile?: number
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).
+ * @minimum 0
+ * @maximum 1 */
upper_bound_percentile?: number
ignore_zeros?: boolean
}
@@ -3684,6 +3721,11 @@ export type ExperimentRatioMetric = ExperimentMetricBaseProperties & {
metric_type: ExperimentMetricType.RATIO
numerator: ExperimentMetricSource
denominator: ExperimentMetricSource
+ // Winsorization is applied to the numerator and denominator independently,
+ // each with its own percentile bounds and computed thresholds. There is no
+ // per-user ratio to cap, so capping operates on the two component aggregates.
+ numerator_outlier_handling?: ExperimentMetricOutlierHandling
+ denominator_outlier_handling?: ExperimentMetricOutlierHandling
}
export const isExperimentRatioMetric = (metric: ExperimentMetric): metric is ExperimentRatioMetric =>
diff --git a/frontend/src/queries/validators.js b/frontend/src/queries/validators.js
index ec38581a1bae..fc17030bdd75 100644
--- a/frontend/src/queries/validators.js
+++ b/frontend/src/queries/validators.js
@@ -5902,13 +5902,25 @@ const schema63 = {
ignore_zeros: { type: 'boolean' },
isSharedMetric: { type: 'boolean' },
kind: { const: 'ExperimentMetric', type: 'string' },
- lower_bound_percentile: { type: 'number' },
+ lower_bound_percentile: {
+ description:
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).',
+ maximum: 1,
+ minimum: 0,
+ type: 'number',
+ },
metric_type: { const: 'mean', type: 'string' },
name: { type: 'string' },
response: { type: 'object' },
sharedMetricId: { type: 'number' },
source: { $ref: '#/definitions/ExperimentMetricSource' },
- upper_bound_percentile: { type: 'number' },
+ upper_bound_percentile: {
+ description:
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).',
+ maximum: 1,
+ minimum: 0,
+ type: 'number',
+ },
uuid: { type: 'string' },
version: { description: 'version of the node, used for schema migrations', type: 'number' },
},
@@ -9944,19 +9956,53 @@ function validate79(data, { instancePath = '', parentData, parentDataProperty, r
if (data.lower_bound_percentile !== undefined) {
let data8 = data.lower_bound_percentile
const _errs20 = errors
- if (!(typeof data8 == 'number' && isFinite(data8))) {
- validate79.errors = [
- {
- instancePath:
- instancePath + '/lower_bound_percentile',
- schemaPath:
- '#/properties/lower_bound_percentile/type',
- keyword: 'type',
- params: { type: 'number' },
- message: 'must be number',
- },
- ]
- return false
+ if (errors === _errs20) {
+ if (typeof data8 == 'number' && isFinite(data8)) {
+ if (data8 > 1 || isNaN(data8)) {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/lower_bound_percentile',
+ schemaPath:
+ '#/properties/lower_bound_percentile/maximum',
+ keyword: 'maximum',
+ params: { comparison: '<=', limit: 1 },
+ message: 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (data8 < 0 || isNaN(data8)) {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/lower_bound_percentile',
+ schemaPath:
+ '#/properties/lower_bound_percentile/minimum',
+ keyword: 'minimum',
+ params: { comparison: '>=', limit: 0 },
+ message: 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath + '/lower_bound_percentile',
+ schemaPath:
+ '#/properties/lower_bound_percentile/type',
+ keyword: 'type',
+ params: { type: 'number' },
+ message: 'must be number',
+ },
+ ]
+ return false
+ }
}
var valid0 = _errs20 === errors
} else {
@@ -10100,25 +10146,77 @@ function validate79(data, { instancePath = '', parentData, parentDataProperty, r
) {
let data14 = data.upper_bound_percentile
const _errs31 = errors
- if (
- !(
+ if (errors === _errs31) {
+ if (
typeof data14 == 'number' &&
isFinite(data14)
- )
- ) {
- validate79.errors = [
- {
- instancePath:
- instancePath +
- '/upper_bound_percentile',
- schemaPath:
- '#/properties/upper_bound_percentile/type',
- keyword: 'type',
- params: { type: 'number' },
- message: 'must be number',
- },
- ]
- return false
+ ) {
+ if (
+ data14 > 1 ||
+ isNaN(data14)
+ ) {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/upper_bound_percentile',
+ schemaPath:
+ '#/properties/upper_bound_percentile/maximum',
+ keyword: 'maximum',
+ params: {
+ comparison:
+ '<=',
+ limit: 1,
+ },
+ message:
+ 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (
+ data14 < 0 ||
+ isNaN(data14)
+ ) {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/upper_bound_percentile',
+ schemaPath:
+ '#/properties/upper_bound_percentile/minimum',
+ keyword:
+ 'minimum',
+ params: {
+ comparison:
+ '>=',
+ limit: 0,
+ },
+ message:
+ 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate79.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/upper_bound_percentile',
+ schemaPath:
+ '#/properties/upper_bound_percentile/type',
+ keyword: 'type',
+ params: {
+ type: 'number',
+ },
+ message:
+ 'must be number',
+ },
+ ]
+ return false
+ }
}
var valid0 = _errs31 === errors
} else {
@@ -10848,6 +10946,7 @@ const schema102 = {
conversion_window: { $ref: '#/definitions/integer' },
conversion_window_unit: { $ref: '#/definitions/FunnelConversionWindowTimeUnit' },
denominator: { $ref: '#/definitions/ExperimentMetricSource' },
+ denominator_outlier_handling: { $ref: '#/definitions/ExperimentMetricOutlierHandling' },
fingerprint: { type: 'string' },
goal: { $ref: '#/definitions/ExperimentMetricGoal' },
isSharedMetric: { type: 'boolean' },
@@ -10855,6 +10954,7 @@ const schema102 = {
metric_type: { const: 'ratio', type: 'string' },
name: { type: 'string' },
numerator: { $ref: '#/definitions/ExperimentMetricSource' },
+ numerator_outlier_handling: { $ref: '#/definitions/ExperimentMetricOutlierHandling' },
response: { type: 'object' },
sharedMetricId: { type: 'number' },
uuid: { type: 'string' },
@@ -10863,6 +10963,27 @@ const schema102 = {
required: ['denominator', 'kind', 'metric_type', 'numerator'],
type: 'object',
}
+const schema105 = {
+ additionalProperties: false,
+ properties: {
+ ignore_zeros: { type: 'boolean' },
+ lower_bound_percentile: {
+ description:
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).',
+ maximum: 1,
+ minimum: 0,
+ type: 'number',
+ },
+ upper_bound_percentile: {
+ description:
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).',
+ maximum: 1,
+ minimum: 0,
+ type: 'number',
+ },
+ },
+ type: 'object',
+}
function validate115(data, { instancePath = '', parentData, parentDataProperty, rootData = data } = {}) {
let vErrors = null
let errors = 0
@@ -11001,33 +11122,210 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
var valid0 = true
}
if (valid0) {
- if (data.fingerprint !== undefined) {
+ if (data.denominator_outlier_handling !== undefined) {
+ let data4 = data.denominator_outlier_handling
const _errs10 = errors
- if (typeof data.fingerprint !== 'string') {
- validate115.errors = [
- {
- instancePath: instancePath + '/fingerprint',
- schemaPath: '#/properties/fingerprint/type',
- keyword: 'type',
- params: { type: 'string' },
- message: 'must be string',
- },
- ]
- return false
+ const _errs11 = errors
+ if (errors === _errs11) {
+ if (data4 && typeof data4 == 'object' && !Array.isArray(data4)) {
+ const _errs13 = errors
+ for (const key1 in data4) {
+ if (
+ !(
+ key1 === 'ignore_zeros' ||
+ key1 === 'lower_bound_percentile' ||
+ key1 === 'upper_bound_percentile'
+ )
+ ) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath + '/denominator_outlier_handling',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/additionalProperties',
+ keyword: 'additionalProperties',
+ params: { additionalProperty: key1 },
+ message: 'must NOT have additional properties',
+ },
+ ]
+ return false
+ break
+ }
+ }
+ if (_errs13 === errors) {
+ if (data4.ignore_zeros !== undefined) {
+ const _errs14 = errors
+ if (typeof data4.ignore_zeros !== 'boolean') {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/ignore_zeros',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/ignore_zeros/type',
+ keyword: 'type',
+ params: { type: 'boolean' },
+ message: 'must be boolean',
+ },
+ ]
+ return false
+ }
+ var valid4 = _errs14 === errors
+ } else {
+ var valid4 = true
+ }
+ if (valid4) {
+ if (data4.lower_bound_percentile !== undefined) {
+ let data6 = data4.lower_bound_percentile
+ const _errs16 = errors
+ if (errors === _errs16) {
+ if (typeof data6 == 'number' && isFinite(data6)) {
+ if (data6 > 1 || isNaN(data6)) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/maximum',
+ keyword: 'maximum',
+ params: { comparison: '<=', limit: 1 },
+ message: 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (data6 < 0 || isNaN(data6)) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/minimum',
+ keyword: 'minimum',
+ params: {
+ comparison: '>=',
+ limit: 0,
+ },
+ message: 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/type',
+ keyword: 'type',
+ params: { type: 'number' },
+ message: 'must be number',
+ },
+ ]
+ return false
+ }
+ }
+ var valid4 = _errs16 === errors
+ } else {
+ var valid4 = true
+ }
+ if (valid4) {
+ if (data4.upper_bound_percentile !== undefined) {
+ let data7 = data4.upper_bound_percentile
+ const _errs18 = errors
+ if (errors === _errs18) {
+ if (typeof data7 == 'number' && isFinite(data7)) {
+ if (data7 > 1 || isNaN(data7)) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/maximum',
+ keyword: 'maximum',
+ params: {
+ comparison: '<=',
+ limit: 1,
+ },
+ message: 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (data7 < 0 || isNaN(data7)) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/minimum',
+ keyword: 'minimum',
+ params: {
+ comparison: '>=',
+ limit: 0,
+ },
+ message: 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/denominator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/type',
+ keyword: 'type',
+ params: { type: 'number' },
+ message: 'must be number',
+ },
+ ]
+ return false
+ }
+ }
+ var valid4 = _errs18 === errors
+ } else {
+ var valid4 = true
+ }
+ }
+ }
+ }
+ } else {
+ validate115.errors = [
+ {
+ instancePath: instancePath + '/denominator_outlier_handling',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/type',
+ keyword: 'type',
+ params: { type: 'object' },
+ message: 'must be object',
+ },
+ ]
+ return false
+ }
}
var valid0 = _errs10 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.goal !== undefined) {
- let data5 = data.goal
- const _errs12 = errors
- if (typeof data5 !== 'string') {
+ if (data.fingerprint !== undefined) {
+ const _errs20 = errors
+ if (typeof data.fingerprint !== 'string') {
validate115.errors = [
{
- instancePath: instancePath + '/goal',
- schemaPath: '#/definitions/ExperimentMetricGoal/type',
+ instancePath: instancePath + '/fingerprint',
+ schemaPath: '#/properties/fingerprint/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -11035,82 +11333,70 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
]
return false
}
- if (!(data5 === 'increase' || data5 === 'decrease')) {
- validate115.errors = [
- {
- instancePath: instancePath + '/goal',
- schemaPath: '#/definitions/ExperimentMetricGoal/enum',
- keyword: 'enum',
- params: { allowedValues: schema78.enum },
- message: 'must be equal to one of the allowed values',
- },
- ]
- return false
- }
- var valid0 = _errs12 === errors
+ var valid0 = _errs20 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.isSharedMetric !== undefined) {
- const _errs15 = errors
- if (typeof data.isSharedMetric !== 'boolean') {
+ if (data.goal !== undefined) {
+ let data9 = data.goal
+ const _errs22 = errors
+ if (typeof data9 !== 'string') {
validate115.errors = [
{
- instancePath: instancePath + '/isSharedMetric',
- schemaPath: '#/properties/isSharedMetric/type',
+ instancePath: instancePath + '/goal',
+ schemaPath: '#/definitions/ExperimentMetricGoal/type',
keyword: 'type',
- params: { type: 'boolean' },
- message: 'must be boolean',
- },
+ params: { type: 'string' },
+ message: 'must be string',
+ },
]
return false
}
- var valid0 = _errs15 === errors
+ if (!(data9 === 'increase' || data9 === 'decrease')) {
+ validate115.errors = [
+ {
+ instancePath: instancePath + '/goal',
+ schemaPath: '#/definitions/ExperimentMetricGoal/enum',
+ keyword: 'enum',
+ params: { allowedValues: schema78.enum },
+ message: 'must be equal to one of the allowed values',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs22 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.kind !== undefined) {
- let data7 = data.kind
- const _errs17 = errors
- if (typeof data7 !== 'string') {
+ if (data.isSharedMetric !== undefined) {
+ const _errs25 = errors
+ if (typeof data.isSharedMetric !== 'boolean') {
validate115.errors = [
{
- instancePath: instancePath + '/kind',
- schemaPath: '#/properties/kind/type',
+ instancePath: instancePath + '/isSharedMetric',
+ schemaPath: '#/properties/isSharedMetric/type',
keyword: 'type',
- params: { type: 'string' },
- message: 'must be string',
+ params: { type: 'boolean' },
+ message: 'must be boolean',
},
]
return false
}
- if ('ExperimentMetric' !== data7) {
- validate115.errors = [
- {
- instancePath: instancePath + '/kind',
- schemaPath: '#/properties/kind/const',
- keyword: 'const',
- params: { allowedValue: 'ExperimentMetric' },
- message: 'must be equal to constant',
- },
- ]
- return false
- }
- var valid0 = _errs17 === errors
+ var valid0 = _errs25 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.metric_type !== undefined) {
- let data8 = data.metric_type
- const _errs19 = errors
- if (typeof data8 !== 'string') {
+ if (data.kind !== undefined) {
+ let data11 = data.kind
+ const _errs27 = errors
+ if (typeof data11 !== 'string') {
validate115.errors = [
{
- instancePath: instancePath + '/metric_type',
- schemaPath: '#/properties/metric_type/type',
+ instancePath: instancePath + '/kind',
+ schemaPath: '#/properties/kind/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -11118,30 +11404,31 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
]
return false
}
- if ('ratio' !== data8) {
+ if ('ExperimentMetric' !== data11) {
validate115.errors = [
{
- instancePath: instancePath + '/metric_type',
- schemaPath: '#/properties/metric_type/const',
+ instancePath: instancePath + '/kind',
+ schemaPath: '#/properties/kind/const',
keyword: 'const',
- params: { allowedValue: 'ratio' },
+ params: { allowedValue: 'ExperimentMetric' },
message: 'must be equal to constant',
},
]
return false
}
- var valid0 = _errs19 === errors
+ var valid0 = _errs27 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.name !== undefined) {
- const _errs21 = errors
- if (typeof data.name !== 'string') {
+ if (data.metric_type !== undefined) {
+ let data12 = data.metric_type
+ const _errs29 = errors
+ if (typeof data12 !== 'string') {
validate115.errors = [
{
- instancePath: instancePath + '/name',
- schemaPath: '#/properties/name/type',
+ instancePath: instancePath + '/metric_type',
+ schemaPath: '#/properties/metric_type/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -11149,125 +11436,397 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
]
return false
}
- var valid0 = _errs21 === errors
+ if ('ratio' !== data12) {
+ validate115.errors = [
+ {
+ instancePath: instancePath + '/metric_type',
+ schemaPath: '#/properties/metric_type/const',
+ keyword: 'const',
+ params: { allowedValue: 'ratio' },
+ message: 'must be equal to constant',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs29 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.numerator !== undefined) {
- const _errs23 = errors
- if (
- !validate84(data.numerator, {
- instancePath: instancePath + '/numerator',
- parentData: data,
- parentDataProperty: 'numerator',
- rootData,
- })
- ) {
- vErrors =
- vErrors === null
- ? validate84.errors
- : vErrors.concat(validate84.errors)
- errors = vErrors.length
+ if (data.name !== undefined) {
+ const _errs31 = errors
+ if (typeof data.name !== 'string') {
+ validate115.errors = [
+ {
+ instancePath: instancePath + '/name',
+ schemaPath: '#/properties/name/type',
+ keyword: 'type',
+ params: { type: 'string' },
+ message: 'must be string',
+ },
+ ]
+ return false
}
- var valid0 = _errs23 === errors
+ var valid0 = _errs31 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.response !== undefined) {
- let data11 = data.response
- const _errs24 = errors
+ if (data.numerator !== undefined) {
+ const _errs33 = errors
if (
- !(
- data11 &&
- typeof data11 == 'object' &&
- !Array.isArray(data11)
- )
+ !validate84(data.numerator, {
+ instancePath: instancePath + '/numerator',
+ parentData: data,
+ parentDataProperty: 'numerator',
+ rootData,
+ })
) {
- validate115.errors = [
- {
- instancePath:
- instancePath + '/response',
- schemaPath:
- '#/properties/response/type',
- keyword: 'type',
- params: { type: 'object' },
- message: 'must be object',
- },
- ]
- return false
+ vErrors =
+ vErrors === null
+ ? validate84.errors
+ : vErrors.concat(validate84.errors)
+ errors = vErrors.length
}
- var valid0 = _errs24 === errors
+ var valid0 = _errs33 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.sharedMetricId !== undefined) {
- let data12 = data.sharedMetricId
- const _errs26 = errors
- if (
- !(
- typeof data12 == 'number' &&
- isFinite(data12)
- )
- ) {
- validate115.errors = [
- {
- instancePath:
- instancePath +
- '/sharedMetricId',
- schemaPath:
- '#/properties/sharedMetricId/type',
- keyword: 'type',
- params: { type: 'number' },
- message: 'must be number',
- },
- ]
- return false
+ if (data.numerator_outlier_handling !== undefined) {
+ let data15 = data.numerator_outlier_handling
+ const _errs34 = errors
+ const _errs35 = errors
+ if (errors === _errs35) {
+ if (
+ data15 &&
+ typeof data15 == 'object' &&
+ !Array.isArray(data15)
+ ) {
+ const _errs37 = errors
+ for (const key2 in data15) {
+ if (
+ !(
+ key2 === 'ignore_zeros' ||
+ key2 ===
+ 'lower_bound_percentile' ||
+ key2 ===
+ 'upper_bound_percentile'
+ )
+ ) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/additionalProperties',
+ keyword:
+ 'additionalProperties',
+ params: {
+ additionalProperty:
+ key2,
+ },
+ message:
+ 'must NOT have additional properties',
+ },
+ ]
+ return false
+ break
+ }
+ }
+ if (_errs37 === errors) {
+ if (
+ data15.ignore_zeros !==
+ undefined
+ ) {
+ const _errs38 = errors
+ if (
+ typeof data15.ignore_zeros !==
+ 'boolean'
+ ) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/ignore_zeros',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/ignore_zeros/type',
+ keyword: 'type',
+ params: {
+ type: 'boolean',
+ },
+ message:
+ 'must be boolean',
+ },
+ ]
+ return false
+ }
+ var valid7 = _errs38 === errors
+ } else {
+ var valid7 = true
+ }
+ if (valid7) {
+ if (
+ data15.lower_bound_percentile !==
+ undefined
+ ) {
+ let data17 =
+ data15.lower_bound_percentile
+ const _errs40 = errors
+ if (errors === _errs40) {
+ if (
+ typeof data17 ==
+ 'number' &&
+ isFinite(data17)
+ ) {
+ if (
+ data17 > 1 ||
+ isNaN(data17)
+ ) {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/maximum',
+ keyword:
+ 'maximum',
+ params: {
+ comparison:
+ '<=',
+ limit: 1,
+ },
+ message:
+ 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (
+ data17 <
+ 0 ||
+ isNaN(
+ data17
+ )
+ ) {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/minimum',
+ keyword:
+ 'minimum',
+ params: {
+ comparison:
+ '>=',
+ limit: 0,
+ },
+ message:
+ 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/lower_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/lower_bound_percentile/type',
+ keyword:
+ 'type',
+ params: {
+ type: 'number',
+ },
+ message:
+ 'must be number',
+ },
+ ]
+ return false
+ }
+ }
+ var valid7 =
+ _errs40 === errors
+ } else {
+ var valid7 = true
+ }
+ if (valid7) {
+ if (
+ data15.upper_bound_percentile !==
+ undefined
+ ) {
+ let data18 =
+ data15.upper_bound_percentile
+ const _errs42 = errors
+ if (
+ errors === _errs42
+ ) {
+ if (
+ typeof data18 ==
+ 'number' &&
+ isFinite(data18)
+ ) {
+ if (
+ data18 >
+ 1 ||
+ isNaN(
+ data18
+ )
+ ) {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/maximum',
+ keyword:
+ 'maximum',
+ params: {
+ comparison:
+ '<=',
+ limit: 1,
+ },
+ message:
+ 'must be <= 1',
+ },
+ ]
+ return false
+ } else {
+ if (
+ data18 <
+ 0 ||
+ isNaN(
+ data18
+ )
+ ) {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/minimum',
+ keyword:
+ 'minimum',
+ params: {
+ comparison:
+ '>=',
+ limit: 0,
+ },
+ message:
+ 'must be >= 0',
+ },
+ ]
+ return false
+ }
+ }
+ } else {
+ validate115.errors =
+ [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling/upper_bound_percentile',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/properties/upper_bound_percentile/type',
+ keyword:
+ 'type',
+ params: {
+ type: 'number',
+ },
+ message:
+ 'must be number',
+ },
+ ]
+ return false
+ }
+ }
+ var valid7 =
+ _errs42 === errors
+ } else {
+ var valid7 = true
+ }
+ }
+ }
+ }
+ } else {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/numerator_outlier_handling',
+ schemaPath:
+ '#/definitions/ExperimentMetricOutlierHandling/type',
+ keyword: 'type',
+ params: { type: 'object' },
+ message: 'must be object',
+ },
+ ]
+ return false
+ }
}
- var valid0 = _errs26 === errors
+ var valid0 = _errs34 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.uuid !== undefined) {
- const _errs28 = errors
- if (typeof data.uuid !== 'string') {
+ if (data.response !== undefined) {
+ let data19 = data.response
+ const _errs44 = errors
+ if (
+ !(
+ data19 &&
+ typeof data19 == 'object' &&
+ !Array.isArray(data19)
+ )
+ ) {
validate115.errors = [
{
instancePath:
- instancePath + '/uuid',
+ instancePath + '/response',
schemaPath:
- '#/properties/uuid/type',
+ '#/properties/response/type',
keyword: 'type',
- params: { type: 'string' },
- message: 'must be string',
+ params: { type: 'object' },
+ message: 'must be object',
},
]
return false
}
- var valid0 = _errs28 === errors
+ var valid0 = _errs44 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.version !== undefined) {
- let data14 = data.version
- const _errs30 = errors
+ if (data.sharedMetricId !== undefined) {
+ let data20 = data.sharedMetricId
+ const _errs46 = errors
if (
!(
- typeof data14 == 'number' &&
- isFinite(data14)
+ typeof data20 == 'number' &&
+ isFinite(data20)
)
) {
validate115.errors = [
{
instancePath:
instancePath +
- '/version',
+ '/sharedMetricId',
schemaPath:
- '#/properties/version/type',
+ '#/properties/sharedMetricId/type',
keyword: 'type',
params: { type: 'number' },
message: 'must be number',
@@ -11275,10 +11834,69 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
]
return false
}
- var valid0 = _errs30 === errors
+ var valid0 = _errs46 === errors
} else {
var valid0 = true
}
+ if (valid0) {
+ if (data.uuid !== undefined) {
+ const _errs48 = errors
+ if (typeof data.uuid !== 'string') {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/uuid',
+ schemaPath:
+ '#/properties/uuid/type',
+ keyword: 'type',
+ params: {
+ type: 'string',
+ },
+ message:
+ 'must be string',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs48 === errors
+ } else {
+ var valid0 = true
+ }
+ if (valid0) {
+ if (data.version !== undefined) {
+ let data22 = data.version
+ const _errs50 = errors
+ if (
+ !(
+ typeof data22 ==
+ 'number' &&
+ isFinite(data22)
+ )
+ ) {
+ validate115.errors = [
+ {
+ instancePath:
+ instancePath +
+ '/version',
+ schemaPath:
+ '#/properties/version/type',
+ keyword: 'type',
+ params: {
+ type: 'number',
+ },
+ message:
+ 'must be number',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs50 === errors
+ } else {
+ var valid0 = true
+ }
+ }
+ }
}
}
}
@@ -11311,7 +11929,7 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,
validate115.errors = vErrors
return errors === 0
}
-const schema106 = {
+const schema108 = {
additionalProperties: false,
properties: {
breakdownFilter: { $ref: '#/definitions/BreakdownFilter' },
@@ -11375,7 +11993,7 @@ function validate120(data, { instancePath = '', parentData, parentDataProperty,
} else {
const _errs1 = errors
for (const key0 in data) {
- if (!func2.call(schema106.properties, key0)) {
+ if (!func2.call(schema108.properties, key0)) {
validate120.errors = [
{
instancePath,
@@ -11874,7 +12492,7 @@ function validate120(data, { instancePath = '', parentData, parentDataProperty,
keyword: 'enum',
params: {
allowedValues:
- schema106
+ schema108
.properties
.start_handling
.enum,
diff --git a/frontend/src/scenes/experiments/ExperimentForm/MetricsPanel/MetricOutlierHandling.tsx b/frontend/src/scenes/experiments/ExperimentForm/MetricsPanel/MetricOutlierHandling.tsx
index 4a107450c11c..826b43fb15ad 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/MetricsPanel/MetricOutlierHandling.tsx
+++ b/frontend/src/scenes/experiments/ExperimentForm/MetricsPanel/MetricOutlierHandling.tsx
@@ -1,29 +1,66 @@
-import type { ExperimentMetric } from '~/queries/schema/schema-general'
-import { isExperimentMeanMetric } from '~/queries/schema/schema-general'
+import type {
+ ExperimentMetric,
+ ExperimentMetricOutlierHandling as OutlierHandlingConfig,
+} from '~/queries/schema/schema-general'
+import { isExperimentMeanMetric, isExperimentRatioMetric } from '~/queries/schema/schema-general'
-/**
- * Only for mean metrics
- */
export type MetricOutlierHandlingProps = {
metric: ExperimentMetric
}
-export const MetricOutlierHandling = ({ metric }: MetricOutlierHandlingProps): JSX.Element | null => {
- if (!isExperimentMeanMetric(metric)) {
+// Percentiles are stored as fractions (0.05, 0.95); display them in percent units.
+const toPercent = (fraction: number): number => Math.round(fraction * 100 * 100) / 100
+
+const formatBounds = (config: OutlierHandlingConfig | undefined): string | null => {
+ const hasLower = config?.lower_bound_percentile != null
+ const hasUpper = config?.upper_bound_percentile != null
+ if (!hasLower && !hasUpper) {
return null
}
+ return [
+ hasLower ? `Lower ${toPercent(config!.lower_bound_percentile!)}%` : null,
+ hasUpper ? `Upper ${toPercent(config!.upper_bound_percentile!)}%` : null,
+ ]
+ .filter(Boolean)
+ .join(', ')
+}
- const hasLower = metric.lower_bound_percentile != null
- const hasUpper = metric.upper_bound_percentile != null
+export const MetricOutlierHandling = ({ metric }: MetricOutlierHandlingProps): JSX.Element | null => {
+ if (isExperimentMeanMetric(metric)) {
+ const bounds = formatBounds({
+ lower_bound_percentile: metric.lower_bound_percentile,
+ upper_bound_percentile: metric.upper_bound_percentile,
+ })
+ if (!bounds) {
+ return null
+ }
+ return (
+ <div className="text-xs">
+ <span className="text-muted">Outlier handling:</span> <span className="font-semibold">{bounds}</span>
+ </div>
+ )
+ }
+
+ if (isExperimentRatioMetric(metric)) {
+ const numeratorBounds = formatBounds(metric.numerator_outlier_handling)
+ const denominatorBounds = formatBounds(metric.denominator_outlier_handling)
+ if (!numeratorBounds && !denominatorBounds) {
+ return null
+ }
+ return (
+ <div className="text-xs">
+ <span className="text-muted">Outlier handling:</span>{' '}
+ <span className="font-semibold">
+ {[
+ numeratorBounds ? `Numerator ${numeratorBounds}` : null,
+ denominatorBounds ? `Denominator ${denominatorBounds}` : null,
+ ]
+ .filter(Boolean)
+ .join(' · ')}
+ </span>
+ </div>
+ )
+ }
- return (
- <div className="text-xs">
- <span className="text-muted">Outlier handling:</span>{' '}
- <span className="font-semibold">
- {hasLower && `Lower ${metric.lower_bound_percentile}%`}
- {hasLower && hasUpper && ', '}
- {hasUpper && `Upper ${metric.upper_bound_percentile}%`}
- </span>
- </div>
- )
+ return null
}
diff --git a/frontend/src/scenes/experiments/ExperimentMetricForm.tsx b/frontend/src/scenes/experiments/ExperimentMetricForm.tsx
index 02a922fd0f39..be5729e8b795 100644
--- a/frontend/src/scenes/experiments/ExperimentMetricForm.tsx
+++ b/frontend/src/scenes/experiments/ExperimentMetricForm.tsx
@@ -37,7 +37,10 @@ import { ExperimentMetricGoal, ExperimentMetricMathType, FilterType, FunnelConve
import { ExperimentMetricConversionWindowFilter } from './ExperimentMetricConversionWindowFilter'
import { ExperimentMetricFunnelOrderSelector } from './ExperimentMetricFunnelOrderSelector'
-import { ExperimentMetricOutlierHandling } from './ExperimentMetricOutlierHandling'
+import {
+ ExperimentMetricOutlierHandling,
+ ExperimentRatioMetricOutlierHandling,
+} from './ExperimentMetricOutlierHandling'
import { filterToMetricConfig, filterToMetricSource } from './metricQueryUtils'
import { createFilterForSource, getFilter } from './metricQueryUtils'
import { commonActionFilterProps } from './Metrics/Selectors'
@@ -652,6 +655,12 @@ export function ExperimentMetricForm({
<SceneDivider />
</>
)}
+ {isExperimentRatioMetric(metric) && (
+ <>
+ <ExperimentRatioMetricOutlierHandling metric={metric} handleSetMetric={handleSetMetric} />
+ <SceneDivider />
+ </>
+ )}
<SceneSection
title="Recent activity"
className="max-w-prose"
diff --git a/frontend/src/scenes/experiments/ExperimentMetricOutlierHandling.tsx b/frontend/src/scenes/experiments/ExperimentMetricOutlierHandling.tsx
index 8d8837c76af9..02a514122d90 100644
--- a/frontend/src/scenes/experiments/ExperimentMetricOutlierHandling.tsx
+++ b/frontend/src/scenes/experiments/ExperimentMetricOutlierHandling.tsx
@@ -1,9 +1,90 @@
import { LemonCheckbox, Tooltip } from '@posthog/lemon-ui'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
+import { LemonLabel } from 'lib/lemon-ui/LemonLabel'
import { SceneSection } from '~/layout/scenes/components/SceneSection'
-import { ExperimentMeanMetric, ExperimentMetric } from '~/queries/schema/schema-general'
+import {
+ ExperimentMeanMetric,
+ ExperimentMetric,
+ ExperimentMetricOutlierHandling as ExperimentMetricOutlierHandlingConfig,
+ ExperimentRatioMetric,
+} from '~/queries/schema/schema-general'
+
+const DESCRIPTION = 'Set winsorization lower and upper bounds to cap metric values at the specified percentiles.'
+
+function OutlierHandlingControls({
+ value,
+ onChange,
+}: {
+ value: ExperimentMetricOutlierHandlingConfig
+ onChange: (next: ExperimentMetricOutlierHandlingConfig) => void
+}): JSX.Element {
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center gap-2">
+ <LemonCheckbox
+ label="Lower bound percentile"
+ checked={value.lower_bound_percentile !== undefined}
+ onChange={(checked) => onChange({ ...value, lower_bound_percentile: checked ? 0.05 : undefined })}
+ />
+ <LemonInput
+ value={value.lower_bound_percentile !== undefined ? value.lower_bound_percentile * 100 : 0}
+ onChange={(newValue) =>
+ value.lower_bound_percentile !== undefined &&
+ onChange({ ...value, lower_bound_percentile: (newValue ?? 0) / 100 })
+ }
+ type="number"
+ step={1}
+ suffix={<span className="text-sm">%</span>}
+ size="small"
+ className={`w-20 transition-opacity ${
+ value.lower_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
+ }`}
+ />
+ </div>
+ <div className="flex items-center gap-2">
+ <LemonCheckbox
+ label="Upper bound percentile"
+ checked={value.upper_bound_percentile !== undefined}
+ onChange={(checked) => onChange({ ...value, upper_bound_percentile: checked ? 0.95 : undefined })}
+ />
+ <LemonInput
+ value={value.upper_bound_percentile !== undefined ? value.upper_bound_percentile * 100 : 0}
+ onChange={(newValue) =>
+ value.upper_bound_percentile !== undefined &&
+ onChange({ ...value, upper_bound_percentile: (newValue ?? 0) / 100 })
+ }
+ type="number"
+ step={1}
+ suffix={<span className="text-sm">%</span>}
+ size="small"
+ className={`w-20 transition-opacity ${
+ value.upper_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
+ }`}
+ />
+ <div
+ className={`text-xs transition-opacity ${
+ value.upper_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
+ }`}
+ >
+ <Tooltip
+ title="Useful if a large number of participants in the experiment does not have the event resulting in a 0 value."
+ docLink="https://posthog.com/docs/experiments/metrics#outlier-handling"
+ >
+ <span>
+ <LemonCheckbox
+ label="Ignore zeros when calculating upper bound"
+ checked={value.ignore_zeros ?? false}
+ onChange={(checked) => onChange({ ...value, ignore_zeros: checked })}
+ />
+ </span>
+ </Tooltip>
+ </div>
+ </div>
+ </div>
+ )
+}
export function ExperimentMetricOutlierHandling({
metric,
@@ -16,76 +97,67 @@ export function ExperimentMetricOutlierHandling({
<SceneSection
title="Outlier handling"
titleHelper={<>Prevent outliers from skewing results by capping the lower and upper bounds of a metric.</>}
- description={
- <p className="text-muted text-xs -mb-1">
- Set winsorization lower and upper bounds to cap metric values at the specified percentiles.
- </p>
+ description={<p className="text-muted text-xs -mb-1">{DESCRIPTION}</p>}
+ >
+ <OutlierHandlingControls
+ value={{
+ lower_bound_percentile: metric.lower_bound_percentile,
+ upper_bound_percentile: metric.upper_bound_percentile,
+ ignore_zeros: metric.ignore_zeros,
+ }}
+ onChange={(next) => handleSetMetric({ ...metric, ...next })}
+ />
+ </SceneSection>
+ )
+}
+
+// When no bounds are set, drop the whole config so the metric stays clean (and its
+// fingerprint unchanged). ignore_zeros only matters alongside an upper bound.
+function normalizeOutlierHandling(
+ config: ExperimentMetricOutlierHandlingConfig
+): ExperimentMetricOutlierHandlingConfig | undefined {
+ if (config.lower_bound_percentile === undefined && config.upper_bound_percentile === undefined) {
+ return undefined
+ }
+ return config
+}
+
+export function ExperimentRatioMetricOutlierHandling({
+ metric,
+ handleSetMetric,
+}: {
+ metric: ExperimentRatioMetric
+ handleSetMetric: (newMetric: ExperimentMetric) => void
+}): JSX.Element {
+ return (
+ <SceneSection
+ title="Outlier handling"
+ titleHelper={
+ <>
+ Prevent outliers from skewing results by capping the numerator and denominator independently. There
+ is no per-user ratio to cap, so each component is winsorized on its own.
+ </>
}
+ description={<p className="text-muted text-xs -mb-1">{DESCRIPTION}</p>}
>
- <div className="flex flex-col gap-2">
- <div className="flex items-center gap-2">
- <LemonCheckbox
- label="Lower bound percentile"
- checked={metric.lower_bound_percentile !== undefined}
- onChange={(checked) =>
- handleSetMetric({ ...metric, lower_bound_percentile: checked ? 0.05 : undefined })
- }
- />
- <LemonInput
- value={metric.lower_bound_percentile !== undefined ? metric.lower_bound_percentile * 100 : 0}
- onChange={(value) =>
- metric.lower_bound_percentile !== undefined &&
- handleSetMetric({ ...metric, lower_bound_percentile: (value ?? 0) / 100 })
+ <div className="flex flex-col gap-4">
+ <div className="flex flex-col gap-2">
+ <LemonLabel>Numerator</LemonLabel>
+ <OutlierHandlingControls
+ value={metric.numerator_outlier_handling ?? {}}
+ onChange={(next) =>
+ handleSetMetric({ ...metric, numerator_outlier_handling: normalizeOutlierHandling(next) })
}
- type="number"
- step={1}
- suffix={<span className="text-sm">%</span>}
- size="small"
- className={`w-20 transition-opacity ${
- metric.lower_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
- }`}
/>
</div>
- <div className="flex items-center gap-2">
- <LemonCheckbox
- label="Upper bound percentile"
- checked={metric.upper_bound_percentile !== undefined}
- onChange={(checked) =>
- handleSetMetric({ ...metric, upper_bound_percentile: checked ? 0.95 : undefined })
+ <div className="flex flex-col gap-2">
+ <LemonLabel>Denominator</LemonLabel>
+ <OutlierHandlingControls
+ value={metric.denominator_outlier_handling ?? {}}
+ onChange={(next) =>
+ handleSetMetric({ ...metric, denominator_outlier_handling: normalizeOutlierHandling(next) })
}
/>
- <LemonInput
- value={metric.upper_bound_percentile !== undefined ? metric.upper_bound_percentile * 100 : 0}
- onChange={(value) =>
- metric.upper_bound_percentile !== undefined &&
- handleSetMetric({ ...metric, upper_bound_percentile: (value ?? 0) / 100 })
- }
- type="number"
- step={1}
- suffix={<span className="text-sm">%</span>}
- size="small"
- className={`w-20 transition-opacity ${
- metric.upper_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
- }`}
- />
- <div
- className={`text-xs transition-opacity ${
- metric.upper_bound_percentile === undefined ? 'opacity-0 invisible' : 'opacity-100 visible'
- }`}
- >
- <Tooltip
- title="Useful if a large number of participants in the experiment does not have the event resulting in a 0 value."
- docLink="https://posthog.com/docs/experiments/metrics#outlier-handling"
- >
- <span>
- <LemonCheckbox
- label="Ignore zeros when calculating upper bound"
- checked={metric.ignore_zeros ?? false}
- onChange={(checked) => handleSetMetric({ ...metric, ignore_zeros: checked })}
- />
- </span>
- </Tooltip>
- </div>
</div>
</div>
</SceneSection>
diff --git a/frontend/src/scenes/experiments/activity-descriptions/metricChangeDescriptions.tsx b/frontend/src/scenes/experiments/activity-descriptions/metricChangeDescriptions.tsx
index 338e4daf6d2b..79109b74f3b4 100644
--- a/frontend/src/scenes/experiments/activity-descriptions/metricChangeDescriptions.tsx
+++ b/frontend/src/scenes/experiments/activity-descriptions/metricChangeDescriptions.tsx
@@ -95,6 +95,14 @@ const getRatioChanges = (metricBefore: ExperimentMetric, metricAfter: Experiment
return `changed the denominator`
}
+ // check if outlier handling was changed for either component
+ if (!equal(metricBefore.numerator_outlier_handling, metricAfter.numerator_outlier_handling)) {
+ return `changed the numerator outlier handling`
+ }
+ if (!equal(metricBefore.denominator_outlier_handling, metricAfter.denominator_outlier_handling)) {
+ return `changed the denominator outlier handling`
+ }
+
return null
}
export const getMetricChanges = (
diff --git a/posthog/hogql_queries/experiments/breakdown_injector.py b/posthog/hogql_queries/experiments/breakdown_injector.py
index b872ddc107da..7e99d393209a 100644
--- a/posthog/hogql_queries/experiments/breakdown_injector.py
+++ b/posthog/hogql_queries/experiments/breakdown_injector.py
@@ -333,20 +333,26 @@ class BreakdownInjector:
for alias in aliases:
query.group_by.append(ast.Field(chain=[final_cte_name, alias]))
- def inject_ratio_breakdown_columns(self, query: ast.SelectQuery) -> None:
+ def inject_ratio_breakdown_columns(self, query: ast.SelectQuery, winsorized: bool = False) -> None:
"""
Injects breakdown columns into ratio query AST.
Modifies query in-place.
- With the combined_events structure, breakdowns are simpler:
+ With the pre-aggregation structure, breakdowns are simpler:
- Breakdowns are attributed from exposures (not from numerator/denominator events)
- entity_metrics gets breakdown columns directly from exposures
- - No need for breakdown join conditions since there's only one join to combined_events
+ - No need for breakdown join conditions on the event joins
+
+ When ``winsorized`` is set the query has extra ``percentiles`` and
+ ``winsorized_entity_metrics`` CTEs: percentiles are computed per breakdown group
+ (so each group is capped at its own threshold, pooled across variations) and the
+ final aggregation reads from ``winsorized_entity_metrics``.
"""
if not self._has_breakdown():
return
aliases = self._get_breakdown_aliases()
+ final_cte_name = "winsorized_entity_metrics" if winsorized else "entity_metrics"
# Inject into entity_metrics CTE SELECT and GROUP BY (from exposures)
if query.ctes and "entity_metrics" in query.ctes:
@@ -361,18 +367,64 @@ class BreakdownInjector:
for alias in aliases:
entity_metrics_cte.expr.group_by.append(ast.Field(chain=["exposures", alias]))
+ # Inject into percentiles CTE (only for winsorization queries) so each breakdown
+ # group gets its own thresholds, pooled across variations.
+ if winsorized and query.ctes and "percentiles" in query.ctes:
+ percentiles_cte = query.ctes["percentiles"]
+ if isinstance(percentiles_cte, ast.CTE) and isinstance(percentiles_cte.expr, ast.SelectQuery):
+ for alias in aliases:
+ percentiles_cte.expr.select.append(
+ ast.Alias(alias=alias, expr=ast.Field(chain=["entity_metrics", alias]))
+ )
+ if percentiles_cte.expr.group_by is None:
+ percentiles_cte.expr.group_by = []
+ for alias in aliases:
+ percentiles_cte.expr.group_by.append(ast.Field(chain=["entity_metrics", alias]))
+
+ # Inject into winsorized_entity_metrics CTE: add breakdown columns and convert the
+ # CROSS JOIN to percentiles into a per-breakdown JOIN.
+ if winsorized and query.ctes and "winsorized_entity_metrics" in query.ctes:
+ winsorized_cte = query.ctes["winsorized_entity_metrics"]
+ if isinstance(winsorized_cte, ast.CTE) and isinstance(winsorized_cte.expr, ast.SelectQuery):
+ for alias in aliases:
+ winsorized_cte.expr.select.append(
+ ast.Alias(alias=alias, expr=ast.Field(chain=["entity_metrics", alias]))
+ )
+ if winsorized_cte.expr.select_from:
+ join_expr = winsorized_cte.expr.select_from.next_join
+ if join_expr and isinstance(join_expr, ast.JoinExpr):
+ join_expr.join_type = "JOIN"
+ join_conditions: list[ast.Expr] = []
+ for alias in aliases:
+ join_conditions.append(
+ ast.CompareOperation(
+ op=ast.CompareOperationOp.Eq,
+ left=ast.Field(chain=["percentiles", alias]),
+ right=ast.Field(chain=["entity_metrics", alias]),
+ )
+ )
+ condition_expr: ast.Expr
+ if len(join_conditions) == 1:
+ condition_expr = join_conditions[0]
+ else:
+ combined: ast.Expr = join_conditions[0]
+ for condition in join_conditions[1:]:
+ combined = ast.And(exprs=[combined, condition])
+ condition_expr = combined
+ join_expr.constraint = ast.JoinConstraint(expr=condition_expr, constraint_type="ON")
+
# Inject into final SELECT - breakdown columns must come right after variant
for i, alias in enumerate(aliases):
query.select.insert(
1 + i, # Position after variant column (index 0)
- ast.Alias(alias=alias, expr=ast.Field(chain=["entity_metrics", alias])),
+ ast.Alias(alias=alias, expr=ast.Field(chain=[final_cte_name, alias])),
)
# Inject into final GROUP BY
if query.group_by is None:
query.group_by = []
for alias in aliases:
- query.group_by.append(ast.Field(chain=["entity_metrics", alias]))
+ query.group_by.append(ast.Field(chain=[final_cte_name, alias]))
def inject_retention_breakdown_columns(self, query: ast.SelectQuery) -> None:
"""
diff --git a/posthog/hogql_queries/experiments/experiment_query_builder.py b/posthog/hogql_queries/experiments/experiment_query_builder.py
index 563049cf5edd..fefba8cfd106 100644
--- a/posthog/hogql_queries/experiments/experiment_query_builder.py
+++ b/posthog/hogql_queries/experiments/experiment_query_builder.py
@@ -12,6 +12,7 @@ from posthog.schema import (
ExperimentFunnelMetric,
ExperimentMeanMetric,
ExperimentMetricMathType,
+ ExperimentMetricOutlierHandling,
ExperimentRatioMetric,
ExperimentRetentionMetric,
FunnelConversionWindowTimeUnit,
@@ -1160,16 +1161,192 @@ class ExperimentQueryBuilder:
"""
Builds query for ratio metrics.
- Optimized structure using combined_events to reduce join operations:
+ Dispatches to the winsorized variant when outlier handling is configured for
+ either the numerator or the denominator.
+ """
+ assert isinstance(self.metric, ExperimentRatioMetric)
+
+ if self._ratio_needs_winsorization():
+ return self._build_ratio_query_with_winsorization()
+
+ common_ctes, placeholders = self._get_ratio_query_common()
+
+ query = parse_select(
+ f"""
+ WITH {common_ctes}
+
+ SELECT
+ entity_metrics.variant AS variant,
+ count(entity_metrics.entity_id) AS num_users,
+ sum(entity_metrics.numerator_value) AS total_sum,
+ sum(power(entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(entity_metrics.numerator_value * entity_metrics.denominator_value) AS numerator_denominator_sum_product
+ -- breakdown columns added programmatically below
+ FROM entity_metrics
+ GROUP BY entity_metrics.variant
+ -- breakdown columns added programmatically below
+ """,
+ placeholders=placeholders,
+ )
+
+ assert isinstance(query, ast.SelectQuery)
+
+ # Inject breakdown columns into the query AST
+ if self.breakdown_injector:
+ self.breakdown_injector.inject_ratio_breakdown_columns(query)
+
+ return query
+
+ def _ratio_needs_winsorization(self) -> bool:
+ """Whether either component of a ratio metric has outlier handling configured."""
+ assert isinstance(self.metric, ExperimentRatioMetric)
+ for outlier_handling in (
+ self.metric.numerator_outlier_handling,
+ self.metric.denominator_outlier_handling,
+ ):
+ if outlier_handling is not None and (
+ outlier_handling.lower_bound_percentile is not None
+ or outlier_handling.upper_bound_percentile is not None
+ ):
+ return True
+ return False
+
+ def _build_winsorization_bound_exprs(
+ self,
+ outlier_handling: ExperimentMetricOutlierHandling | None,
+ value_field: str,
+ ) -> tuple[ast.Expr, ast.Expr]:
+ """
+ Build (lower_bound, upper_bound) expressions over entity_metrics.<value_field>.
+
+ When a bound is not configured the threshold falls back to min()/max() so the
+ least(greatest(...)) clamp becomes a no-op for that side. This lets the numerator
+ and denominator be capped independently — a binomial denominator simply leaves its
+ outlier handling unset and is never clamped.
+
+ value_field is an internal column name (numerator_value / denominator_value), never
+ user input, so interpolating it into the expression string is safe.
+ """
+ lower_pct = outlier_handling.lower_bound_percentile if outlier_handling else None
+ upper_pct = outlier_handling.upper_bound_percentile if outlier_handling else None
+ ignore_zeros = bool(outlier_handling.ignore_zeros) if outlier_handling else False
+
+ if lower_pct is not None:
+ lower_bound_expr = parse_expr(
+ f"quantileExact({{level}})(entity_metrics.{value_field})",
+ placeholders={"level": ast.Constant(value=lower_pct)},
+ )
+ else:
+ lower_bound_expr = parse_expr(f"min(entity_metrics.{value_field})")
+
+ if upper_pct is not None:
+ if ignore_zeros:
+ upper_bound_expr = parse_expr(
+ f"quantileExact({{level}})(if(entity_metrics.{value_field} != 0, entity_metrics.{value_field}, null))",
+ placeholders={"level": ast.Constant(value=upper_pct)},
+ )
+ else:
+ upper_bound_expr = parse_expr(
+ f"quantileExact({{level}})(entity_metrics.{value_field})",
+ placeholders={"level": ast.Constant(value=upper_pct)},
+ )
+ else:
+ upper_bound_expr = parse_expr(f"max(entity_metrics.{value_field})")
+
+ return lower_bound_expr, upper_bound_expr
+
+ def _build_ratio_query_with_winsorization(self) -> ast.SelectQuery:
+ """
+ Builds query for ratio metrics with winsorization (outlier handling).
+
+ The numerator and denominator are capped independently, each as if it were its own
+ mean metric: percentile thresholds are computed separately for each component (pooled
+ across all variations) and the per-entity numerator and denominator values are clamped
+ against their own bounds. The capped components flow into the same aggregate columns
+ (including the cross-product) so the delta-method variance stays consistent with the
+ capped point estimate.
+ """
+ assert isinstance(self.metric, ExperimentRatioMetric)
+
+ common_ctes, placeholders = self._get_ratio_query_common()
+
+ num_lower_bound, num_upper_bound = self._build_winsorization_bound_exprs(
+ self.metric.numerator_outlier_handling, "numerator_value"
+ )
+ denom_lower_bound, denom_upper_bound = self._build_winsorization_bound_exprs(
+ self.metric.denominator_outlier_handling, "denominator_value"
+ )
+
+ placeholders["numerator_lower_bound"] = num_lower_bound
+ placeholders["numerator_upper_bound"] = num_upper_bound
+ placeholders["denominator_lower_bound"] = denom_lower_bound
+ placeholders["denominator_upper_bound"] = denom_upper_bound
+
+ query = parse_select(
+ f"""
+ WITH {common_ctes},
+
+ percentiles AS (
+ SELECT
+ {{numerator_lower_bound}} AS numerator_lower_bound,
+ {{numerator_upper_bound}} AS numerator_upper_bound,
+ {{denominator_lower_bound}} AS denominator_lower_bound,
+ {{denominator_upper_bound}} AS denominator_upper_bound
+ -- breakdown columns added programmatically below
+ FROM entity_metrics
+ -- GROUP BY added programmatically below if breakdowns exist
+ ),
+
+ winsorized_entity_metrics AS (
+ SELECT
+ entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value
+ -- breakdown columns added programmatically below
+ FROM entity_metrics
+ CROSS JOIN percentiles
+ -- JOIN conditions added programmatically below if breakdowns exist
+ )
+
+ SELECT
+ winsorized_entity_metrics.variant AS variant,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(winsorized_entity_metrics.numerator_value * winsorized_entity_metrics.denominator_value) AS numerator_denominator_sum_product
+ -- breakdown columns added programmatically below
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant
+ -- breakdown columns added programmatically below
+ """,
+ placeholders=placeholders,
+ )
+
+ assert isinstance(query, ast.SelectQuery)
+
+ # Inject breakdown columns into the query AST
+ if self.breakdown_injector:
+ self.breakdown_injector.inject_ratio_breakdown_columns(query, winsorized=True)
+
+ return query
+
+ def _get_ratio_query_common(self) -> tuple[str, dict[str, ast.Expr]]:
+ """
+ Builds the shared CTE chain and placeholders for ratio metric queries.
+
+ Optimized structure using pre-aggregation to reduce join operations:
- exposures: all exposures with variant assignment (with exposure_identifier for data warehouse)
- - numerator_events: events for numerator metric with value
- - denominator_events: events for denominator metric with value
- - combined_events: UNION ALL of numerator and denominator events with NULL for non-applicable columns
- - entity_metrics: single join of exposures to combined_events, aggregating both metrics in one pass
- - Final SELECT: aggregated statistics per variant
+ - numerator_events / denominator_events: events for each component with value
+ - numerator_agg / denominator_agg: per-entity aggregates joined to exposures
+ - entity_metrics: single row per entity carrying numerator_value and denominator_value
This approach reduces memory pressure by joining exposures to events only once
- instead of separately for numerator and denominator.
+ per component instead of fanning out the raw event rows.
"""
assert isinstance(self.metric, ExperimentRatioMetric)
@@ -1298,59 +1475,31 @@ class ExperimentQueryBuilder:
)
"""
- query = parse_select(
- f"""
- WITH {common_ctes}
-
- SELECT
- entity_metrics.variant AS variant,
- count(entity_metrics.entity_id) AS num_users,
- sum(entity_metrics.numerator_value) AS total_sum,
- sum(power(entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
- sum(entity_metrics.denominator_value) AS denominator_sum,
- sum(power(entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
- sum(entity_metrics.numerator_value * entity_metrics.denominator_value) AS numerator_denominator_sum_product
- -- breakdown columns added programmatically below
- FROM entity_metrics
- GROUP BY entity_metrics.variant
- -- breakdown columns added programmatically below
- """,
- placeholders={
- "exposure_select_query": exposure_query,
- "num_entity_key": num_entity_field,
- "denom_entity_key": denom_entity_field,
- "num_timestamp_field": ast.Field(chain=[num_timestamp_field]),
- "num_table": ast.Field(chain=[num_table]),
- "denom_timestamp_field": ast.Field(chain=[denom_timestamp_field]),
- "denom_table": ast.Field(chain=[denom_table]),
- "numerator_predicate": self._build_metric_predicate(
- source=self.metric.numerator, table_alias=num_table
- ),
- "numerator_value_expr": self._build_value_expr(source=self.metric.numerator),
- "numerator_agg": self._build_value_aggregation_expr(
- source=self.metric.numerator, events_alias="numerator_events", column_name="value"
- ),
- "numerator_conversion_window": self._build_conversion_window_predicate_for_events("numerator_events"),
- "denominator_predicate": self._build_metric_predicate(
- source=self.metric.denominator, table_alias=denom_table
- ),
- "denominator_value_expr": self._build_value_expr(source=self.metric.denominator),
- "denominator_agg": self._build_value_aggregation_expr(
- source=self.metric.denominator, events_alias="denominator_events", column_name="value"
- ),
- "denominator_conversion_window": self._build_conversion_window_predicate_for_events(
- "denominator_events"
- ),
- },
- )
-
- assert isinstance(query, ast.SelectQuery)
-
- # Inject breakdown columns into the query AST
- if self.breakdown_injector:
- self.breakdown_injector.inject_ratio_breakdown_columns(query)
+ placeholders: dict[str, ast.Expr] = {
+ "exposure_select_query": exposure_query,
+ "num_entity_key": num_entity_field,
+ "denom_entity_key": denom_entity_field,
+ "num_timestamp_field": ast.Field(chain=[num_timestamp_field]),
+ "num_table": ast.Field(chain=[num_table]),
+ "denom_timestamp_field": ast.Field(chain=[denom_timestamp_field]),
+ "denom_table": ast.Field(chain=[denom_table]),
+ "numerator_predicate": self._build_metric_predicate(source=self.metric.numerator, table_alias=num_table),
+ "numerator_value_expr": self._build_value_expr(source=self.metric.numerator),
+ "numerator_agg": self._build_value_aggregation_expr(
+ source=self.metric.numerator, events_alias="numerator_events", column_name="value"
+ ),
+ "numerator_conversion_window": self._build_conversion_window_predicate_for_events("numerator_events"),
+ "denominator_predicate": self._build_metric_predicate(
+ source=self.metric.denominator, table_alias=denom_table
+ ),
+ "denominator_value_expr": self._build_value_expr(source=self.metric.denominator),
+ "denominator_agg": self._build_value_aggregation_expr(
+ source=self.metric.denominator, events_alias="denominator_events", column_name="value"
+ ),
+ "denominator_conversion_window": self._build_conversion_window_predicate_for_events("denominator_events"),
+ }
- return query
+ return common_ctes, placeholders
def _build_conversion_window_predicate(self) -> ast.Expr:
"""
diff --git a/posthog/hogql_queries/experiments/test/experiment_query_runner/__snapshots__/test_ratio_metric.ambr b/posthog/hogql_queries/experiments/test/experiment_query_runner/__snapshots__/test_ratio_metric.ambr
index 745132638966..422147947f65 100644
--- a/posthog/hogql_queries/experiments/test/experiment_query_runner/__snapshots__/test_ratio_metric.ambr
+++ b/posthog/hogql_queries/experiments/test/experiment_query_runner/__snapshots__/test_ratio_metric.ambr
@@ -369,6 +369,547 @@
use_hive_partitioning=0
'''
# ---
+# name: TestExperimentRatioMetric.test_outlier_handling_numerator_and_denominator_independent_0_direct
+ '''
+ WITH exposures AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ if(ifNull(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), 0), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,
+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,
+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,
+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ LEFT JOIN
+ (SELECT person.id AS id,
+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email
+ FROM person
+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),
+ (SELECT person.id AS id, max(person.version) AS version
+ FROM person
+ WHERE equals(person.team_id, 99999)
+ GROUP BY person.id
+ HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))
+ GROUP BY entity_id),
+ numerator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),
+ denominator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'pageview'))),
+ numerator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value
+ FROM numerator_events
+ JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(numerator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ denominator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value
+ FROM denominator_events
+ JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(denominator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ entity_metrics AS
+ (SELECT exposures.variant AS variant,
+ exposures.entity_id AS entity_id,
+ any(coalesce(numerator_agg.value, 0)) AS numerator_value,
+ any(coalesce(denominator_agg.value, 0)) AS denominator_value
+ FROM exposures
+ LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)
+ LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)
+ GROUP BY exposures.variant,
+ exposures.entity_id),
+ percentiles AS
+ (SELECT min(entity_metrics.numerator_value) AS numerator_lower_bound,
+ quantileExact(0.9)(entity_metrics.numerator_value) AS numerator_upper_bound,
+ min(entity_metrics.denominator_value) AS denominator_lower_bound,
+ quantileExact(0.9)(entity_metrics.denominator_value) AS denominator_upper_bound
+ FROM entity_metrics),
+ winsorized_entity_metrics AS
+ (SELECT entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value
+ FROM entity_metrics
+ CROSS JOIN percentiles)
+ SELECT winsorized_entity_metrics.variant AS variant,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(multiply(winsorized_entity_metrics.numerator_value, winsorized_entity_metrics.denominator_value)) AS numerator_denominator_sum_product
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant
+ LIMIT 50000 SETTINGS readonly=2,
+ max_execution_time=600,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=39728447488,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestExperimentRatioMetric.test_outlier_handling_numerator_and_denominator_independent_1_precomputed
+ '''
+ WITH exposures AS
+ (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
+ if(ifNull(greater(uniqExact(t.variant), 1), 0), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,
+ min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,
+ max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,
+ argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,
+ argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id
+ FROM experiment_exposures_preaggregated AS t
+ WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))
+ GROUP BY entity_id),
+ numerator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),
+ denominator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'pageview'))),
+ numerator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value
+ FROM numerator_events
+ JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(numerator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ denominator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value
+ FROM denominator_events
+ JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(denominator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ entity_metrics AS
+ (SELECT exposures.variant AS variant,
+ exposures.entity_id AS entity_id,
+ any(coalesce(numerator_agg.value, 0)) AS numerator_value,
+ any(coalesce(denominator_agg.value, 0)) AS denominator_value
+ FROM exposures
+ LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)
+ LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)
+ GROUP BY exposures.variant,
+ exposures.entity_id),
+ percentiles AS
+ (SELECT min(entity_metrics.numerator_value) AS numerator_lower_bound,
+ quantileExact(0.9)(entity_metrics.numerator_value) AS numerator_upper_bound,
+ min(entity_metrics.denominator_value) AS denominator_lower_bound,
+ quantileExact(0.9)(entity_metrics.denominator_value) AS denominator_upper_bound
+ FROM entity_metrics),
+ winsorized_entity_metrics AS
+ (SELECT entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value
+ FROM entity_metrics
+ CROSS JOIN percentiles)
+ SELECT winsorized_entity_metrics.variant AS variant,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(multiply(winsorized_entity_metrics.numerator_value, winsorized_entity_metrics.denominator_value)) AS numerator_denominator_sum_product
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant
+ LIMIT 50000 SETTINGS load_balancing='in_order',
+ readonly=2,
+ max_execution_time=600,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=39728447488,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestExperimentRatioMetric.test_outlier_handling_numerator_only_0_direct
+ '''
+ WITH exposures AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ if(ifNull(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), 0), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,
+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,
+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,
+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ LEFT JOIN
+ (SELECT person.id AS id,
+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email
+ FROM person
+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),
+ (SELECT person.id AS id, max(person.version) AS version
+ FROM person
+ WHERE equals(person.team_id, 99999)
+ GROUP BY person.id
+ HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))
+ GROUP BY entity_id),
+ numerator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),
+ denominator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'pageview'))),
+ numerator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value
+ FROM numerator_events
+ JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(numerator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ denominator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value
+ FROM denominator_events
+ JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(denominator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ entity_metrics AS
+ (SELECT exposures.variant AS variant,
+ exposures.entity_id AS entity_id,
+ any(coalesce(numerator_agg.value, 0)) AS numerator_value,
+ any(coalesce(denominator_agg.value, 0)) AS denominator_value
+ FROM exposures
+ LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)
+ LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)
+ GROUP BY exposures.variant,
+ exposures.entity_id),
+ percentiles AS
+ (SELECT min(entity_metrics.numerator_value) AS numerator_lower_bound,
+ quantileExact(0.9)(entity_metrics.numerator_value) AS numerator_upper_bound,
+ min(entity_metrics.denominator_value) AS denominator_lower_bound,
+ max(entity_metrics.denominator_value) AS denominator_upper_bound
+ FROM entity_metrics),
+ winsorized_entity_metrics AS
+ (SELECT entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value
+ FROM entity_metrics
+ CROSS JOIN percentiles)
+ SELECT winsorized_entity_metrics.variant AS variant,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(multiply(winsorized_entity_metrics.numerator_value, winsorized_entity_metrics.denominator_value)) AS numerator_denominator_sum_product
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant
+ LIMIT 50000 SETTINGS readonly=2,
+ max_execution_time=600,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=39728447488,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestExperimentRatioMetric.test_outlier_handling_numerator_only_1_precomputed
+ '''
+ WITH exposures AS
+ (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
+ if(ifNull(greater(uniqExact(t.variant), 1), 0), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,
+ min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,
+ max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,
+ argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,
+ argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id
+ FROM experiment_exposures_preaggregated AS t
+ WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))
+ GROUP BY entity_id),
+ numerator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),
+ denominator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'pageview'))),
+ numerator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value
+ FROM numerator_events
+ JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(numerator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ denominator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value
+ FROM denominator_events
+ JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(denominator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ entity_metrics AS
+ (SELECT exposures.variant AS variant,
+ exposures.entity_id AS entity_id,
+ any(coalesce(numerator_agg.value, 0)) AS numerator_value,
+ any(coalesce(denominator_agg.value, 0)) AS denominator_value
+ FROM exposures
+ LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)
+ LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)
+ GROUP BY exposures.variant,
+ exposures.entity_id),
+ percentiles AS
+ (SELECT min(entity_metrics.numerator_value) AS numerator_lower_bound,
+ quantileExact(0.9)(entity_metrics.numerator_value) AS numerator_upper_bound,
+ min(entity_metrics.denominator_value) AS denominator_lower_bound,
+ max(entity_metrics.denominator_value) AS denominator_upper_bound
+ FROM entity_metrics),
+ winsorized_entity_metrics AS
+ (SELECT entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value
+ FROM entity_metrics
+ CROSS JOIN percentiles)
+ SELECT winsorized_entity_metrics.variant AS variant,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(multiply(winsorized_entity_metrics.numerator_value, winsorized_entity_metrics.denominator_value)) AS numerator_denominator_sum_product
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant
+ LIMIT 50000 SETTINGS load_balancing='in_order',
+ readonly=2,
+ max_execution_time=600,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=39728447488,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestExperimentRatioMetric.test_outlier_handling_with_breakdown
+ '''
+ WITH exposures AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ if(ifNull(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), 0), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,
+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,
+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,
+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id,
+ argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_1
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ LEFT JOIN
+ (SELECT person.id AS id,
+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email
+ FROM person
+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),
+ (SELECT person.id AS id, max(person.version) AS version
+ FROM person
+ WHERE equals(person.team_id, 99999)
+ GROUP BY person.id
+ HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))
+ GROUP BY entity_id),
+ numerator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),
+ denominator_events AS
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ toTimeZone(events.timestamp, 'UTC') AS timestamp,
+ coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'pageview'))),
+ numerator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value
+ FROM numerator_events
+ JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(numerator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ denominator_agg AS
+ (SELECT exposures.entity_id AS entity_id,
+ sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value
+ FROM denominator_events
+ JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)
+ WHERE ifNull(greaterOrEquals(denominator_events.timestamp, exposures.first_exposure_time), 0)
+ GROUP BY exposures.entity_id),
+ entity_metrics AS
+ (SELECT exposures.variant AS variant,
+ exposures.entity_id AS entity_id,
+ any(coalesce(numerator_agg.value, 0)) AS numerator_value,
+ any(coalesce(denominator_agg.value, 0)) AS denominator_value,
+ exposures.breakdown_value_1 AS breakdown_value_1
+ FROM exposures
+ LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)
+ LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)
+ GROUP BY exposures.variant,
+ exposures.entity_id,
+ exposures.breakdown_value_1),
+ percentiles AS
+ (SELECT min(entity_metrics.numerator_value) AS numerator_lower_bound,
+ quantileExact(0.95)(entity_metrics.numerator_value) AS numerator_upper_bound,
+ min(entity_metrics.denominator_value) AS denominator_lower_bound,
+ max(entity_metrics.denominator_value) AS denominator_upper_bound,
+ entity_metrics.breakdown_value_1 AS breakdown_value_1
+ FROM entity_metrics
+ GROUP BY entity_metrics.breakdown_value_1),
+ winsorized_entity_metrics AS
+ (SELECT entity_metrics.entity_id AS entity_id,
+ entity_metrics.variant AS variant,
+ least(greatest(percentiles.numerator_lower_bound, entity_metrics.numerator_value), percentiles.numerator_upper_bound) AS numerator_value,
+ least(greatest(percentiles.denominator_lower_bound, entity_metrics.denominator_value), percentiles.denominator_upper_bound) AS denominator_value,
+ entity_metrics.breakdown_value_1 AS breakdown_value_1
+ FROM entity_metrics
+ JOIN percentiles ON equals(percentiles.breakdown_value_1, entity_metrics.breakdown_value_1))
+ SELECT winsorized_entity_metrics.variant AS variant,
+ winsorized_entity_metrics.breakdown_value_1 AS breakdown_value_1,
+ count(winsorized_entity_metrics.entity_id) AS num_users,
+ sum(winsorized_entity_metrics.numerator_value) AS total_sum,
+ sum(power(winsorized_entity_metrics.numerator_value, 2)) AS total_sum_of_squares,
+ sum(winsorized_entity_metrics.denominator_value) AS denominator_sum,
+ sum(power(winsorized_entity_metrics.denominator_value, 2)) AS denominator_sum_squares,
+ sum(multiply(winsorized_entity_metrics.numerator_value, winsorized_entity_metrics.denominator_value)) AS numerator_denominator_sum_product
+ FROM winsorized_entity_metrics
+ GROUP BY winsorized_entity_metrics.variant,
+ winsorized_entity_metrics.breakdown_value_1
+ LIMIT 50000 SETTINGS readonly=2,
+ max_execution_time=600,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=39728447488,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestExperimentRatioMetric.test_ratio_metric_action_and_event_sources_0_direct
'''
WITH exposures AS
diff --git a/posthog/hogql_queries/experiments/test/experiment_query_runner/test_ratio_metric.py b/posthog/hogql_queries/experiments/test/experiment_query_runner/test_ratio_metric.py
index 8e877bb0a44e..0799d9afe9db 100644
--- a/posthog/hogql_queries/experiments/test/experiment_query_runner/test_ratio_metric.py
+++ b/posthog/hogql_queries/experiments/test/experiment_query_runner/test_ratio_metric.py
@@ -10,9 +10,12 @@ from parameterized import parameterized
from posthog.schema import (
ActionsNode,
+ Breakdown,
+ BreakdownFilter,
EventsNode,
ExperimentDataWarehouseNode,
ExperimentMetricMathType,
+ ExperimentMetricOutlierHandling,
ExperimentQuery,
ExperimentQueryResponse,
ExperimentRatioMetric,
@@ -1246,3 +1249,270 @@ class TestExperimentRatioMetric(ExperimentQueryRunnerBaseTest):
assert len(result.variant_results) == 1
# Test: 1 purchase totaling 75, ratio = 75/1 = 75
self.assertEqual(result.variant_results[0].number_of_samples, 1)
+
+ def _seed_winsorization_journeys(self, feature_flag) -> None:
+ """Seed 20 users (10 control, 10 test) for ratio winsorization tests.
+
+ Per-user numerator = purchase ``amount`` (SUM); denominator = ``pageview`` count (TOTAL).
+
+ Pooled per-user numerators sorted: eighteen 100s, one 200, one 5000.
+ quantileExact(0.9) = element at index floor(0.9 * 20) = 18 -> cap_N = 200.
+ Pooled per-user denominators sorted: eighteen 2s, one 5, one 50.
+ quantileExact(0.9) = element at index 18 -> cap_D = 5.
+
+ The numerator outlier (5000) is a test user while the denominator outlier (50) is a
+ control user, so capping each component clamps a *different* user — exercising the
+ independent capping of numerator and denominator.
+ """
+ ff_property = f"$feature/{feature_flag.key}"
+
+ # (distinct_id, variant, numerator amount, denominator pageview count)
+ users = [
+ ("control_1", "control", 100, 50), # denominator outlier (50 -> cap 5)
+ ("control_2", "control", 100, 2),
+ ("control_3", "control", 100, 2),
+ ("control_4", "control", 100, 2),
+ ("control_5", "control", 100, 2),
+ ("control_6", "control", 100, 2),
+ ("control_7", "control", 100, 2),
+ ("control_8", "control", 100, 2),
+ ("control_9", "control", 100, 2),
+ ("control_10", "control", 200, 5), # numerator & denominator boundary (== caps)
+ ("test_1", "test", 100, 2),
+ ("test_2", "test", 100, 2),
+ ("test_3", "test", 100, 2),
+ ("test_4", "test", 100, 2),
+ ("test_5", "test", 100, 2),
+ ("test_6", "test", 100, 2),
+ ("test_7", "test", 100, 2),
+ ("test_8", "test", 100, 2),
+ ("test_9", "test", 100, 2),
+ ("test_10", "test", 5000, 2), # numerator outlier (5000 -> cap 200)
+ ]
+
+ journeys: dict[str, list[dict]] = {}
+ for distinct_id, variant, amount, pageviews in users:
+ events: list[dict] = [
+ {
+ "event": "$feature_flag_called",
+ "timestamp": "2024-01-02T12:00:00",
+ "properties": {
+ "$feature_flag_response": variant,
+ ff_property: variant,
+ "$feature_flag": feature_flag.key,
+ },
+ },
+ {
+ "event": "purchase",
+ "timestamp": "2024-01-02T12:01:00",
+ "properties": {ff_property: variant, "amount": amount},
+ },
+ ]
+ for _ in range(pageviews):
+ events.append(
+ {
+ "event": "pageview",
+ "timestamp": "2024-01-02T12:02:00",
+ "properties": {ff_property: variant},
+ }
+ )
+ journeys[distinct_id] = events
+
+ journeys_for(journeys, self.team)
+ flush_persons_and_events()
+
+ @parameterized.expand(
+ [
+ ("direct", False),
+ ("precomputed", True),
+ ]
+ )
+ @freeze_time("2024-01-01T12:00:00Z")
+ @snapshot_clickhouse_queries
+ def test_outlier_handling_numerator_only(self, name, use_precomputation):
+ """Capping only the numerator leaves the denominator untouched."""
+ self._setup_precomputation_test(use_precomputation)
+
+ feature_flag = self.create_feature_flag()
+ experiment = self.create_experiment(feature_flag=feature_flag)
+ experiment.stats_config = {"method": "frequentist"}
+ experiment.save()
+
+ metric = ExperimentRatioMetric(
+ numerator=EventsNode(
+ event="purchase",
+ math=ExperimentMetricMathType.SUM,
+ math_property="amount",
+ ),
+ denominator=EventsNode(event="pageview", math=ExperimentMetricMathType.TOTAL),
+ numerator_outlier_handling=ExperimentMetricOutlierHandling(upper_bound_percentile=0.9),
+ )
+
+ experiment_query = ExperimentQuery(
+ experiment_id=experiment.id,
+ kind="ExperimentQuery",
+ metric=metric,
+ )
+
+ experiment.metrics = [metric.model_dump(mode="json")]
+ self._save_experiment_with_precomputation(experiment, use_precomputation)
+
+ self._seed_winsorization_journeys(feature_flag)
+
+ query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)
+ result = cast(ExperimentQueryResponse, query_runner.calculate())
+
+ assert result.baseline is not None
+ assert result.variant_results is not None
+ self.assertEqual(len(result.variant_results), 1)
+
+ control_variant = result.baseline
+ test_variant = result.variant_results[0]
+
+ self.assertEqual(control_variant.number_of_samples, 10)
+ self.assertEqual(test_variant.number_of_samples, 10)
+
+ # Numerator capped at 200: control unchanged (no outlier), test's 5000 -> 200.
+ # control: 9*100 + 200 = 1100 ; test: 9*100 + 200 = 1100
+ self.assertEqual(control_variant.sum, 1100)
+ self.assertEqual(test_variant.sum, 1100)
+
+ # Denominator left uncapped: control = 50 + 8*2 + 5 = 71 ; test = 10*2 = 20
+ self.assertEqual(control_variant.denominator_sum, 71)
+ self.assertEqual(test_variant.denominator_sum, 20)
+
+ @parameterized.expand(
+ [
+ ("direct", False),
+ ("precomputed", True),
+ ]
+ )
+ @freeze_time("2024-01-01T12:00:00Z")
+ @snapshot_clickhouse_queries
+ def test_outlier_handling_numerator_and_denominator_independent(self, name, use_precomputation):
+ """Numerator and denominator are capped independently, each at its own threshold."""
+ self._setup_precomputation_test(use_precomputation)
+
+ feature_flag = self.create_feature_flag()
+ experiment = self.create_experiment(feature_flag=feature_flag)
+ experiment.stats_config = {"method": "frequentist"}
+ experiment.save()
+
+ metric = ExperimentRatioMetric(
+ numerator=EventsNode(
+ event="purchase",
+ math=ExperimentMetricMathType.SUM,
+ math_property="amount",
+ ),
+ denominator=EventsNode(event="pageview", math=ExperimentMetricMathType.TOTAL),
+ numerator_outlier_handling=ExperimentMetricOutlierHandling(upper_bound_percentile=0.9),
+ denominator_outlier_handling=ExperimentMetricOutlierHandling(upper_bound_percentile=0.9),
+ )
+
+ experiment_query = ExperimentQuery(
+ experiment_id=experiment.id,
+ kind="ExperimentQuery",
+ metric=metric,
+ )
+
+ experiment.metrics = [metric.model_dump(mode="json")]
+ self._save_experiment_with_precomputation(experiment, use_precomputation)
+
+ self._seed_winsorization_journeys(feature_flag)
+
+ query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)
+ result = cast(ExperimentQueryResponse, query_runner.calculate())
+
+ assert result.baseline is not None
+ assert result.variant_results is not None
+ self.assertEqual(len(result.variant_results), 1)
+
+ control_variant = result.baseline
+ test_variant = result.variant_results[0]
+
+ self.assertEqual(control_variant.number_of_samples, 10)
+ self.assertEqual(test_variant.number_of_samples, 10)
+
+ # Numerator capped at 200 -> both variants 1100 (as above).
+ self.assertEqual(control_variant.sum, 1100)
+ self.assertEqual(test_variant.sum, 1100)
+
+ # Denominator capped at 5: control's outlier 50 -> 5, so control = 5 + 8*2 + 5 = 26 ;
+ # test has no denominator outlier so it stays 10*2 = 20.
+ self.assertEqual(control_variant.denominator_sum, 26)
+ self.assertEqual(test_variant.denominator_sum, 20)
+
+ @freeze_time("2024-01-01T12:00:00Z")
+ @snapshot_clickhouse_queries
+ def test_outlier_handling_with_breakdown(self):
+ """Winsorization computes per-breakdown thresholds for ratio metrics, not global ones."""
+ feature_flag = self.create_feature_flag()
+ experiment = self.create_experiment(feature_flag=feature_flag)
+ experiment.stats_config = {"method": "frequentist"}
+ experiment.save()
+
+ metric = ExperimentRatioMetric(
+ numerator=EventsNode(
+ event="purchase",
+ math=ExperimentMetricMathType.SUM,
+ math_property="amount",
+ ),
+ denominator=EventsNode(event="pageview", math=ExperimentMetricMathType.TOTAL),
+ breakdownFilter=BreakdownFilter(breakdowns=[Breakdown(property="$browser")]),
+ numerator_outlier_handling=ExperimentMetricOutlierHandling(upper_bound_percentile=0.95),
+ )
+
+ experiment_query = ExperimentQuery(
+ experiment_id=experiment.id,
+ kind="ExperimentQuery",
+ metric=metric,
+ )
+
+ experiment.metrics = [metric.model_dump(mode="json")]
+ experiment.save()
+
+ ff_property = f"$feature/{feature_flag.key}"
+
+ # Chrome users have low numerators, Safari users high — if thresholds were global,
+ # Safari values would be capped at Chrome's percentile.
+ journeys: dict[str, list[dict]] = {}
+ for variant in ("control", "test"):
+ for i in range(4):
+ browser = "Chrome" if i < 2 else "Safari"
+ amount = (10 + i * 10) if browser == "Chrome" else (100 + (i - 2) * 100)
+ journeys[f"{variant}_{i}"] = [
+ {
+ "event": "$feature_flag_called",
+ "timestamp": "2024-01-02T12:00:00",
+ "properties": {
+ "$feature_flag_response": variant,
+ ff_property: variant,
+ "$feature_flag": feature_flag.key,
+ "$browser": browser,
+ },
+ },
+ {
+ "event": "purchase",
+ "timestamp": "2024-01-02T12:01:00",
+ "properties": {ff_property: variant, "amount": amount, "$browser": browser},
+ },
+ {
+ "event": "pageview",
+ "timestamp": "2024-01-02T12:02:00",
+ "properties": {ff_property: variant, "$browser": browser},
+ },
+ ]
+
+ journeys_for(journeys, self.team)
+ flush_persons_and_events()
+
+ query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)
+ result = cast(ExperimentQueryResponse, query_runner.calculate())
+
+ # The query builds and runs with per-breakdown winsorization.
+ self.assertIsNotNone(result.breakdown_results)
+ assert result.breakdown_results is not None
+ self.assertEqual(len(result.breakdown_results), 2)
+ for breakdown_result in result.breakdown_results:
+ self.assertIsNotNone(breakdown_result.baseline)
+ self.assertIsInstance(breakdown_result.variants, list)
diff --git a/posthog/schema.py b/posthog/schema.py
index 320dc27fbbe9..88c584e08599 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -8,7 +8,7 @@ from __future__ import annotations
from enum import Enum, StrEnum
from typing import Annotated, Any, Literal
-from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel, conint
+from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel, confloat, conint
class SchemaRoot(RootModel[Any]):
@@ -1961,8 +1961,18 @@ class ExperimentMetricOutlierHandling(BaseModel):
extra="forbid",
)
ignore_zeros: bool | None = None
- lower_bound_percentile: float | None = None
- upper_bound_percentile: float | None = None
+ lower_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ ),
+ )
+ upper_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ ),
+ )
class Status(StrEnum):
@@ -6923,6 +6933,32 @@ class ExperimentApiEventSource(BaseModel):
)
id: int | None = Field(default=None, description="Action ID. Required for ActionsNode.")
kind: Kind
+ math: ExperimentMetricMathType | None = Field(
+ default=None,
+ description=(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum'"
+ " together with math_property to aggregate a numeric property — e.g. a"
+ " ratio numerator of revenue per order. Other options: 'avg', 'min', 'max',"
+ " 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ )
+ math_group_type_index: MathGroupTypeIndex | None = Field(
+ default=None,
+ description=("Group type index to aggregate over. Required when math is 'unique_group'."),
+ )
+ math_hogql: str | None = Field(
+ default=None,
+ description=(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it"
+ " the metric silently falls back to a plain count/sum."
+ ),
+ )
+ math_property: str | None = Field(
+ default=None,
+ description=(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
+ )
properties: list[EventPropertyFilter] | None = Field(
default=None,
description="Event property filters to narrow which events are counted.",
@@ -6960,13 +6996,40 @@ class ExperimentApiMetric(BaseModel):
denominator: ExperimentApiEventSource | None = Field(
default=None, description="For ratio metrics: denominator source."
)
+ denominator_outlier_handling: ExperimentMetricOutlierHandling | None = Field(
+ default=None,
+ description=(
+ "For ratio metrics: winsorization applied to the denominator aggregate."
+ " Leave unset for a binomial-style denominator, which is never clamped."
+ ),
+ )
goal: ExperimentMetricGoal | None = Field(
default=None, description="Whether higher or lower values indicate success."
)
+ ignore_zeros: bool | None = Field(
+ default=None,
+ description=("For mean metrics: exclude zero values when computing the winsorization percentile thresholds."),
+ )
kind: Literal["ExperimentMetric"] = "ExperimentMetric"
+ lower_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "For mean metrics: winsorization lower percentile bound, as a fraction in"
+ " [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this"
+ " percentile are clamped to it before aggregation."
+ ),
+ )
metric_type: ExperimentMetricType
name: str | None = Field(default=None, description="Human-readable metric name.")
numerator: ExperimentApiEventSource | None = Field(default=None, description="For ratio metrics: numerator source.")
+ numerator_outlier_handling: ExperimentMetricOutlierHandling | None = Field(
+ default=None,
+ description=(
+ "For ratio metrics: winsorization applied to the numerator aggregate,"
+ " independently of the denominator and each with its own percentile"
+ " thresholds."
+ ),
+ )
retention_window_end: int | None = None
retention_window_start: int | None = None
retention_window_unit: FunnelConversionWindowTimeUnit | None = None
@@ -6979,6 +7042,14 @@ class ExperimentApiMetric(BaseModel):
default=None, description="For retention metrics: start event."
)
start_handling: StartHandling | None = None
+ upper_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "For mean metrics: winsorization upper percentile bound, as a fraction in"
+ " [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this"
+ " percentile are clamped to it before aggregation."
+ ),
+ )
uuid: str | None = Field(default=None, description="Unique identifier. Auto-generated if omitted.")
@@ -21090,6 +21161,7 @@ class ExperimentRatioMetric(BaseModel):
conversion_window: int | None = None
conversion_window_unit: FunnelConversionWindowTimeUnit | None = None
denominator: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
+ denominator_outlier_handling: ExperimentMetricOutlierHandling | None = None
fingerprint: str | None = None
goal: ExperimentMetricGoal | None = None
isSharedMetric: bool | None = None
@@ -21097,6 +21169,7 @@ class ExperimentRatioMetric(BaseModel):
metric_type: Literal["ratio"] = "ratio"
name: str | None = None
numerator: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
+ numerator_outlier_handling: ExperimentMetricOutlierHandling | None = None
response: dict[str, Any] | None = None
sharedMetricId: float | None = None
uuid: str | None = None
@@ -21108,8 +21181,10 @@ class ExperimentRatioMetricTypeProps(BaseModel):
extra="forbid",
)
denominator: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
+ denominator_outlier_handling: ExperimentMetricOutlierHandling | None = None
metric_type: Literal["ratio"] = "ratio"
numerator: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
+ numerator_outlier_handling: ExperimentMetricOutlierHandling | None = None
class ExperimentRetentionMetric(BaseModel):
@@ -21972,13 +22047,23 @@ class ExperimentMeanMetric(BaseModel):
ignore_zeros: bool | None = None
isSharedMetric: bool | None = None
kind: Literal["ExperimentMetric"] = "ExperimentMetric"
- lower_bound_percentile: float | None = None
+ lower_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ ),
+ )
metric_type: Literal["mean"] = "mean"
name: str | None = None
response: dict[str, Any] | None = None
sharedMetricId: float | None = None
source: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
- upper_bound_percentile: float | None = None
+ upper_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ ),
+ )
uuid: str | None = None
version: float | None = Field(default=None, description="version of the node, used for schema migrations")
@@ -21988,10 +22073,20 @@ class ExperimentMeanMetricTypeProps(BaseModel):
extra="forbid",
)
ignore_zeros: bool | None = None
- lower_bound_percentile: float | None = None
+ lower_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ ),
+ )
metric_type: Literal["mean"] = "mean"
source: EventsNode | ActionsNode | ExperimentDataWarehouseNode = Field(..., discriminator="kind")
- upper_bound_percentile: float | None = None
+ upper_bound_percentile: confloat(ge=0.0, le=1.0) | None = Field(
+ default=None,
+ description=(
+ "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ ),
+ )
class ExperimentMetricTypeProps(
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index e208410edc0e..83a634ab4967 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -276,16 +276,56 @@ export const KindApi = {
ActionsNode: 'ActionsNode',
} as const
+export type ExperimentMetricMathTypeApi = (typeof ExperimentMetricMathTypeApi)[keyof typeof ExperimentMetricMathTypeApi]
+
+export const ExperimentMetricMathTypeApi = {
+ Total: 'total',
+ Sum: 'sum',
+ UniqueSession: 'unique_session',
+ Min: 'min',
+ Max: 'max',
+ Avg: 'avg',
+ Dau: 'dau',
+ UniqueGroup: 'unique_group',
+ Hogql: 'hogql',
+} as const
+
+export type MathGroupTypeIndexApi = (typeof MathGroupTypeIndexApi)[keyof typeof MathGroupTypeIndexApi]
+
+export const MathGroupTypeIndexApi = {
+ Number0: 0,
+ Number1: 1,
+ Number2: 2,
+ Number3: 3,
+ Number4: 4,
+} as const
+
export interface ExperimentApiEventSourceApi {
/** Event name, e.g. '$pageview'. Required for EventsNode. */
event?: string | null
/** Action ID. Required for ActionsNode. */
id?: number | null
kind: KindApi
+ /** How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'. */
+ math?: ExperimentMetricMathTypeApi | null
+ /** Group type index to aggregate over. Required when math is 'unique_group'. */
+ math_group_type_index?: MathGroupTypeIndexApi | null
+ /** HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum. */
+ math_hogql?: string | null
+ /** Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue'). */
+ math_property?: string | null
/** Event property filters to narrow which events are counted. */
properties?: EventPropertyFilterApi[] | null
}
+export interface ExperimentMetricOutlierHandlingApi {
+ ignore_zeros?: boolean | null
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). */
+ lower_bound_percentile?: number | null
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). */
+ upper_bound_percentile?: number | null
+}
+
export type ExperimentMetricGoalApi = (typeof ExperimentMetricGoalApi)[keyof typeof ExperimentMetricGoalApi]
export const ExperimentMetricGoalApi = {
@@ -328,14 +368,22 @@ export interface ExperimentApiMetricApi {
conversion_window?: number | null
/** For ratio metrics: denominator source. */
denominator?: ExperimentApiEventSourceApi | null
+ /** For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped. */
+ denominator_outlier_handling?: ExperimentMetricOutlierHandlingApi | null
/** Whether higher or lower values indicate success. */
goal?: ExperimentMetricGoalApi | null
+ /** For mean metrics: exclude zero values when computing the winsorization percentile thresholds. */
+ ignore_zeros?: boolean | null
kind?: 'ExperimentMetric'
+ /** For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation. */
+ lower_bound_percentile?: number | null
metric_type: ExperimentMetricTypeApi
/** Human-readable metric name. */
name?: string | null
/** For ratio metrics: numerator source. */
numerator?: ExperimentApiEventSourceApi | null
+ /** For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds. */
+ numerator_outlier_handling?: ExperimentMetricOutlierHandlingApi | null
retention_window_end?: number | null
retention_window_start?: number | null
retention_window_unit?: FunnelConversionWindowTimeUnitApi | null
@@ -346,6 +394,8 @@ export interface ExperimentApiMetricApi {
/** For retention metrics: start event. */
start_event?: ExperimentApiEventSourceApi | null
start_handling?: StartHandlingApi | null
+ /** For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation. */
+ upper_bound_percentile?: number | null
/** Unique identifier. Auto-generated if omitted. */
uuid?: string | null
}
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 3aefbbe08a70..7d843f3ff424 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -4426,12 +4426,14 @@ export interface ExperimentMeanMetricApi {
ignore_zeros?: boolean | null
isSharedMetric?: boolean | null
kind?: 'ExperimentMetric'
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). */
lower_bound_percentile?: number | null
metric_type?: 'mean'
name?: string | null
response?: ExperimentMeanMetricApiResponse
sharedMetricId?: number | null
source: EventsNodeApi | ActionsNodeApi | ExperimentDataWarehouseNodeApi
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). */
upper_bound_percentile?: number | null
uuid?: string | null
/** version of the node, used for schema migrations */
@@ -4459,6 +4461,14 @@ export interface ExperimentFunnelMetricApi {
version?: number | null
}
+export interface ExperimentMetricOutlierHandlingApi {
+ ignore_zeros?: boolean | null
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). */
+ lower_bound_percentile?: number | null
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). */
+ upper_bound_percentile?: number | null
+}
+
export type ExperimentRatioMetricApiResponse = { [key: string]: unknown } | null
export interface ExperimentRatioMetricApi {
@@ -4466,6 +4476,7 @@ export interface ExperimentRatioMetricApi {
conversion_window?: number | null
conversion_window_unit?: FunnelConversionWindowTimeUnitApi | null
denominator: EventsNodeApi | ActionsNodeApi | ExperimentDataWarehouseNodeApi
+ denominator_outlier_handling?: ExperimentMetricOutlierHandlingApi | null
fingerprint?: string | null
goal?: ExperimentMetricGoalApi | null
isSharedMetric?: boolean | null
@@ -4473,6 +4484,7 @@ export interface ExperimentRatioMetricApi {
metric_type?: 'ratio'
name?: string | null
numerator: EventsNodeApi | ActionsNodeApi | ExperimentDataWarehouseNodeApi
+ numerator_outlier_handling?: ExperimentMetricOutlierHandlingApi | null
response?: ExperimentRatioMetricApiResponse
sharedMetricId?: number | null
uuid?: string | null
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 16e97b5d1b74..f3e9e141b277 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -3254,12 +3254,14 @@ export namespace Schemas {
ignore_zeros?: boolean | null;
isSharedMetric?: boolean | null;
kind?: 'ExperimentMetric';
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). */
lower_bound_percentile?: number | null;
metric_type?: 'mean';
name?: string | null;
response?: ExperimentMeanMetricResponse;
sharedMetricId?: number | null;
source: EventsNode | ActionsNode | ExperimentDataWarehouseNode;
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). */
upper_bound_percentile?: number | null;
uuid?: string | null;
/** version of the node, used for schema migrations */
@@ -3287,6 +3289,14 @@ export namespace Schemas {
version?: number | null;
}
+ export interface ExperimentMetricOutlierHandling {
+ ignore_zeros?: boolean | null;
+ /** Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). */
+ lower_bound_percentile?: number | null;
+ /** Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). */
+ upper_bound_percentile?: number | null;
+ }
+
export type ExperimentRatioMetricResponse = { [key: string]: unknown } | null;
export interface ExperimentRatioMetric {
@@ -3294,6 +3304,7 @@ export namespace Schemas {
conversion_window?: number | null;
conversion_window_unit?: FunnelConversionWindowTimeUnit | null;
denominator: EventsNode | ActionsNode | ExperimentDataWarehouseNode;
+ denominator_outlier_handling?: ExperimentMetricOutlierHandling | null;
fingerprint?: string | null;
goal?: ExperimentMetricGoal | null;
isSharedMetric?: boolean | null;
@@ -3301,6 +3312,7 @@ export namespace Schemas {
metric_type?: 'ratio';
name?: string | null;
numerator: EventsNode | ActionsNode | ExperimentDataWarehouseNode;
+ numerator_outlier_handling?: ExperimentMetricOutlierHandling | null;
response?: ExperimentRatioMetricResponse;
sharedMetricId?: number | null;
uuid?: string | null;
@@ -15854,6 +15866,14 @@ export namespace Schemas {
/** Action ID. Required for ActionsNode. */
id?: number | null;
kind: Kind;
+ /** How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'. */
+ math?: ExperimentMetricMathType | null;
+ /** Group type index to aggregate over. Required when math is 'unique_group'. */
+ math_group_type_index?: MathGroupTypeIndex | null;
+ /** HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum. */
+ math_hogql?: string | null;
+ /** Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue'). */
+ math_property?: string | null;
/** Event property filters to narrow which events are counted. */
properties?: EventPropertyFilter[] | null;
}
@@ -15875,14 +15895,22 @@ export namespace Schemas {
conversion_window?: number | null;
/** For ratio metrics: denominator source. */
denominator?: ExperimentApiEventSource | null;
+ /** For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped. */
+ denominator_outlier_handling?: ExperimentMetricOutlierHandling | null;
/** Whether higher or lower values indicate success. */
goal?: ExperimentMetricGoal | null;
+ /** For mean metrics: exclude zero values when computing the winsorization percentile thresholds. */
+ ignore_zeros?: boolean | null;
kind?: 'ExperimentMetric';
+ /** For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation. */
+ lower_bound_percentile?: number | null;
metric_type: ExperimentMetricType;
/** Human-readable metric name. */
name?: string | null;
/** For ratio metrics: numerator source. */
numerator?: ExperimentApiEventSource | null;
+ /** For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds. */
+ numerator_outlier_handling?: ExperimentMetricOutlierHandling | null;
retention_window_end?: number | null;
retention_window_start?: number | null;
retention_window_unit?: FunnelConversionWindowTimeUnit | null;
@@ -15893,6 +15921,8 @@ export namespace Schemas {
/** For retention metrics: start event. */
start_event?: ExperimentApiEventSource | null;
start_handling?: StartHandling | null;
+ /** For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation. */
+ upper_bound_percentile?: number | null;
/** Unique identifier. Auto-generated if omitted. */
uuid?: string | null;
}
diff --git a/services/mcp/src/generated/experiments/api.ts b/services/mcp/src/generated/experiments/api.ts
index 007d24976b56..ea32bb0f850c 100644
--- a/services/mcp/src/generated/experiments/api.ts
+++ b/services/mcp/src/generated/experiments/api.ts
@@ -175,6 +175,10 @@ export const experimentsCreateBodyExposureCriteriaOneExposureConfigDefault = nul
export const experimentsCreateBodyExposureCriteriaOneFilterTestAccountsDefault = null
export const experimentsCreateBodyMetricsOneItemCompletionEventOneEventDefault = null
export const experimentsCreateBodyMetricsOneItemCompletionEventOneIdDefault = null
+export const experimentsCreateBodyMetricsOneItemCompletionEventOneMathDefault = null
+export const experimentsCreateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -184,28 +188,65 @@ export const experimentsCreateBodyMetricsOneItemCompletionEventDefault = null
export const experimentsCreateBodyMetricsOneItemConversionWindowDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorOneEventDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorOneIdDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOneMathDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorOnePropertiesDefault = null
export const experimentsCreateBodyMetricsOneItemDenominatorDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingDefault = null
export const experimentsCreateBodyMetricsOneItemGoalDefault = null
+export const experimentsCreateBodyMetricsOneItemIgnoreZerosDefault = null
export const experimentsCreateBodyMetricsOneItemKindDefault = `ExperimentMetric`
+export const experimentsCreateBodyMetricsOneItemLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemLowerBoundPercentileDefault = null
export const experimentsCreateBodyMetricsOneItemNameDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorOneEventDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorOneIdDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOneMathDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorOnePropertiesDefault = null
export const experimentsCreateBodyMetricsOneItemNumeratorDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingDefault = null
export const experimentsCreateBodyMetricsOneItemRetentionWindowEndDefault = null
export const experimentsCreateBodyMetricsOneItemRetentionWindowStartDefault = null
export const experimentsCreateBodyMetricsOneItemRetentionWindowUnitDefault = null
export const experimentsCreateBodyMetricsOneItemSeriesOneItemEventDefault = null
export const experimentsCreateBodyMetricsOneItemSeriesOneItemIdDefault = null
+export const experimentsCreateBodyMetricsOneItemSeriesOneItemMathDefault = null
+export const experimentsCreateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -214,6 +255,10 @@ export const experimentsCreateBodyMetricsOneItemSeriesOneItemPropertiesDefault =
export const experimentsCreateBodyMetricsOneItemSeriesDefault = null
export const experimentsCreateBodyMetricsOneItemSourceOneEventDefault = null
export const experimentsCreateBodyMetricsOneItemSourceOneIdDefault = null
+export const experimentsCreateBodyMetricsOneItemSourceOneMathDefault = null
+export const experimentsCreateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemSourceOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemSourceOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -222,6 +267,10 @@ export const experimentsCreateBodyMetricsOneItemSourceOnePropertiesDefault = nul
export const experimentsCreateBodyMetricsOneItemSourceDefault = null
export const experimentsCreateBodyMetricsOneItemStartEventOneEventDefault = null
export const experimentsCreateBodyMetricsOneItemStartEventOneIdDefault = null
+export const experimentsCreateBodyMetricsOneItemStartEventOneMathDefault = null
+export const experimentsCreateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsOneItemStartEventOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsOneItemStartEventOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -229,9 +278,17 @@ export const experimentsCreateBodyMetricsOneItemStartEventOnePropertiesOneItemVa
export const experimentsCreateBodyMetricsOneItemStartEventOnePropertiesDefault = null
export const experimentsCreateBodyMetricsOneItemStartEventDefault = null
export const experimentsCreateBodyMetricsOneItemStartHandlingDefault = null
+export const experimentsCreateBodyMetricsOneItemUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsOneItemUpperBoundPercentileDefault = null
export const experimentsCreateBodyMetricsOneItemUuidDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -241,28 +298,65 @@ export const experimentsCreateBodyMetricsSecondaryOneItemCompletionEventDefault
export const experimentsCreateBodyMetricsSecondaryOneItemConversionWindowDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemGoalDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemIgnoreZerosDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemKindDefault = `ExperimentMetric`
+export const experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNameDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemRetentionWindowEndDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemRetentionWindowStartDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemRetentionWindowUnitDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -271,6 +365,10 @@ export const experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemProperties
export const experimentsCreateBodyMetricsSecondaryOneItemSeriesDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -279,6 +377,10 @@ export const experimentsCreateBodyMetricsSecondaryOneItemSourceOnePropertiesDefa
export const experimentsCreateBodyMetricsSecondaryOneItemSourceDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneIdDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -286,6 +388,10 @@ export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOneProperties
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartEventDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemStartHandlingDefault = null
+export const experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin = 0
+export const experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault = null
export const experimentsCreateBodyMetricsSecondaryOneItemUuidDefault = null
export const experimentsCreateBodyAllowUnknownEventsDefault = false
export const experimentsCreateBodyUpdateFeatureFlagParamsDefault = false
@@ -494,6 +600,58 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemCompletionEventOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemCompletionEventOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -599,6 +757,56 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemDenominatorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemDenominatorOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemDenominatorOneMathHogqlDefault)
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -686,13 +894,82 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
])
.default(experimentsCreateBodyMetricsOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemDenominatorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsCreateBodyMetricsOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsCreateBodyMetricsOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsCreateBodyMetricsOneItemLowerBoundPercentileOneMin)
+ .max(experimentsCreateBodyMetricsOneItemLowerBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemLowerBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -710,6 +987,54 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemNumeratorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemNumeratorOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemNumeratorOneMathHogqlDefault)
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemNumeratorOneMathPropertyDefault)
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -797,6 +1122,57 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
])
.default(experimentsCreateBodyMetricsOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemNumeratorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(experimentsCreateBodyMetricsOneItemRetentionWindowEndDefault),
@@ -819,6 +1195,58 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemSeriesOneItemIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemSeriesOneItemMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -921,6 +1349,54 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemSourceOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemSourceOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemSourceOneMathHogqlDefault)
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemSourceOneMathPropertyDefault)
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1020,6 +1496,56 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsOneItemStartEventOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemStartEventOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(experimentsCreateBodyMetricsOneItemStartEventOneMathHogqlDefault)
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1110,6 +1636,18 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsCreateBodyMetricsOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsCreateBodyMetricsOneItemUpperBoundPercentileOneMin)
+ .max(experimentsCreateBodyMetricsOneItemUpperBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsOneItemUpperBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsCreateBodyMetricsOneItemUuidDefault)
@@ -1144,6 +1682,60 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1253,6 +1845,60 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1342,13 +1988,82 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
])
.default(experimentsCreateBodyMetricsSecondaryOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsCreateBodyMetricsSecondaryOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsCreateBodyMetricsSecondaryOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin)
+ .max(experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -1368,6 +2083,60 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1457,6 +2226,57 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
])
.default(experimentsCreateBodyMetricsSecondaryOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(experimentsCreateBodyMetricsSecondaryOneItemRetentionWindowEndDefault),
@@ -1483,6 +2303,60 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1585,6 +2459,58 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsSecondaryOneItemSourceOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1688,6 +2614,60 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
.default(experimentsCreateBodyMetricsSecondaryOneItemStartEventOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsCreateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -1780,6 +2760,18 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsCreateBodyMetricsSecondaryOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin)
+ .max(experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsCreateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsCreateBodyMetricsSecondaryOneItemUuidDefault)
@@ -1869,6 +2861,10 @@ export const experimentsPartialUpdateBodyExposureCriteriaOneExposureConfigDefaul
export const experimentsPartialUpdateBodyExposureCriteriaOneFilterTestAccountsDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -1878,28 +2874,65 @@ export const experimentsPartialUpdateBodyMetricsOneItemCompletionEventDefault =
export const experimentsPartialUpdateBodyMetricsOneItemConversionWindowDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemDenominatorDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemGoalDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemIgnoreZerosDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemKindDefault = `ExperimentMetric`
+export const experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNameDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemNumeratorDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemRetentionWindowEndDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemRetentionWindowStartDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemRetentionWindowUnitDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -1908,6 +2941,10 @@ export const experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemPropertiesDe
export const experimentsPartialUpdateBodyMetricsOneItemSeriesDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSourceOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSourceOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSourceOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSourceOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemSourceOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -1916,6 +2953,10 @@ export const experimentsPartialUpdateBodyMetricsOneItemSourceOnePropertiesDefaul
export const experimentsPartialUpdateBodyMetricsOneItemSourceDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -1923,9 +2964,17 @@ export const experimentsPartialUpdateBodyMetricsOneItemStartEventOnePropertiesOn
export const experimentsPartialUpdateBodyMetricsOneItemStartEventOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartEventDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemStartHandlingDefault = null
+export const experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileDefault = null
export const experimentsPartialUpdateBodyMetricsOneItemUuidDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -1935,28 +2984,69 @@ export const experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventD
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemConversionWindowDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault =
+ null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault =
+ null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemGoalDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemIgnoreZerosDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemKindDefault = `ExperimentMetric`
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNameDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault =
+ null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault =
+ null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemRetentionWindowEndDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemRetentionWindowStartDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemRetentionWindowUnitDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -1965,6 +3055,10 @@ export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemPro
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -1973,6 +3067,10 @@ export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOnePropert
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneIdDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -1980,6 +3078,10 @@ export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOnePro
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOnePropertiesDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemStartHandlingDefault = null
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin = 0
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault = null
export const experimentsPartialUpdateBodyMetricsSecondaryOneItemUuidDefault = null
export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
@@ -2190,6 +3292,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2297,6 +3453,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
.default(experimentsPartialUpdateBodyMetricsOneItemDenominatorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2386,13 +3596,82 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
])
.default(experimentsPartialUpdateBodyMetricsOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemDenominatorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsPartialUpdateBodyMetricsOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsPartialUpdateBodyMetricsOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsPartialUpdateBodyMetricsOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileOneMin)
+ .max(experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemLowerBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -2410,6 +3689,58 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
.default(experimentsPartialUpdateBodyMetricsOneItemNumeratorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2499,6 +3830,57 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
])
.default(experimentsPartialUpdateBodyMetricsOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemNumeratorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(experimentsPartialUpdateBodyMetricsOneItemRetentionWindowEndDefault),
@@ -2525,6 +3907,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2627,6 +4063,58 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
.default(experimentsPartialUpdateBodyMetricsOneItemSourceOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemSourceOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSourceOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemSourceOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2730,6 +4218,58 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
.default(experimentsPartialUpdateBodyMetricsOneItemStartEventOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2822,6 +4362,18 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsPartialUpdateBodyMetricsOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileOneMin)
+ .max(experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsOneItemUpperBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsPartialUpdateBodyMetricsOneItemUuidDefault)
@@ -2856,6 +4408,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -2965,6 +4571,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -3054,13 +4714,88 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault
+ )
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsPartialUpdateBodyMetricsSecondaryOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -3082,12 +4817,66 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
- properties: zod
+ math: zod
.union([
- zod.array(
- zod.object({
- key: zod.string(),
- label: zod
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
+ properties: zod
+ .union([
+ zod.array(
+ zod.object({
+ key: zod.string(),
+ label: zod
.union([zod.string(), zod.null()])
.default(
experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemLabelDefault
@@ -3171,6 +4960,59 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault
+ )
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemRetentionWindowEndDefault),
@@ -3199,6 +5041,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -3305,6 +5201,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -3410,6 +5360,60 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -3502,6 +5506,22 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(experimentsPartialUpdateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsPartialUpdateBodyMetricsSecondaryOneItemUuidDefault)
@@ -3612,6 +5632,10 @@ export const experimentsDuplicateCreateBodyExposureCriteriaOneExposureConfigDefa
export const experimentsDuplicateCreateBodyExposureCriteriaOneFilterTestAccountsDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -3621,28 +5645,65 @@ export const experimentsDuplicateCreateBodyMetricsOneItemCompletionEventDefault
export const experimentsDuplicateCreateBodyMetricsOneItemConversionWindowDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemGoalDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemIgnoreZerosDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemKindDefault = `ExperimentMetric`
+export const experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNameDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemRetentionWindowEndDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemRetentionWindowStartDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemRetentionWindowUnitDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -3651,6 +5712,10 @@ export const experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemProperties
export const experimentsDuplicateCreateBodyMetricsOneItemSeriesDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -3659,6 +5724,10 @@ export const experimentsDuplicateCreateBodyMetricsOneItemSourceOnePropertiesDefa
export const experimentsDuplicateCreateBodyMetricsOneItemSourceDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -3666,9 +5735,17 @@ export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOneProperties
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartEventDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemStartHandlingDefault = null
+export const experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileDefault = null
export const experimentsDuplicateCreateBodyMetricsOneItemUuidDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOnePropertiesOneItemTypeDefault = `event`
@@ -3678,28 +5755,69 @@ export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEven
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemConversionWindowDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemTypeDefault = `event`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesOneItemValueDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault =
+ null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault =
+ null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemGoalDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemIgnoreZerosDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemKindDefault = `ExperimentMetric`
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNameDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemTypeDefault = `event`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesOneItemValueDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault =
+ null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault =
+ null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemRetentionWindowEndDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemRetentionWindowStartDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemRetentionWindowUnitDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemPropertiesOneItemTypeDefault = `event`
@@ -3708,6 +5826,10 @@ export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemP
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOnePropertiesOneItemTypeDefault = `event`
@@ -3716,6 +5838,10 @@ export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOnePrope
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneIdDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemLabelDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemOperatorDefault = `exact`
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesOneItemTypeDefault = `event`
@@ -3723,6 +5849,10 @@ export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneP
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOnePropertiesDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartHandlingDefault = null
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin = 0
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax = 1
+
+export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault = null
export const experimentsDuplicateCreateBodyMetricsSecondaryOneItemUuidDefault = null
export const experimentsDuplicateCreateBodyAllowUnknownEventsDefault = false
export const experimentsDuplicateCreateBodyUpdateFeatureFlagParamsDefault = false
@@ -3937,6 +6067,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4046,6 +6230,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4135,13 +6373,82 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
])
.default(experimentsDuplicateCreateBodyMetricsOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemDenominatorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsDuplicateCreateBodyMetricsOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileOneMin)
+ .max(experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemLowerBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -4161,6 +6468,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
.default(experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4250,6 +6611,57 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
])
.default(experimentsDuplicateCreateBodyMetricsOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemNumeratorOutlierHandlingDefault)
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsOneItemRetentionWindowEndDefault),
@@ -4276,6 +6688,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4378,6 +6844,58 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
.default(experimentsDuplicateCreateBodyMetricsOneItemSourceOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathDefault)
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemSourceOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4481,6 +6999,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
.default(experimentsDuplicateCreateBodyMetricsOneItemStartEventOneIdDefault)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4573,6 +7145,18 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileOneMin)
+ .max(experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileOneMax),
+ zod.null(),
+ ])
+ .default(experimentsDuplicateCreateBodyMetricsOneItemUpperBoundPercentileDefault)
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsOneItemUuidDefault)
@@ -4607,6 +7191,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemCompletionEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4716,6 +7354,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4805,13 +7497,90 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
])
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorDefault)
.describe('For ratio metrics: denominator source.'),
+ denominator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemDenominatorOutlierHandlingDefault
+ )
+ .describe(
+ 'For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped.'
+ ),
goal: zod
.union([zod.enum(['increase', 'decrease']), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemGoalDefault)
.describe('Whether higher or lower values indicate success.'),
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemIgnoreZerosDefault)
+ .describe(
+ 'For mean metrics: exclude zero values when computing the winsorization percentile thresholds.'
+ ),
kind: zod
.literal('ExperimentMetric')
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemKindDefault),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemLowerBoundPercentileDefault
+ )
+ .describe(
+ 'For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation.'
+ ),
metric_type: zod.enum(['funnel', 'mean', 'ratio', 'retention']),
name: zod
.union([zod.string(), zod.null()])
@@ -4833,6 +7602,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -4922,6 +7745,59 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
])
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorDefault)
.describe('For ratio metrics: numerator source.'),
+ numerator_outlier_handling: zod
+ .union([
+ zod.object({
+ ignore_zeros: zod
+ .union([zod.boolean(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneIgnoreZerosDefault
+ ),
+ lower_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneLowerBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile).'
+ ),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingOneUpperBoundPercentileDefault
+ )
+ .describe(
+ 'Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile).'
+ ),
+ }),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemNumeratorOutlierHandlingDefault
+ )
+ .describe(
+ 'For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds.'
+ ),
retention_window_end: zod
.union([zod.number(), zod.null()])
.default(
@@ -4954,6 +7830,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSeriesOneItemMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -5060,6 +7990,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemSourceOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -5165,6 +8149,60 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
)
.describe('Action ID. Required for ActionsNode.'),
kind: zod.enum(['EventsNode', 'ActionsNode']),
+ math: zod
+ .union([
+ zod.enum([
+ 'total',
+ 'sum',
+ 'unique_session',
+ 'min',
+ 'max',
+ 'avg',
+ 'dau',
+ 'unique_group',
+ 'hogql',
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathDefault
+ )
+ .describe(
+ "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ ),
+ math_group_type_index: zod
+ .union([
+ zod.union([
+ zod.literal(0),
+ zod.literal(1),
+ zod.literal(2),
+ zod.literal(3),
+ zod.literal(4),
+ ]),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathGroupTypeIndexDefault
+ )
+ .describe(
+ "Group type index to aggregate over. Required when math is 'unique_group'."
+ ),
+ math_hogql: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathHogqlDefault
+ )
+ .describe(
+ "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ ),
+ math_property: zod
+ .union([zod.string(), zod.null()])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartEventOneMathPropertyDefault
+ )
+ .describe(
+ "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ ),
properties: zod
.union([
zod.array(
@@ -5257,6 +8295,24 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
start_handling: zod
.union([zod.enum(['first_seen', 'last_seen']), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemStartHandlingDefault),
+ upper_bound_percentile: zod
+ .union([
+ zod
+ .number()
+ .min(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMin
+ )
+ .max(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileOneMax
+ ),
+ zod.null(),
+ ])
+ .default(
+ experimentsDuplicateCreateBodyMetricsSecondaryOneItemUpperBoundPercentileDefault
+ )
+ .describe(
+ 'For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation.'
+ ),
uuid: zod
.union([zod.string(), zod.null()])
.default(experimentsDuplicateCreateBodyMetricsSecondaryOneItemUuidDefault)
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
index 5db75ba0030d..42253d7dffb9 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
@@ -284,6 +284,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -457,6 +537,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -586,6 +746,59 @@
"default": null,
"description": "For ratio metrics: denominator source."
},
+ "denominator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped."
+ },
"goal": {
"anyOf": [
{
@@ -599,11 +812,37 @@
"default": null,
"description": "Whether higher or lower values indicate success."
},
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: exclude zero values when computing the winsorization percentile thresholds."
+ },
"kind": {
"const": "ExperimentMetric",
"default": "ExperimentMetric",
"type": "string"
},
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation."
+ },
"metric_type": {
"enum": ["funnel", "mean", "ratio", "retention"],
"type": "string"
@@ -652,6 +891,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -781,6 +1100,59 @@
"default": null,
"description": "For ratio metrics: numerator source."
},
+ "numerator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds."
+ },
"retention_window_end": {
"anyOf": [
{
@@ -848,6 +1220,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1011,6 +1463,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1117,34 +1649,118 @@
"default": null
}
},
- "required": ["key"],
- "type": "object"
- },
- "type": "array"
+ "required": ["key"],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Event property filters to narrow which events are counted."
+ }
+ },
+ "required": ["kind"],
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: event source."
+ },
+ "start_event": {
+ "anyOf": [
+ {
+ "properties": {
+ "event": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Event name, e.g. '$pageview'. Required for EventsNode."
+ },
+ "id": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Action ID. Required for ActionsNode."
+ },
+ "kind": {
+ "enum": ["EventsNode", "ActionsNode"],
+ "type": "string"
+ },
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
},
{
"type": "null"
}
],
"default": null,
- "description": "Event property filters to narrow which events are counted."
- }
- },
- "required": ["kind"],
- "type": "object"
- },
- {
- "type": "null"
- }
- ],
- "default": null,
- "description": "For mean metrics: event source."
- },
- "start_event": {
- "anyOf": [
- {
- "properties": {
- "event": {
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
"anyOf": [
{
"type": "string"
@@ -1154,23 +1770,19 @@
}
],
"default": null,
- "description": "Event name, e.g. '$pageview'. Required for EventsNode."
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
},
- "id": {
+ "math_property": {
"anyOf": [
{
- "type": "number"
+ "type": "string"
},
{
"type": "null"
}
],
"default": null,
- "description": "Action ID. Required for ActionsNode."
- },
- "kind": {
- "enum": ["EventsNode", "ActionsNode"],
- "type": "string"
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
},
"properties": {
"anyOf": [
@@ -1313,6 +1925,20 @@
],
"default": null
},
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation."
+ },
"uuid": {
"anyOf": [
{
@@ -1375,6 +2001,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1548,6 +2254,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1677,6 +2463,59 @@
"default": null,
"description": "For ratio metrics: denominator source."
},
+ "denominator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped."
+ },
"goal": {
"anyOf": [
{
@@ -1690,11 +2529,37 @@
"default": null,
"description": "Whether higher or lower values indicate success."
},
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: exclude zero values when computing the winsorization percentile thresholds."
+ },
"kind": {
"const": "ExperimentMetric",
"default": "ExperimentMetric",
"type": "string"
},
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation."
+ },
"metric_type": {
"enum": ["funnel", "mean", "ratio", "retention"],
"type": "string"
@@ -1725,23 +2590,103 @@
}
],
"default": null,
- "description": "Event name, e.g. '$pageview'. Required for EventsNode."
+ "description": "Event name, e.g. '$pageview'. Required for EventsNode."
+ },
+ "id": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Action ID. Required for ActionsNode."
+ },
+ "kind": {
+ "enum": ["EventsNode", "ActionsNode"],
+ "type": "string"
+ },
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
},
- "id": {
+ "math_group_type_index": {
"anyOf": [
{
- "type": "number"
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
},
{
"type": "null"
}
],
"default": null,
- "description": "Action ID. Required for ActionsNode."
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
},
- "kind": {
- "enum": ["EventsNode", "ActionsNode"],
- "type": "string"
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
},
"properties": {
"anyOf": [
@@ -1872,6 +2817,59 @@
"default": null,
"description": "For ratio metrics: numerator source."
},
+ "numerator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds."
+ },
"retention_window_end": {
"anyOf": [
{
@@ -1939,6 +2937,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -2102,6 +3180,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -2263,6 +3421,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -2404,6 +3642,20 @@
],
"default": null
},
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation."
+ },
"uuid": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
index af8d41425881..6adadd336724 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
@@ -98,6 +98,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -271,6 +351,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -400,6 +560,59 @@
"default": null,
"description": "For ratio metrics: denominator source."
},
+ "denominator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped."
+ },
"goal": {
"anyOf": [
{
@@ -413,11 +626,37 @@
"default": null,
"description": "Whether higher or lower values indicate success."
},
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: exclude zero values when computing the winsorization percentile thresholds."
+ },
"kind": {
"const": "ExperimentMetric",
"default": "ExperimentMetric",
"type": "string"
},
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation."
+ },
"metric_type": {
"enum": ["funnel", "mean", "ratio", "retention"],
"type": "string"
@@ -466,6 +705,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -595,6 +914,59 @@
"default": null,
"description": "For ratio metrics: numerator source."
},
+ "numerator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds."
+ },
"retention_window_end": {
"anyOf": [
{
@@ -662,6 +1034,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -825,6 +1277,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -986,6 +1518,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1127,6 +1739,20 @@
],
"default": null
},
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation."
+ },
"uuid": {
"anyOf": [
{
@@ -1189,6 +1815,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1362,6 +2068,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1478,10 +2264,63 @@
}
],
"default": null,
- "description": "Event property filters to narrow which events are counted."
+ "description": "Event property filters to narrow which events are counted."
+ }
+ },
+ "required": ["kind"],
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: denominator source."
+ },
+ "denominator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
}
},
- "required": ["kind"],
"type": "object"
},
{
@@ -1489,7 +2328,7 @@
}
],
"default": null,
- "description": "For ratio metrics: denominator source."
+ "description": "For ratio metrics: winsorization applied to the denominator aggregate. Leave unset for a binomial-style denominator, which is never clamped."
},
"goal": {
"anyOf": [
@@ -1504,11 +2343,37 @@
"default": null,
"description": "Whether higher or lower values indicate success."
},
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: exclude zero values when computing the winsorization percentile thresholds."
+ },
"kind": {
"const": "ExperimentMetric",
"default": "ExperimentMetric",
"type": "string"
},
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile). Per-user values below this percentile are clamped to it before aggregation."
+ },
"metric_type": {
"enum": ["funnel", "mean", "ratio", "retention"],
"type": "string"
@@ -1557,6 +2422,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1686,6 +2631,59 @@
"default": null,
"description": "For ratio metrics: numerator source."
},
+ "numerator_outlier_handling": {
+ "anyOf": [
+ {
+ "properties": {
+ "ignore_zeros": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null
+ },
+ "lower_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization lower percentile bound, as a fraction in [0, 1] (e.g. 0.01 for the 1st percentile)."
+ },
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile)."
+ }
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For ratio metrics: winsorization applied to the numerator aggregate, independently of the denominator and each with its own percentile thresholds."
+ },
"retention_window_end": {
"anyOf": [
{
@@ -1753,6 +2751,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -1916,6 +2994,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -2077,6 +3235,86 @@
"enum": ["EventsNode", "ActionsNode"],
"type": "string"
},
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "How to aggregate this source. Defaults to 'total' (event count). Use 'sum' together with math_property to aggregate a numeric property — e.g. a ratio numerator of revenue per order. Other options: 'avg', 'min', 'max', 'unique_session', 'dau', 'unique_group', 'hogql'."
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Group type index to aggregate over. Required when math is 'unique_group'."
+ },
+ "math_hogql": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "HogQL aggregation expression. Required when math is 'hogql' — without it the metric silently falls back to a plain count/sum."
+ },
+ "math_property": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Numeric event property to aggregate when math is 'sum', 'avg', 'min', or 'max' (e.g. 'revenue')."
+ },
"properties": {
"anyOf": [
{
@@ -2218,6 +3456,20 @@
],
"default": null
},
+ "upper_bound_percentile": {
+ "anyOf": [
+ {
+ "maximum": 1,
+ "minimum": 0,
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "For mean metrics: winsorization upper percentile bound, as a fraction in [0, 1] (e.g. 0.99 for the 99th percentile). Per-user values above this percentile are clamped to it before aggregation."
+ },
"uuid": {
"anyOf": [
{