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.

fix(marketing-analytics): expose conversion goal kind as a real enum (#75187)

Javier Bahamondes6479b6e59cbc
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index cb12fd6812eb..4f32d1c74262 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -589,6 +589,8 @@ SPECTACULAR_SETTINGS = {
"EmailReputationScopeEnum": "products.workflows.backend.models.email_reputation.EmailReputationSnapshot.Scope",
"EmailReputationStateEnum": "products.workflows.backend.models.email_reputation.EmailReputationSnapshot.State",
"MCPAuthTypeEnum": "products.mcp_store.backend.models.AUTH_TYPE_CHOICES",
+ # Shared by ConversionGoalSummary.kind and GoalExplanation.kind (same choice set).
+ "ConversionGoalKindEnum": "products.marketing_analytics.backend.hogql_queries.constants.CONVERSION_GOAL_KIND_CHOICES",
"MCPInstallationScopeEnum": ["personal", "shared"],
# Disambiguates from data_modeling's node_type (table/view/matview/endpoint).
"NotebookSQLV2NodeTypeEnum": ["hogql", "python"],
diff --git a/products/marketing_analytics/backend/api.py b/products/marketing_analytics/backend/api.py
index c0fa391cee9c..4b1238e51a88 100644
--- a/products/marketing_analytics/backend/api.py
+++ b/products/marketing_analytics/backend/api.py
@@ -25,6 +25,7 @@ from posthog.models.user import User
from products.marketing_analytics.backend.hogql_queries.adapters.base import ExternalConfig, QueryContext
from products.marketing_analytics.backend.hogql_queries.adapters.factory import MarketingSourceFactory
from products.marketing_analytics.backend.hogql_queries.adapters.self_managed import SelfManagedAdapter
+from products.marketing_analytics.backend.hogql_queries.constants import CONVERSION_GOAL_KIND_CHOICES
from products.marketing_analytics.backend.hogql_queries.utils import map_url_to_provider
from products.marketing_analytics.backend.services.conversion_goals_inspector import (
explain_conversion_goal,
@@ -109,10 +110,12 @@ class UtmAuditResponseSerializer(serializers.Serializer):
class ConversionGoalSummarySerializer(serializers.Serializer):
id = serializers.CharField(help_text="Unique id of the goal (event name, action id, or DW goal id)")
name = serializers.CharField(help_text="Display name of the conversion goal")
- # `kind` is a collision-prone enum name in drf-spectacular, so we expose it as a
- # documented string rather than a ChoiceField to avoid a CI --fail-on-warn break.
- kind = serializers.CharField(
- help_text="Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table)"
+ # `kind` collides with other enums in drf-spectacular, so it carries a stable name via
+ # ENUM_NAME_OVERRIDES ("ConversionGoalKindEnum") — a plain CharField would leave consumers
+ # reading the valid values out of this help text.
+ kind = serializers.ChoiceField(
+ choices=CONVERSION_GOAL_KIND_CHOICES,
+ help_text="Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)",
)
target_label = serializers.CharField(
help_text="Human-readable target the goal matches (event/action name or table)"
@@ -248,7 +251,10 @@ class GoalExplanationPeriodSerializer(serializers.Serializer):
class GoalExplanationSerializer(serializers.Serializer):
goal_id = serializers.CharField(help_text="Id of the explained conversion goal")
goal_name = serializers.CharField(help_text="Display name of the conversion goal")
- kind = serializers.CharField(help_text="EventsNode/ActionsNode/DataWarehouseNode")
+ kind = serializers.ChoiceField(
+ choices=CONVERSION_GOAL_KIND_CHOICES,
+ help_text="Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)",
+ )
period = GoalExplanationPeriodSerializer(help_text="The period the breakdown was computed over")
total_count = serializers.IntegerField(help_text="Total matching conversion events in the period")
integrated_count = serializers.IntegerField(
diff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.py
index 6e2de5cd4366..010725fb19f8 100644
--- a/products/marketing_analytics/backend/hogql_queries/constants.py
+++ b/products/marketing_analytics/backend/hogql_queries/constants.py
@@ -37,6 +37,7 @@ from posthog.schema import (
MetaAdsTableExclusions,
MetaAdsTableKeywords,
NativeMarketingSource,
+ NodeKind,
PinterestAdsDefaultSources,
PinterestAdsTableExclusions,
PinterestAdsTableKeywords,
@@ -60,6 +61,16 @@ from posthog.hogql import ast
DEFAULT_LIMIT = 100
PAGINATION_EXTRA = 1 # Request one extra for pagination
FALLBACK_COST_VALUE = 999999999
+# The three node kinds a conversion goal can be, derived from the schema enum so they can't drift
+# from ConversionGoalFilter1/2/3. Referenced by name from SPECTACULAR_SETTINGS["ENUM_NAME_OVERRIDES"]
+# so the API serializers can expose `kind` as a real enum: the name collides in drf-spectacular, and
+# without a stable override the generated type degrades to a plain string.
+CONVERSION_GOAL_KIND_CHOICES = [
+ NodeKind.EVENTS_NODE.value,
+ NodeKind.ACTIONS_NODE.value,
+ NodeKind.DATA_WAREHOUSE_NODE.value,
+]
+
UNKNOWN_CAMPAIGN = "Unknown Campaign"
UNKNOWN_SOURCE = "Unknown Source"
ORGANIC_CAMPAIGN = "organic"
diff --git a/products/marketing_analytics/frontend/generated/api.schemas.ts b/products/marketing_analytics/frontend/generated/api.schemas.ts
index c4a621d77aad..917caa560882 100644
--- a/products/marketing_analytics/frontend/generated/api.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.schemas.ts
@@ -7,13 +7,30 @@
* PostHog API - generated
* OpenAPI spec version: 1.0.0
*/
+/**
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode
+ */
+export type ConversionGoalKindEnumApi = (typeof ConversionGoalKindEnumApi)[keyof typeof ConversionGoalKindEnumApi]
+
+export const ConversionGoalKindEnumApi = {
+ EventsNode: 'EventsNode',
+ ActionsNode: 'ActionsNode',
+ DataWarehouseNode: 'DataWarehouseNode',
+} as const
+
export interface ConversionGoalSummaryApi {
/** Unique id of the goal (event name, action id, or DW goal id) */
id: string
/** Display name of the conversion goal */
name: string
- /** Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table) */
- kind: string
+ /** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
+ *
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode */
+ kind: ConversionGoalKindEnumApi
/** Human-readable target the goal matches (event/action name or table) */
target_label: string
/** Count of matching conversion events in the last 30 days */
@@ -271,8 +288,12 @@ export interface GoalExplanationApi {
goal_id: string
/** Display name of the conversion goal */
goal_name: string
- /** EventsNode/ActionsNode/DataWarehouseNode */
- kind: string
+ /** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
+ *
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode */
+ kind: ConversionGoalKindEnumApi
/** The period the breakdown was computed over */
period: GoalExplanationPeriodApi
/** Total matching conversion events in the period */
diff --git a/products/marketing_analytics/frontend/generated/api.zod.schemas.ts b/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
index 67d54e413cdd..89bfca8a118e 100644
--- a/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
@@ -9,13 +9,25 @@
*/
import { z as zod } from 'zod'
+export const ConversionGoalKindEnumApi = zod
+ .enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
+ .describe(
+ '\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ )
+
+export type ConversionGoalKindEnumApi = zod.input<typeof ConversionGoalKindEnumApi>
+export type ConversionGoalKindEnumApiOutput = zod.output<typeof ConversionGoalKindEnumApi>
+
export const ConversionGoalSummaryApi = zod.object({
id: zod.string().describe('Unique id of the goal (event name, action id, or DW goal id)'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
- .string()
+ .enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
+ .describe(
+ '\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ )
.describe(
- 'Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table)'
+ 'Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)\n\n\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
),
target_label: zod.string().describe('Human-readable target the goal matches (event\/action name or table)'),
last_30d_count: zod.number().describe('Count of matching conversion events in the last 30 days'),
@@ -61,9 +73,12 @@ export const ConversionGoalsListResponseApi = zod.object({
id: zod.string().describe('Unique id of the goal (event name, action id, or DW goal id)'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
- .string()
+ .enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
+ .describe(
+ '\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ )
.describe(
- 'Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table)'
+ 'Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)\n\n\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
),
target_label: zod
.string()
@@ -545,9 +560,12 @@ export const MarketingDiagnosticResponseApi = zod.object({
id: zod.string().describe('Unique id of the goal (event name, action id, or DW goal id)'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
- .string()
+ .enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
+ .describe(
+ '\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ )
.describe(
- 'Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table)'
+ 'Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)\n\n\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
),
target_label: zod
.string()
@@ -652,7 +670,14 @@ export type GoalEventSampleApiOutput = zod.output<typeof GoalEventSampleApi>
export const GoalExplanationApi = zod.object({
goal_id: zod.string().describe('Id of the explained conversion goal'),
goal_name: zod.string().describe('Display name of the conversion goal'),
- kind: zod.string().describe('EventsNode\/ActionsNode\/DataWarehouseNode'),
+ kind: zod
+ .enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
+ .describe(
+ '\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ )
+ .describe(
+ 'Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)\n\n\* `EventsNode` - EventsNode\n\* `ActionsNode` - ActionsNode\n\* `DataWarehouseNode` - DataWarehouseNode'
+ ),
period: zod
.object({
date_from: zod.string().nullable().describe('Start of the analyzed period (ISO)'),
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 81e583d0708b..258c08ee2081 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -14572,13 +14572,31 @@ export namespace Schemas {
images?: ConversationsTicketImage[] | null;
}
+ /**
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode
+ */
+ export type ConversionGoalKindEnum = typeof ConversionGoalKindEnum[keyof typeof ConversionGoalKindEnum];
+
+
+ export const ConversionGoalKindEnum = {
+ EventsNode: 'EventsNode',
+ ActionsNode: 'ActionsNode',
+ DataWarehouseNode: 'DataWarehouseNode',
+ } as const;
+
export interface ConversionGoalSummary {
/** Unique id of the goal (event name, action id, or DW goal id) */
id: string;
/** Display name of the conversion goal */
name: string;
- /** Goal type — one of: EventsNode (PostHog event), ActionsNode (PostHog action), DataWarehouseNode (external table) */
- kind: string;
+ /** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
+ *
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode */
+ kind: ConversionGoalKindEnum;
/** Human-readable target the goal matches (event/action name or table) */
target_label: string;
/** Count of matching conversion events in the last 30 days */
@@ -32590,8 +32608,12 @@ export namespace Schemas {
goal_id: string;
/** Display name of the conversion goal */
goal_name: string;
- /** EventsNode/ActionsNode/DataWarehouseNode */
- kind: string;
+ /** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
+ *
+ * * `EventsNode` - EventsNode
+ * * `ActionsNode` - ActionsNode
+ * * `DataWarehouseNode` - DataWarehouseNode */
+ kind: ConversionGoalKindEnum;
/** The period the breakdown was computed over */
period: GoalExplanationPeriod;
/** Total matching conversion events in the period */