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(marketing-analytics): add a cost per customer column (#83264)

Javier Bahamondes673e27650cdc
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index 1c22fc87ec64..f2ccfc47a30c 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -1369,7 +1369,7 @@ export type MarketingAnalyticsEventConversionGoalApiSchemaMap = { [key: string]:
export interface MarketingAnalyticsEventConversionGoalApi {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -1424,7 +1424,7 @@ export type MarketingAnalyticsActionConversionGoalApiSchemaMap = { [key: string]
export interface MarketingAnalyticsActionConversionGoalApi {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -1475,7 +1475,7 @@ export type MarketingAnalyticsWarehouseConversionGoalApiSchemaMap = { [key: stri
export interface MarketingAnalyticsWarehouseConversionGoalApi {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index e582942b9aa7..6105689343ae 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -15700,7 +15700,7 @@
"type": "string"
},
"counts_as_customer": {
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.",
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false.",
"type": "boolean"
},
"counts_as_revenue": {
@@ -15794,7 +15794,7 @@
"type": "string"
},
"counts_as_customer": {
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.",
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false.",
"type": "boolean"
},
"counts_as_revenue": {
@@ -15877,7 +15877,7 @@
"type": "string"
},
"counts_as_customer": {
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.",
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false.",
"type": "boolean"
},
"counts_as_revenue": {
@@ -33652,7 +33652,7 @@
"type": "object"
},
"MarketingAnalyticsConstants": {
- "enum": ["Goal", "Cost per", "ROAS", "const:"],
+ "enum": ["Goal", "Cost per", "ROAS", "customer", "const:"],
"type": "string"
},
"MarketingAnalyticsDrillDownConfig": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index c0c34e5f42dd..57cb3ee0fc99 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -7345,8 +7345,11 @@ export type ConversionGoalFilter = (EventsNode | ActionsNode | DataWarehouseNode
/**
* Marks this goal as customer-defining: a conversion here means the person became a customer
* (e.g. a payment or subscription), not an intermediate step like a sign up. It gates
- * customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted
- * once per person via first_time_for_user) rather than every conversion. Defaults to false.
+ * customer-based metrics such as CAC, whose denominator is this goal's conversions — its
+ * count, or its unique converters under dau math. That equals new customers only for a
+ * once-per-person moment: a repeatable event such as a monthly payment counts every time and
+ * understates cost per customer, and dedup under dau is per result row, so someone converting
+ * under two sources counts twice at channel level. Defaults to false.
*/
counts_as_customer?: boolean
/**
@@ -7525,6 +7528,7 @@ export enum MarketingAnalyticsConstants {
Goal = 'Goal',
CostPer = 'Cost per',
Roas = 'ROAS',
+ Customer = 'customer',
ConstantValuePrefix = 'const:',
}
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTableLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTableLogic.ts
index f175bad73bdc..fffcd837f251 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTableLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTableLogic.ts
@@ -21,7 +21,7 @@ import {
import { DataWarehouseSettingsTab, ExternalDataSource } from '~/types'
import { marketingAnalyticsLogic } from './marketingAnalyticsLogic'
-import { createMarketingAnalyticsOrderBy, isDraftConversionGoalColumn } from './utils'
+import { createMarketingAnalyticsOrderBy, goalSumsAProperty, isDraftConversionGoalColumn } from './utils'
export type ExternalTable = {
name: string
@@ -157,17 +157,29 @@ export const marketingAnalyticsTableLogic = kea<marketingAnalyticsTableLogicType
)
.flat()
- // ROAS divides revenue-goal value by spend, so it needs both a revenue goal and a
+ // ROAS and CAC both divide against spend, so each needs a goal flagged for it and a
// Cost column at this drill-down level.
- const roasColumn =
- featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_RETURN_METRICS] &&
+ const returnMetricsAvailable =
+ !!featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_RETURN_METRICS] &&
costAvailable &&
- !config.excludesConversionGoals &&
- conversionGoals.some((goal) => goal.counts_as_revenue)
+ !config.excludesConversionGoals
+ // Match the backend's eligibility, or a requested column the backend omits just
+ // vanishes from the table. ROAS needs a goal whose value is money, so a counting
+ // revenue goal doesn't qualify. CAC takes any customer goal: a summing one
+ // contributes its paired count column rather than its value.
+ const roasColumn =
+ returnMetricsAvailable &&
+ conversionGoals.some((goal) => goal.counts_as_revenue && goalSumsAProperty(goal))
? [MarketingAnalyticsConstants.Roas]
: []
+ const cacColumn =
+ returnMetricsAvailable && conversionGoals.some((goal) => goal.counts_as_customer)
+ ? [`${MarketingAnalyticsConstants.CostPer} ${MarketingAnalyticsConstants.Customer}`]
+ : []
- const selectColumns = [...baseColumns, ...conversionGoalColumns, ...roasColumn].filter(isNotNil)
+ const selectColumns = [...baseColumns, ...conversionGoalColumns, ...roasColumn, ...cacColumn].filter(
+ isNotNil
+ )
return selectColumns
},
],
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts
index 111dff3931d6..391790c680c4 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts
@@ -1,4 +1,5 @@
import {
+ ConversionGoalFilter,
DatabaseSchemaDataWarehouseTable,
MARKETING_INTEGRATION_CONFIGS,
MarketingAnalyticsColumnsSchemaNames,
@@ -7,6 +8,7 @@ import {
NodeKind,
VALID_NATIVE_MARKETING_SOURCES,
} from '~/queries/schema/schema-general'
+import { BaseMathType, PropertyMathType } from '~/types'
import { NativeSource } from './marketingAnalyticsLogic'
import {
@@ -14,6 +16,7 @@ import {
findSchemaByFieldName,
getEnabledNativeMarketingSources,
getOrderBy,
+ goalSumsAProperty,
getSortedColumnsByArray,
orderArrayByPreference,
rowMatchesSearch,
@@ -452,4 +455,25 @@ describe('marketing analytics utils', () => {
expect(rowMatchesSearch(record, searchTerm)).toBe(expected)
})
})
+
+ describe('goalSumsAProperty', () => {
+ const goalWithMath = (math: ConversionGoalFilter['math']): ConversionGoalFilter =>
+ ({
+ kind: NodeKind.EventsNode,
+ math,
+ conversion_goal_id: 'g',
+ conversion_goal_name: 'Goal',
+ schema_map: {},
+ }) as ConversionGoalFilter
+
+ it.each([
+ ['sum is a summed property', PropertyMathType.Sum, true],
+ ['dau counts conversions', BaseMathType.UniqueUsers, false],
+ ['total counts conversions', BaseMathType.TotalCount, false],
+ ['a *_sum math is a summed property', 'property_sum' as ConversionGoalFilter['math'], true],
+ ['undefined math counts conversions', undefined, false],
+ ])('%s', (_name, math, expected) => {
+ expect(goalSumsAProperty(goalWithMath(math))).toBe(expected)
+ })
+ })
})
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts
index 90d12b9651c5..520efe8fa2f5 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts
@@ -14,7 +14,7 @@ import {
NodeKind,
VALID_NATIVE_MARKETING_SOURCES,
} from '~/queries/schema/schema-general'
-import { HogQLMathType, ManualLinkSourceType } from '~/types'
+import { HogQLMathType, ManualLinkSourceType, PropertyMathType } from '~/types'
import { NativeSource } from './marketingAnalyticsLogic'
@@ -195,6 +195,18 @@ export function generateUniqueName(baseName: string, existingNames: string[]): s
return newName
}
+/**
+ * Mirrors the backend `goal_sums_a_property` (conversion_goal_processor.py): whether a goal's
+ * column holds a summed property value rather than a conversion count. The backend builds ROAS
+ * only from summing revenue goals and CAC only from counting customer goals, so the column gates
+ * here must apply the same test — otherwise the table requests a ratio column the backend leaves
+ * out, and it silently disappears.
+ */
+export function goalSumsAProperty(goal: ConversionGoalFilter): boolean {
+ const math = goal.math
+ return math === PropertyMathType.Sum || (typeof math === 'string' && math.endsWith('_sum'))
+}
+
export function isDraftConversionGoalColumn(column: string, draftConversionGoal: ConversionGoalFilter | null): boolean {
if (!draftConversionGoal) {
return false
diff --git a/posthog/schema.py b/posthog/schema.py
index e043f4df87e3..44a212bdeb4d 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -14874,9 +14874,13 @@ class ConversionGoalFilter1(BaseModel):
description=(
"Marks this goal as customer-defining: a conversion here means the person"
" became a customer (e.g. a payment or subscription), not an intermediate"
- " step like a sign up. It gates customer-based metrics such as CAC and"
- " LTV:CAC, whose denominator is new customers (counted once per person via"
- " first_time_for_user) rather than every conversion. Defaults to false."
+ " step like a sign up. It gates customer-based metrics such as CAC, whose"
+ " denominator is this goal's conversions — its count, or its unique"
+ " converters under dau math. That equals new customers only for a"
+ " once-per-person moment: a repeatable event such as a monthly payment"
+ " counts every time and understates cost per customer, and dedup under dau"
+ " is per result row, so someone converting under two sources counts twice"
+ " at channel level. Defaults to false."
),
)
counts_as_revenue: bool | None = Field(
@@ -14938,9 +14942,13 @@ class ConversionGoalFilter2(BaseModel):
description=(
"Marks this goal as customer-defining: a conversion here means the person"
" became a customer (e.g. a payment or subscription), not an intermediate"
- " step like a sign up. It gates customer-based metrics such as CAC and"
- " LTV:CAC, whose denominator is new customers (counted once per person via"
- " first_time_for_user) rather than every conversion. Defaults to false."
+ " step like a sign up. It gates customer-based metrics such as CAC, whose"
+ " denominator is this goal's conversions — its count, or its unique"
+ " converters under dau math. That equals new customers only for a"
+ " once-per-person moment: a repeatable event such as a monthly payment"
+ " counts every time and understates cost per customer, and dedup under dau"
+ " is per result row, so someone converting under two sources counts twice"
+ " at channel level. Defaults to false."
),
)
counts_as_revenue: bool | None = Field(
@@ -15000,9 +15008,13 @@ class ConversionGoalFilter3(BaseModel):
description=(
"Marks this goal as customer-defining: a conversion here means the person"
" became a customer (e.g. a payment or subscription), not an intermediate"
- " step like a sign up. It gates customer-based metrics such as CAC and"
- " LTV:CAC, whose denominator is new customers (counted once per person via"
- " first_time_for_user) rather than every conversion. Defaults to false."
+ " step like a sign up. It gates customer-based metrics such as CAC, whose"
+ " denominator is this goal's conversions — its count, or its unique"
+ " converters under dau math. That equals new customers only for a"
+ " once-per-person moment: a repeatable event such as a monthly payment"
+ " counts every time and understates cost per customer, and dedup under dau"
+ " is per result row, so someone converting under two sources counts twice"
+ " at channel level. Defaults to false."
),
)
counts_as_revenue: bool | None = Field(
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index afcc9332728f..3ed14ecf229b 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -3098,6 +3098,7 @@ class MarketingAnalyticsConstants(StrEnum):
GOAL = "Goal"
COST_PER = "Cost per"
ROAS = "ROAS"
+ CUSTOMER = "customer"
CONST_ = "const:"
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index a3da02d103fe..10364bf04eef 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -7054,7 +7054,7 @@ export type ConversionGoalFilter1ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter1Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -7152,7 +7152,7 @@ export type ConversionGoalFilter2ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter2Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -7246,7 +7246,7 @@ export type ConversionGoalFilter3ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter3Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
index 162cd881c709..08cfa474e39f 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
@@ -832,7 +832,8 @@
if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name,
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
- multiply(toFloat(conversion_math_value), attribution_weight) AS conversion_value
+ multiply(toFloat(conversion_math_value), attribution_weight) AS conversion_value,
+ attribution_weight
FROM
(
SELECT
@@ -948,7 +949,8 @@
if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name,
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
- multiply(1, attribution_weight) AS conversion_value
+ multiply(1, attribution_weight) AS conversion_value,
+ attribution_weight
FROM
(
SELECT
@@ -1064,7 +1066,8 @@
if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name,
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
- multiply(1, attribution_weight) AS conversion_value
+ multiply(1, attribution_weight) AS conversion_value,
+ attribution_weight
FROM
(
SELECT
@@ -1180,7 +1183,8 @@
if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name,
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
- multiply(1, attribution_weight) AS conversion_value
+ multiply(1, attribution_weight) AS conversion_value,
+ attribution_weight
FROM
(
SELECT
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
index b6723524a6cc..f0f8b8ac6d7d 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
@@ -4,7 +4,7 @@
SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source, coalesce(sum(conversion_value), 0) AS conversion_0
FROM (
- SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, multiply(1, attribution_weight) AS conversion_value
+ SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, multiply(1, attribution_weight) AS conversion_value, attribution_weight
FROM (
SELECT person_id, conversion_math_value, conversion_campaign, conversion_source, conversion_medium, conversion_content, conversion_term, conversion_referring_domain, conversion_gclid, conversion_fbclid, conversion_gad_source, filtered_utm_campaigns[tp_idx] AS fallback_campaign, filtered_utm_sources[tp_idx] AS fallback_source, filtered_utm_mediums[tp_idx] AS fallback_medium, filtered_utm_contents[tp_idx] AS fallback_content, filtered_utm_terms[tp_idx] AS fallback_term, filtered_utm_referring_domains[tp_idx] AS fallback_referring_domain, filtered_utm_gclids[tp_idx] AS fallback_gclid, filtered_utm_fbclids[tp_idx] AS fallback_fbclid, filtered_utm_gad_sources[tp_idx] AS fallback_gad_source, attribution_weights[tp_idx] AS attribution_weight
FROM (
diff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.py
index 9ccd361cb12b..79f3f4724196 100644
--- a/products/marketing_analytics/backend/hogql_queries/constants.py
+++ b/products/marketing_analytics/backend/hogql_queries/constants.py
@@ -92,6 +92,10 @@ UNKNOWN_CHANNEL = DefaultChannelTypes.UNKNOWN.value
# REPORTED_ROAS, the platform's own figure. Not a base column: it needs the goals CTE.
ROAS_COLUMN = MarketingAnalyticsConstants.ROAS.value
+# Joined to the "Cost per" prefix so it inherits that family's currency and higher-is-worse
+# formatting. Counts each customer goal's conversions as customers — see the aggregator.
+CAC_COLUMN_SUFFIX = MarketingAnalyticsConstants.CUSTOMER.value
+
# What `$entry_referring_domain` holds when a session arrived with no referrer at all. Stored as a
# sentinel rather than an empty string, so anything asking "does this session name a referrer?" has
# to test for it explicitly. Matches the literal the channel-type classifier keys off in
diff --git a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py
index be2ffdb9004f..12641957f8e1 100644
--- a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py
+++ b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py
@@ -207,6 +207,17 @@ class SharedTouchpointsPrecompute:
return self._result
+def goal_sums_a_property(goal: Union[ConversionGoalFilter1, ConversionGoalFilter2, ConversionGoalFilter3]) -> bool:
+ """Whether a goal's column holds a summed property value rather than a conversion count.
+
+ Everything that divides by a goal's column — the ROAS numerator, the CAC denominator, and the
+ processor-selection guards that decide which goals to build — needs the same answer, so they
+ all route through here rather than each re-deriving it from `math` and drifting apart.
+ """
+ math_type = goal.math
+ return math_type in ["sum", PropertyMathType.SUM] or str(math_type).endswith("_sum")
+
+
# Mutable by design: `precompute_stale` is set while building the query, and each
# processor owns a `timings` clone the runner merges back after the pool joins.
@dataclass(frozen=False)
@@ -279,11 +290,26 @@ class ConversionGoalProcessor:
def sums_a_property(self) -> bool:
"""Whether this goal's column holds a summed property value rather than a conversion count.
- Anything dividing by a goal's column needs to tell the two apart, so this shares the branch
- with `get_select_field` rather than re-deriving it from `math`.
+ Shares the branch with `get_select_field` via `goal_sums_a_property` rather than re-deriving
+ it from `math`.
"""
- math_type = self.goal.math
- return math_type in ["sum", PropertyMathType.SUM] or str(math_type).endswith("_sum")
+ return goal_sums_a_property(self.goal)
+
+ def get_count_field(self) -> ast.Expr:
+ """Conversions counted, whatever the goal's own math is.
+
+ A summing goal's column holds money, so anything needing "how many" — cost per
+ customer, say — can't divide by it.
+
+ Branches on attribution mode for the same reason `_get_aggregation_expr` does: multi-touch
+ explodes one conversion into a row per touchpoint, so counting rows would report a purchase
+ with three touchpoints as three customers. The weights sum to 1.0 per conversion, so summing
+ them recovers the count with each touchpoint credited its share. A goal that scans directly
+ never explodes and has no weight column to read.
+ """
+ if self.config.is_multi_touch and self.uses_attribution_pipeline:
+ return ast.Call(name="sum", args=[ast.Field(chain=["attribution_weight"])])
+ return ast.Call(name="count", args=[ast.Constant(value="*")])
def get_select_field(self) -> ast.Expr:
"""Build select field expression based on math aggregation type"""
@@ -396,10 +422,20 @@ class ConversionGoalProcessor:
`touchpoints` lets callers running several goals share one touchpoints materialization. When
omitted the goal materializes its own, so standalone callers keep working unchanged.
"""
- if self.goal.kind in ["EventsNode", "ActionsNode"]:
- return self._generate_array_based_query(additional_conditions, date_from, date_to, touchpoints)
+ if self.uses_attribution_pipeline:
+ return self._generate_funnel_query(additional_conditions, date_from, date_to, touchpoints)
return self._generate_direct_query(additional_conditions)
+ @property
+ def uses_attribution_pipeline(self) -> bool:
+ """Whether this goal's rows come from the attribution pipeline rather than a direct scan.
+
+ Only the pipeline emits the columns attribution adds — `attribution_weight` above all — so
+ anything reading one has to ask first. Warehouse goals and a zero-length window both scan
+ directly.
+ """
+ return self.goal.kind in ["EventsNode", "ActionsNode"] and self.config.attribution_window_days > 0
+
def build_array_collection_query(self, additional_conditions: Sequence[ast.Expr]) -> ast.SelectQuery:
"""Build the per-person array-collection subquery.
@@ -427,18 +463,6 @@ class ConversionGoalProcessor:
return self._build_final_aggregation_query(attribution)
- def _generate_array_based_query(
- self,
- additional_conditions: Sequence[ast.Expr],
- date_from: Optional[datetime] = None,
- date_to: Optional[datetime] = None,
- touchpoints: Optional[SharedTouchpointsPrecompute] = None,
- ) -> ast.SelectQuery:
- """Generate array-based query with attribution logic for Events/Actions"""
- if self.config.attribution_window_days > 0:
- return self._generate_funnel_query(additional_conditions, date_from, date_to, touchpoints)
- return self._generate_direct_query(additional_conditions)
-
def _generate_funnel_query(
self,
additional_conditions: Sequence[ast.Expr],
@@ -1751,6 +1775,9 @@ class ConversionGoalProcessor:
right=ast.Field(chain=["attribution_weight"]),
),
),
+ # Carried out of the subquery so a consumer can count conversions rather than
+ # rows: these sum to 1.0 per conversion, so summing them undoes the explode.
+ ast.Field(chain=["attribution_weight"]),
]
)
diff --git a/products/marketing_analytics/backend/hogql_queries/conversion_goals_aggregator.py b/products/marketing_analytics/backend/hogql_queries/conversion_goals_aggregator.py
index 41a64c026a94..b5f38cdd1893 100644
--- a/products/marketing_analytics/backend/hogql_queries/conversion_goals_aggregator.py
+++ b/products/marketing_analytics/backend/hogql_queries/conversion_goals_aggregator.py
@@ -11,6 +11,7 @@ from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.settings import TEST
from products.marketing_analytics.backend.hogql_queries.constants import (
+ CAC_COLUMN_SUFFIX,
ROAS_COLUMN,
UNIFIED_CONVERSION_GOALS_CTE_ALIAS,
UNKNOWN_CHANNEL,
@@ -58,6 +59,13 @@ class ConversionGoalsAggregator:
self.processors = processors
self.config = config
+ def _count_processors(self) -> list[ConversionGoalProcessor]:
+ """Customer goals whose own column holds money, so cost per customer needs a count too.
+
+ A customer goal that already counts (or uniques, for `dau`) is its own denominator.
+ """
+ return [p for p in self.processors if p.goal.counts_as_customer and p.sums_a_property()]
+
def generate_unified_cte(self, date_range: QueryDateRange, additional_conditions_getter) -> ast.CTE:
"""Generate a single CTE that contains all conversion goals aggregated by campaign/source"""
if not self.processors:
@@ -92,6 +100,8 @@ class ConversionGoalsAggregator:
else:
base_queries = [_build_base_query(p) for p in self.processors]
+ count_processors = self._count_processors()
+
conversion_subqueries = []
for processor, base_query in zip(self.processors, base_queries):
# Transform the query to include a column for this specific conversion goal
@@ -127,6 +137,17 @@ class ConversionGoalsAggregator:
)
)
+ # Every subquery in the UNION has to carry the same columns, so the count
+ # rides along for all of them, actual for its owner and 0 elsewhere. Same
+ # grouping as the value column, so it counts that goal's conversions.
+ if p in count_processors:
+ enhanced_select.append(
+ ast.Alias(
+ alias=self.config.get_conversion_goal_count_column_name(p.index),
+ expr=p.get_count_field() if p.index == processor.index else ast.Constant(value=0),
+ )
+ )
+
enhanced_query = ast.SelectQuery(
select=enhanced_select,
select_from=base_query.select_from,
@@ -196,6 +217,7 @@ class ConversionGoalsAggregator:
]
# Add each conversion goal as a summed column
+ count_processors = self._count_processors()
for processor in self.processors:
final_select.append(
ast.Alias(
@@ -210,6 +232,14 @@ class ConversionGoalsAggregator:
),
)
)
+ if processor in count_processors:
+ count_column = self.config.get_conversion_goal_count_column_name(processor.index)
+ final_select.append(
+ ast.Alias(
+ alias=count_column,
+ expr=ast.Call(name="sum", args=[ast.Field(chain=[subquery_alias, count_column])]),
+ )
+ )
final_query = ast.SelectQuery(
select=final_select,
@@ -400,14 +430,20 @@ class ConversionGoalsAggregator:
)
columns[f"{self.config.cost_per_prefix} {goal_name}"] = cost_per_goal_alias
- # Needs campaign_costs joined, since spend is the denominator. A flagged goal only
- # contributes if its column holds money — a counting one would render 200 signups against
- # $100 of spend as "ROAS 2.0".
+ # Both need campaign_costs joined, since spend is the denominator. ROAS also needs the
+ # goal to hold money: a counting goal in its numerator reads 200 signups against $100
+ # as "ROAS 2.0". CAC has no such restriction — a summing goal contributes its count
+ # column instead of its value, so a purchase goal flagged as both still works.
if include_cost_per:
revenue_processors = [p for p in self.processors if p.goal.counts_as_revenue and p.sums_a_property()]
if revenue_processors:
columns[ROAS_COLUMN] = self._build_roas_column(revenue_processors)
+ customer_processors = [p for p in self.processors if p.goal.counts_as_customer]
+ if customer_processors:
+ cac_alias = f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}"
+ columns[cac_alias] = self._build_cac_column(customer_processors, cac_alias)
+
return columns
def _build_roas_column(self, revenue_processors: list[ConversionGoalProcessor]) -> ast.Alias:
@@ -428,16 +464,41 @@ class ConversionGoalsAggregator:
),
)
- def _sum_conversion_values(self, processors: list[ConversionGoalProcessor]) -> ast.Expr:
- """Sum the unified-CTE value columns of the given goals into one expression."""
- fields = [
- ast.Field(
- chain=self.config.get_unified_conversion_field_chain(
- self.config.get_conversion_goal_column_name(p.index)
- )
- )
- for p in processors
- ]
+ def _build_cac_column(self, customer_processors: list[ConversionGoalProcessor], alias: str) -> ast.Alias:
+ # Each customer goal contributes its conversion count, which is right only for a
+ # once-per-person moment: a repeatable event overcounts, and `dau` is the closest fit.
+ total_customers = self._sum_conversion_values(customer_processors, prefer_count=True)
+ total_cost = ast.Field(chain=self.config.get_campaign_cost_field_chain(self.config.total_cost_field))
+ return ast.Alias(
+ alias=alias,
+ expr=ast.Call(
+ name="round",
+ args=[
+ ast.ArithmeticOperation(
+ left=total_cost,
+ op=ast.ArithmeticOperationOp.Div,
+ right=ast.Call(name="nullif", args=[total_customers, ast.Constant(value=0)]),
+ ),
+ ast.Constant(value=2),
+ ],
+ ),
+ )
+
+ def _sum_conversion_values(
+ self, processors: list[ConversionGoalProcessor], *, prefer_count: bool = False
+ ) -> ast.Expr:
+ """Sum the unified-CTE columns of the given goals into one expression.
+
+ With `prefer_count`, a goal whose own column holds a summed amount contributes its
+ paired count column instead — the only way a summing goal can answer "how many".
+ """
+
+ def column_for(p: ConversionGoalProcessor) -> str:
+ if prefer_count and p.sums_a_property():
+ return self.config.get_conversion_goal_count_column_name(p.index)
+ return self.config.get_conversion_goal_column_name(p.index)
+
+ fields = [ast.Field(chain=self.config.get_unified_conversion_field_chain(column_for(p))) for p in processors]
total: ast.Expr = fields[0]
for field in fields[1:]:
total = ast.ArithmeticOperation(left=total, op=ast.ArithmeticOperationOp.Add, right=field)
diff --git a/products/marketing_analytics/backend/hogql_queries/marketing_analytics_base_query_runner.py b/products/marketing_analytics/backend/hogql_queries/marketing_analytics_base_query_runner.py
index 5d94fbcafa63..024470ee94ce 100644
--- a/products/marketing_analytics/backend/hogql_queries/marketing_analytics_base_query_runner.py
+++ b/products/marketing_analytics/backend/hogql_queries/marketing_analytics_base_query_runner.py
@@ -40,6 +40,7 @@ from products.analytics_platform.backend.lazy_computation.lazy_computation_execu
)
from products.analytics_platform.backend.lazy_computation.stale_policy import is_background_warming_request
from products.marketing_analytics.backend.hogql_queries.constants import (
+ CAC_COLUMN_SUFFIX,
CHANNEL_SESSIONS_CTE_NAME,
DRILL_DOWN_LEVEL_CONFIG,
ROAS_COLUMN,
@@ -56,7 +57,7 @@ from products.warehouse_sources.backend.facade.hogql import get_view_or_table_by
from .adapters.base import MarketingSourceAdapter, QueryContext
from .adapters.factory import MarketingSourceFactory
-from .conversion_goal_processor import ConversionGoalProcessor
+from .conversion_goal_processor import ConversionGoalProcessor, goal_sums_a_property
from .conversion_goals_aggregator import ConversionGoalsAggregator
from .marketing_analytics_config import MarketingAnalyticsConfig
from .utils import build_source_normalization_expr, convert_team_conversion_goals_to_objects
@@ -855,15 +856,22 @@ class MarketingAnalyticsBaseQueryRunner(AnalyticsQueryRunner[ResponseType], ABC,
) -> list:
"""Create conversion goal processors for reuse across different methods"""
processors = []
- # Needed even when the goals' own columns are hidden, or the ratio changes value as
+ # Needed even when the goals' own columns are hidden, or the ratios change value as
# columns are added or removed.
roas_selected = self.query.select is not None and ROAS_COLUMN in self.query.select
+ cac_selected = (
+ self.query.select is not None
+ and f"{MarketingAnalyticsConstants.COST_PER} {CAC_COLUMN_SUFFIX}" in self.query.select
+ )
for index, conversion_goal in enumerate(conversion_goals):
# Create processor if select is None (all columns) or if conversion goal columns are explicitly selected
should_create = self.query.select is None or (
conversion_goal.conversion_goal_name in self.query.select
or f"{MarketingAnalyticsConstants.COST_PER} {conversion_goal.conversion_goal_name}" in self.query.select
- or (roas_selected and conversion_goal.counts_as_revenue)
+ or (roas_selected and conversion_goal.counts_as_revenue and goal_sums_a_property(conversion_goal))
+ # No sum-math exclusion here: CAC divides by a summing goal's count column,
+ # so dropping its processor would drop the denominator with it.
+ or (cac_selected and conversion_goal.counts_as_customer)
)
if should_create:
processor = ConversionGoalProcessor(
diff --git a/products/marketing_analytics/backend/hogql_queries/marketing_analytics_config.py b/products/marketing_analytics/backend/hogql_queries/marketing_analytics_config.py
index bcf36af6db9b..99edf8addc82 100644
--- a/products/marketing_analytics/backend/hogql_queries/marketing_analytics_config.py
+++ b/products/marketing_analytics/backend/hogql_queries/marketing_analytics_config.py
@@ -51,7 +51,9 @@ MULTI_TOUCH_MODES: frozenset[AttributionMode] = frozenset(
)
-@dataclass
+# Mutable by design: `from_team` builds a default instance and then overwrites the
+# team-derived fields on it, rather than threading them all through the constructor.
+@dataclass(frozen=False)
class MarketingAnalyticsConfig:
"""
Configuration object that centralizes all constants and naming conventions
@@ -260,6 +262,10 @@ class MarketingAnalyticsConfig:
"""Get standardized conversion goal column name"""
return f"{self.conversion_goal_prefix}{index}"
+ def get_conversion_goal_count_column_name(self, index: int) -> str:
+ """Conversions counted, for goals whose own column holds a summed amount instead."""
+ return f"{self.conversion_goal_prefix}{index}_count"
+
def get_conversion_goal_alias(self, index: int) -> str:
"""Get conversion goal CTE alias"""
return f"{self.conversion_goal_abbreviation}{index}"
diff --git a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
index 1a933af9f15c..9292c2437f2a 100644
--- a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
+++ b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
@@ -5919,6 +5919,72 @@ class TestConversionGoalProcessor(ClickhouseTestMixin, BaseTest):
assert abs(row[4] - 100.0) < 1.0, f"Each touchpoint should get ~$100, got {row[4]}"
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot
+ def test_multi_touch_count_field_counts_conversions_not_touchpoint_rows(self):
+ """One purchase across three touchpoints is one customer, not three.
+
+ `count(*)` here runs over the exploded rows, and cost per customer divides spend by it —
+ so counting rows reports a third of the true figure with nothing to signal it.
+ """
+ self._create_multi_touch_scenario()
+
+ goal = ConversionGoalFilter1(
+ kind="EventsNode",
+ event="purchase",
+ conversion_goal_id="mt_count",
+ conversion_goal_name="Multi Touch count",
+ math=PropertyMathType.SUM,
+ math_property="revenue",
+ counts_as_customer=True,
+ schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
+ )
+ config = MarketingAnalyticsConfig()
+ config.attribution_mode = AttributionMode.LINEAR
+ config.attribution_window_days = 90
+
+ processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=config)
+
+ date_conditions: list[ast.Expr] = [
+ ast.CompareOperation(
+ left=ast.Field(chain=["events", "timestamp"]),
+ op=ast.CompareOperationOp.GtEq,
+ right=ast.Call(name="toDate", args=[ast.Constant(value="2023-03-01")]),
+ ),
+ ast.CompareOperation(
+ left=ast.Field(chain=["events", "timestamp"]),
+ op=ast.CompareOperationOp.LtEq,
+ right=ast.Call(name="toDate", args=[ast.Constant(value="2023-03-31")]),
+ ),
+ ]
+ cte_query = processor.generate_cte_query(date_conditions)
+ # Same shape the aggregator builds: the count rides along on the value query's grouping.
+ cte_query.select.append(ast.Alias(alias="conversions", expr=processor.get_count_field()))
+ response = execute_hogql_query(query=cte_query, team=self.team)
+
+ assert len(response.results) == 3, f"Expected 3 touchpoint rows, got {len(response.results)}"
+ total_conversions = sum(row[-1] for row in response.results)
+ assert abs(total_conversions - 1.0) < 0.01, f"One purchase is one customer, got {total_conversions}"
+
+ def test_count_field_stays_a_row_count_for_a_goal_that_scans_directly(self):
+ """A zero-length window skips the attribution pipeline, so there are no exploded rows
+ and no `attribution_weight` column to read — even with a multi-touch mode selected."""
+ goal = ConversionGoalFilter1(
+ kind="EventsNode",
+ event="purchase",
+ conversion_goal_id="direct",
+ conversion_goal_name="Direct scan",
+ math=PropertyMathType.SUM,
+ math_property="revenue",
+ schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
+ )
+ config = MarketingAnalyticsConfig()
+ config.attribution_mode = AttributionMode.LINEAR
+ config.attribution_window_days = 0
+
+ processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=config)
+
+ assert processor.uses_attribution_pipeline is False
+ assert "attribution_weight" not in processor.get_count_field().to_hogql()
+
def test_multi_touch_dau_counts_unique_users_per_campaign(self):
self._create_multi_touch_scenario()
diff --git a/products/marketing_analytics/backend/hogql_queries/test_conversion_goals_aggregator.py b/products/marketing_analytics/backend/hogql_queries/test_conversion_goals_aggregator.py
index 68d9654e89ee..6283c86481d8 100644
--- a/products/marketing_analytics/backend/hogql_queries/test_conversion_goals_aggregator.py
+++ b/products/marketing_analytics/backend/hogql_queries/test_conversion_goals_aggregator.py
@@ -34,7 +34,7 @@ from products.analytics_platform.backend.lazy_computation.lazy_computation_execu
)
from products.analytics_platform.backend.models.preaggregation_job import PreaggregationJob
-from .constants import ROAS_COLUMN
+from .constants import CAC_COLUMN_SUFFIX, ROAS_COLUMN
from .conversion_goal_processor import ConversionGoalProcessor, SharedTouchpointsPrecompute
from .conversion_goals_aggregator import ConversionGoalsAggregator, _map_in_caller_context
from .marketing_analytics_config import MarketingAnalyticsConfig
@@ -104,6 +104,7 @@ class TestConversionGoalsAggregator(ClickhouseTestMixin, BaseTest):
math: BaseMathType | PropertyMathType = BaseMathType.TOTAL,
math_property: str | None = None,
counts_as_revenue: bool | None = None,
+ counts_as_customer: bool | None = None,
) -> ConversionGoalFilter1:
return ConversionGoalFilter1(
kind="EventsNode",
@@ -113,6 +114,7 @@ class TestConversionGoalsAggregator(ClickhouseTestMixin, BaseTest):
math=math,
math_property=math_property,
counts_as_revenue=counts_as_revenue,
+ counts_as_customer=counts_as_customer,
schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
)
@@ -357,6 +359,92 @@ class TestConversionGoalsAggregator(ClickhouseTestMixin, BaseTest):
assert self.config.get_conversion_goal_column_name(0) not in roas
assert self.config.total_cost_field in roas
+ def test_cac_column_absent_when_no_goal_is_a_customer_goal(self):
+ goal = self._create_test_conversion_goal("plain", "Plain Goal")
+ aggregator = ConversionGoalsAggregator(processors=[self._create_test_processor(goal, 0)], config=self.config)
+
+ columns = aggregator.get_conversion_goal_columns()
+
+ assert f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}" not in columns
+
+ def test_cac_column_absent_without_campaign_costs(self):
+ goal = self._create_test_conversion_goal("cust", "Customer Goal", counts_as_customer=True)
+ aggregator = ConversionGoalsAggregator(processors=[self._create_test_processor(goal, 0)], config=self.config)
+
+ columns = aggregator.get_conversion_goal_columns(include_cost_per=False)
+
+ assert f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}" not in columns
+
+ def test_cac_divides_spend_by_only_the_customer_goals(self):
+ goals = [
+ self._create_test_conversion_goal("g0", "Pageviews"),
+ self._create_test_conversion_goal("g1", "Signups", counts_as_customer=True),
+ self._create_test_conversion_goal("g2", "Trials"),
+ self._create_test_conversion_goal("g3", "Purchases", counts_as_customer=True),
+ ]
+ processors = [self._create_test_processor(goal, i) for i, goal in enumerate(goals)]
+ aggregator = ConversionGoalsAggregator(processors=processors, config=self.config)
+
+ cac_alias = f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}"
+ cac_expr = aggregator.get_conversion_goal_columns()[cac_alias].expr
+ cac = cac_expr.to_hogql()
+
+ # Customer goals sit at indices 1 and 3; the non-customer goals at 0 and 2 must not count
+ assert self.config.get_conversion_goal_column_name(1) in cac
+ assert self.config.get_conversion_goal_column_name(3) in cac
+ assert self.config.get_conversion_goal_column_name(0) not in cac
+ assert self.config.get_conversion_goal_column_name(2) not in cac
+ # Cost is the numerator for CAC (spend per customer), the inverse of ROAS
+ assert isinstance(cac_expr, ast.Call)
+ division = cac_expr.args[0]
+ assert isinstance(division, ast.ArithmeticOperation)
+ assert division.op == ast.ArithmeticOperationOp.Div
+ assert isinstance(division.left, ast.Field)
+ assert division.left.chain[-1] == self.config.total_cost_field
+
+ def test_cac_divides_by_the_count_of_a_customer_goal_that_sums_money(self):
+ goals = [
+ # A purchase goal flagged as both. Its own column holds revenue, so the
+ # denominator has to be its paired count or CAC becomes spend over revenue.
+ self._create_test_conversion_goal(
+ "g0",
+ "Purchases",
+ math=PropertyMathType.SUM,
+ math_property="revenue",
+ counts_as_customer=True,
+ counts_as_revenue=True,
+ ),
+ self._create_test_conversion_goal("g1", "Signups", counts_as_customer=True),
+ ]
+ processors = [self._create_test_processor(goal, i) for i, goal in enumerate(goals)]
+ aggregator = ConversionGoalsAggregator(processors=processors, config=self.config)
+
+ cac_alias = f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}"
+ cac = aggregator.get_conversion_goal_columns()[cac_alias].expr.to_hogql()
+
+ assert self.config.get_conversion_goal_count_column_name(0) in cac
+ # The counting goal is already its own denominator, so it gets no count column.
+ assert self.config.get_conversion_goal_column_name(1) in cac
+ assert self.config.get_conversion_goal_count_column_name(1) not in cac
+
+ def test_cac_exists_when_every_customer_goal_sums_money(self):
+ # The default shape: the only customer goal is a purchase goal with sum math.
+ # This used to emit no column while the frontend still requested one.
+ goal = self._create_test_conversion_goal(
+ "g0",
+ "Purchases",
+ math=PropertyMathType.SUM,
+ math_property="revenue",
+ counts_as_customer=True,
+ counts_as_revenue=True,
+ )
+ aggregator = ConversionGoalsAggregator(processors=[self._create_test_processor(goal, 0)], config=self.config)
+
+ columns = aggregator.get_conversion_goal_columns()
+
+ assert f"{self.config.cost_per_prefix} {CAC_COLUMN_SUFFIX}" in columns
+ assert ROAS_COLUMN in columns
+
def test_roas_numerator_skips_revenue_goals_that_count_instead_of_summing(self):
goals = [
# Flagged as revenue but counts conversions, so its column holds a count, not money.
diff --git a/products/marketing_analytics/frontend/generated/api.schemas.ts b/products/marketing_analytics/frontend/generated/api.schemas.ts
index ebf2e3a96187..e6444ed13dd7 100644
--- a/products/marketing_analytics/frontend/generated/api.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.schemas.ts
@@ -645,7 +645,7 @@ export type ConversionGoalFilter1ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter1Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -743,7 +743,7 @@ export type ConversionGoalFilter2ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter2Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -837,7 +837,7 @@ export type ConversionGoalFilter3ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter3Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 6610fb1bb900..f8bd3f44d77d 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -6216,7 +6216,7 @@ export type ConversionGoalFilter1ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter1Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -6314,7 +6314,7 @@ export type ConversionGoalFilter2ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter2Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
@@ -6408,7 +6408,7 @@ export type ConversionGoalFilter3ApiSchemaMap = { [key: string]: string | unknow
export interface ConversionGoalFilter3Api {
conversion_goal_id: string
conversion_goal_name: string
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 7eee34cb9185..5f902e484250 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -7325,7 +7325,7 @@ export namespace Schemas {
export interface ConversionGoalFilter1 {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
@@ -7362,7 +7362,7 @@ export namespace Schemas {
export interface ConversionGoalFilter2 {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
@@ -7395,7 +7395,7 @@ export namespace Schemas {
export interface ConversionGoalFilter3 {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
@@ -48172,7 +48172,7 @@ export namespace Schemas {
export interface MarketingAnalyticsActionConversionGoal {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
@@ -48215,7 +48215,7 @@ export namespace Schemas {
export interface MarketingAnalyticsEventConversionGoal {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
@@ -48252,7 +48252,7 @@ export namespace Schemas {
export interface MarketingAnalyticsWarehouseConversionGoal {
conversion_goal_id: string;
conversion_goal_name: string;
- /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false. */
+ /** Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false. */
counts_as_customer?: boolean | null;
/** Marks this goal as revenue-bearing: the value of a conversion is a monetary amount, not a count or an arbitrary numeric property. It gates revenue metrics such as ROAS and LTV:CAC. The amount itself comes from math_property, and its currency from math_property_revenue_currency, the same shape Revenue analytics uses for revenue events. Independent of counts_as_customer: a purchase is usually both, a trial signup neither. Defaults to false. */
counts_as_revenue?: boolean | null;
diff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.ts
index 34e263836268..85cf32ba3088 100644
--- a/services/mcp/src/generated/core/api.ts
+++ b/services/mcp/src/generated/core/api.ts
@@ -469,7 +469,7 @@ export const OrganizationsProjectsPartialUpdateBody = /* @__PURE__ */ zod
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
@@ -1109,7 +1109,7 @@ export const OrganizationsProjectsPartialUpdateBody = /* @__PURE__ */ zod
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
@@ -1741,7 +1741,7 @@ export const OrganizationsProjectsPartialUpdateBody = /* @__PURE__ */ zod
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
diff --git a/services/mcp/src/generated/marketing_analytics/api.ts b/services/mcp/src/generated/marketing_analytics/api.ts
index 9419cb17a6ab..10195d04e769 100644
--- a/services/mcp/src/generated/marketing_analytics/api.ts
+++ b/services/mcp/src/generated/marketing_analytics/api.ts
@@ -8534,7 +8534,7 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = /* @__PURE__ */
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
@@ -11253,7 +11253,7 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = /* @__PURE__ */
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
@@ -13967,7 +13967,7 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = /* @__PURE__ */
.union([zod.boolean(), zod.null()])
.optional()
.describe(
- 'Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false.'
+ "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
),
counts_as_revenue: zod
.union([zod.boolean(), zod.null()])
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
index c51239253256..d910f056c279 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
@@ -520,7 +520,7 @@
"type": "null"
}
],
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false."
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
},
"counts_as_revenue": {
"anyOf": [
@@ -1570,7 +1570,7 @@
"type": "null"
}
],
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false."
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
},
"counts_as_revenue": {
"anyOf": [
@@ -2589,7 +2589,7 @@
"type": "null"
}
],
- "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC and LTV:CAC, whose denominator is new customers (counted once per person via first_time_for_user) rather than every conversion. Defaults to false."
+ "description": "Marks this goal as customer-defining: a conversion here means the person became a customer (e.g. a payment or subscription), not an intermediate step like a sign up. It gates customer-based metrics such as CAC, whose denominator is this goal's conversions — its count, or its unique converters under dau math. That equals new customers only for a once-per-person moment: a repeatable event such as a monthly payment counts every time and understates cost per customer, and dedup under dau is per result row, so someone converting under two sources counts twice at channel level. Defaults to false."
},
"counts_as_revenue": {
"anyOf": [