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): one name for the conversion goal id (#82198)

Javier Bahamondesd4bb1479d2e4
diff --git a/products/marketing_analytics/backend/api.py b/products/marketing_analytics/backend/api.py
index 01340b5ee345..4fc68f401692 100644
--- a/products/marketing_analytics/backend/api.py
+++ b/products/marketing_analytics/backend/api.py
@@ -201,7 +201,9 @@ 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)")
+ conversion_goal_id = serializers.CharField(
+ help_text="Id of the goal. Pass this to the explain, update and delete endpoints."
+ )
name = serializers.CharField(help_text="Display name of the conversion goal")
# `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
@@ -471,8 +473,9 @@ class DataSourceHealthResponseSerializer(serializers.Serializer):
class ExplainConversionGoalQuerySerializer(serializers.Serializer):
- goal_id = serializers.CharField(
- required=True, help_text="Id of the conversion goal to explain (from list_conversion_goals)."
+ conversion_goal_id = serializers.CharField(
+ required=True,
+ help_text=("conversion_goal_id of the goal to explain, as returned by the conversion_goals list endpoint."),
)
date_from = serializers.CharField(
required=False, default=None, allow_null=True, help_text="ISO start; defaults to 30 days ago"
@@ -495,7 +498,7 @@ class GoalExplanationPeriodSerializer(serializers.Serializer):
class GoalExplanationSerializer(serializers.Serializer):
- goal_id = serializers.CharField(help_text="Id of the explained conversion goal")
+ conversion_goal_id = serializers.CharField(help_text="conversion_goal_id of the explained goal")
goal_name = serializers.CharField(help_text="Display name of the conversion goal")
kind = serializers.ChoiceField(
choices=CONVERSION_GOAL_KIND_CHOICES,
@@ -1328,7 +1331,7 @@ class MarketingAnalyticsViewSet(TeamAndOrgViewSetMixin, GenericViewSet):
methods=["GET"], detail=False, url_path="explain_conversion_goal", required_scopes=["marketing_analytics:read"]
)
def explain_conversion_goal(self, request: Request, *args, **kwargs) -> Response:
- goal_id = request.validated_query_data["goal_id"]
+ goal_id = request.validated_query_data["conversion_goal_id"]
date_from = request.validated_query_data["date_from"]
date_to = request.validated_query_data["date_to"]
period = DateRange(date_from=date_from, date_to=date_to) if (date_from or date_to) else None
diff --git a/products/marketing_analytics/backend/max_tools.py b/products/marketing_analytics/backend/max_tools.py
index 2d0f5e82c0e0..93425e48a4ec 100644
--- a/products/marketing_analytics/backend/max_tools.py
+++ b/products/marketing_analytics/backend/max_tools.py
@@ -164,8 +164,11 @@ class MarketingDiagnoseSetupTool(MaxTool):
class MarketingExplainConversionGoalArgs(BaseModel):
- goal_id: str = Field(
- description="The id of the conversion goal to explain. Must match an id from `marketing_list_conversion_goals`.",
+ conversion_goal_id: str = Field(
+ description=(
+ "The conversion_goal_id of the goal to explain, taken from the "
+ "`conversion_goal_id` field of a `marketing_list_conversion_goals` result."
+ ),
)
date_from: str | None = Field(
default=None,
@@ -195,15 +198,18 @@ class MarketingExplainConversionGoalTool(MaxTool):
return _marketing_resource()
async def _arun_impl(
- self, goal_id: str, date_from: str | None = None, date_to: str | None = None
+ self, conversion_goal_id: str, date_from: str | None = None, date_to: str | None = None
) -> tuple[str, dict[str, Any]]:
period = None
if date_from or date_to:
period = DateRange(date_from=date_from, date_to=date_to)
try:
- response = await explain_conversion_goal(self._team, goal_id, period=period)
+ response = await explain_conversion_goal(self._team, conversion_goal_id, period=period)
except ValueError as exc:
- return f"Could not explain goal: {exc}", {"error": "goal_not_found", "goal_id": goal_id}
+ return f"Could not explain goal: {exc}", {
+ "error": "goal_not_found",
+ "conversion_goal_id": conversion_goal_id,
+ }
return _format_explain_goal_for_llm(response), response.to_dict()
@@ -535,7 +541,7 @@ _NON_INTEGRATED_SPLIT_INSTRUCTIONS = dedent("""
def _format_goal_line(goal, *, include_id: bool = False) -> str:
- head = f"- id=`{goal.id}` " if include_id else "- "
+ head = f"- conversion_goal_id=`{goal.conversion_goal_id}` " if include_id else "- "
line = f"{head}**{goal.name}** (`{goal.kind}`, target=`{goal.target_label}`) — last_30d={goal.last_30d_count}"
if goal.integrated_count is not None and goal.non_integrated_count is not None:
line += (
diff --git a/products/marketing_analytics/backend/services/conversion_goals_inspector.py b/products/marketing_analytics/backend/services/conversion_goals_inspector.py
index 93c8f2f0603e..4de00a146658 100644
--- a/products/marketing_analytics/backend/services/conversion_goals_inspector.py
+++ b/products/marketing_analytics/backend/services/conversion_goals_inspector.py
@@ -61,7 +61,7 @@ EXPLAIN_EVENT_SCAN_LIMIT = 5000
@dataclass
class ConversionGoalSummary:
- id: str
+ conversion_goal_id: str
name: str
kind: GoalKind
target_label: str
@@ -109,7 +109,7 @@ class GoalEventSample:
@dataclass
class GoalExplanation:
- goal_id: str
+ conversion_goal_id: str
goal_name: str
kind: GoalKind
period: DateRange
@@ -159,7 +159,7 @@ async def list_conversion_goals(team: Team, *, user: User | None = None) -> Conv
def _failed_goal_summary(goal: dict[str, Any], exc: BaseException) -> ConversionGoalSummary:
goal_id = str(goal.get("conversion_goal_id") or goal.get("id") or "")
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=goal.get("conversion_goal_name") or goal.get("name") or goal_id,
kind=cast(GoalKind, goal.get("kind", "EventsNode")),
target_label="(unavailable)",
@@ -193,7 +193,7 @@ async def explain_conversion_goal(
if kind == "DataWarehouseNode":
return GoalExplanation(
- goal_id=goal_id,
+ conversion_goal_id=goal_id,
goal_name=name,
kind=kind,
period=resolved_period,
@@ -265,7 +265,7 @@ async def explain_conversion_goal(
)
return GoalExplanation(
- goal_id=goal_id,
+ conversion_goal_id=goal_id,
goal_name=name,
kind=kind,
period=resolved_period,
@@ -350,7 +350,7 @@ async def _summarize_goal(
action, action_error = await _resolve_action(team, target_id)
if action is None:
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=name,
kind=kind,
target_label=f"Action #{goal_id}",
@@ -380,7 +380,7 @@ async def _summarize_goal(
target_label = f"{table_name}"
last_30d_count, dw_misconfig = await _count_dw_goal(team, goal, user=user)
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=name,
kind=kind,
target_label=target_label,
@@ -397,7 +397,7 @@ async def _summarize_goal(
)
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=name,
kind=kind,
target_label="(unknown kind)",
@@ -432,7 +432,7 @@ def _summary_with_split(
) -> ConversionGoalSummary:
integrated_pct = round((counts.integrated / counts.total) * 100, 2) if counts.total > 0 else 0.0
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=name,
kind=kind,
target_label=target_label,
diff --git a/products/marketing_analytics/backend/services/setup_plan.py b/products/marketing_analytics/backend/services/setup_plan.py
index 2e5c96b725f7..85dd2fd3735f 100644
--- a/products/marketing_analytics/backend/services/setup_plan.py
+++ b/products/marketing_analytics/backend/services/setup_plan.py
@@ -500,9 +500,9 @@ def _conversion_goal_suggestions(
if goal.is_misconfigured:
suggestions.append(_fix_goal_suggestion(goal))
- if not any(goal_flags.get(g.id, {}).get("counts_as_revenue") for g in goals.goals):
+ if not any(goal_flags.get(g.conversion_goal_id, {}).get("counts_as_revenue") for g in goals.goals):
suggestions.append(_missing_flag_suggestion(goals.goals, goal_flags, revenue=True))
- if not any(goal_flags.get(g.id, {}).get("counts_as_customer") for g in goals.goals):
+ if not any(goal_flags.get(g.conversion_goal_id, {}).get("counts_as_customer") for g in goals.goals):
suggestions.append(_missing_flag_suggestion(goals.goals, goal_flags, revenue=False))
return [s for s in suggestions if s is not None]
@@ -551,7 +551,7 @@ def _create_goal_suggestions(candidates: EventSuggestionsResponse | None) -> lis
def _fix_goal_suggestion(goal: ConversionGoalSummary) -> Suggestion:
return Suggestion(
- id=f"fix_conversion_goal:{goal.id}",
+ id=f"fix_conversion_goal:{goal.conversion_goal_id}",
kind=SuggestionKind.FIX_CONVERSION_GOAL,
severity=Severity.ERROR,
confidence=0.95,
@@ -596,7 +596,7 @@ def _missing_flag_suggestion(
),
unlocks=[Capability.ROAS if revenue else Capability.CAC],
# Which goal counts as revenue is a business decision, not a config fix.
- apply=UpdateConversionGoal(conversion_goal_id=candidate.id, patch={flag: True}),
+ apply=UpdateConversionGoal(conversion_goal_id=candidate.conversion_goal_id, patch={flag: True}),
safe_to_batch=False,
event_volume=candidate.last_30d_count,
)
diff --git a/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py b/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py
index eda7e69f6896..83b4c7e52596 100644
--- a/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py
+++ b/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py
@@ -112,7 +112,7 @@ class TestListConversionGoals(_InspectorMixin):
assert response.attribution_mode == "first_touch"
assert len(response.goals) == 1
goal = response.goals[0]
- assert goal.id == "purchase"
+ assert goal.conversion_goal_id == "purchase"
assert goal.kind == "EventsNode"
assert goal.target_label == "purchase"
assert goal.last_30d_count == 200
@@ -166,7 +166,7 @@ class TestListConversionGoals(_InspectorMixin):
assert response.goals[0].is_misconfigured is False
# The summary still identifies the goal by its own id, which is what the setup
# plan uses to open the right editor.
- assert response.goals[0].id == "cg_demos"
+ assert response.goals[0].conversion_goal_id == "cg_demos"
@pytest.mark.asyncio
async def test_actions_node_with_resolved_action_uses_action_name(self):
@@ -585,7 +585,7 @@ class TestListGoalCountsClickhouse(ClickhouseTestMixin, BaseTest):
assert len(response.goals) == 1
goal = response.goals[0]
- assert goal.id == "signup"
+ assert goal.conversion_goal_id == "signup"
assert goal.kind == "EventsNode"
assert goal.last_30d_count == 3
assert goal.integrated_count == 3
diff --git a/products/marketing_analytics/backend/services/test_marketing_diagnostic.py b/products/marketing_analytics/backend/services/test_marketing_diagnostic.py
index 82263f7474b2..cd6a6ee44cae 100644
--- a/products/marketing_analytics/backend/services/test_marketing_diagnostic.py
+++ b/products/marketing_analytics/backend/services/test_marketing_diagnostic.py
@@ -207,7 +207,7 @@ class TestGetMarketingDiagnostic(APIBaseTest):
@pytest.mark.asyncio
async def test_misconfigured_goals_surface_in_global_actions(self):
goal = ConversionGoalSummary(
- id="999",
+ conversion_goal_id="999",
name="Sign up",
kind="ActionsNode",
target_label="Action #999",
diff --git a/products/marketing_analytics/backend/services/test_setup_plan.py b/products/marketing_analytics/backend/services/test_setup_plan.py
index 2e5accba90a4..e5f8aea09c27 100644
--- a/products/marketing_analytics/backend/services/test_setup_plan.py
+++ b/products/marketing_analytics/backend/services/test_setup_plan.py
@@ -95,7 +95,7 @@ def _integration(
def _goal(goal_id="g1", name="Signup", count=1000, misconfigured=False) -> ConversionGoalSummary:
return ConversionGoalSummary(
- id=goal_id,
+ conversion_goal_id=goal_id,
name=name,
# What the inspector actually emits — it defaults to "EventsNode", not "events".
kind="EventsNode",
diff --git a/products/marketing_analytics/backend/test_api_conversion_goals.py b/products/marketing_analytics/backend/test_api_conversion_goals.py
index c2d6ea2b793b..dc259a923de6 100644
--- a/products/marketing_analytics/backend/test_api_conversion_goals.py
+++ b/products/marketing_analytics/backend/test_api_conversion_goals.py
@@ -1,4 +1,5 @@
from posthog.test.base import APIBaseTest
+from unittest.mock import AsyncMock, patch
from parameterized import parameterized
@@ -8,10 +9,39 @@ from posthog.models.organization import OrganizationMembership
from posthog.models.team.team import Team
from posthog.models.team.team_marketing_analytics_config import TeamMarketingAnalyticsConfig
+from products.marketing_analytics.backend.services.conversion_goals_inspector import (
+ ConversionGoalsListResponse,
+ ConversionGoalSummary,
+)
+
from ee.models.rbac.access_control import AccessControl
SCHEMA_MAP = {"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"}
+_LIST_TARGET = "products.marketing_analytics.backend.api.list_conversion_goals"
+
+
+def _summary_for(conversion_goal_id: str) -> ConversionGoalsListResponse:
+ return ConversionGoalsListResponse(
+ goals=[
+ ConversionGoalSummary(
+ conversion_goal_id=conversion_goal_id,
+ name="Sign ups",
+ kind="EventsNode",
+ target_label="sign_up",
+ last_30d_count=10,
+ integrated_count=10,
+ events_without_utm_source=0,
+ events_with_unmatched_utm_source=0,
+ non_integrated_count=0,
+ integrated_pct=100.0,
+ is_misconfigured=False,
+ misconfig_reason=None,
+ )
+ ],
+ attribution_window_days=90,
+ )
+
def goal_payload(name: str, event: str = "sign_up", **extra) -> dict:
return {"kind": "EventsNode", "event": event, "conversion_goal_name": name, "schema_map": SCHEMA_MAP, **extra}
@@ -356,3 +386,48 @@ class TestConversionGoalWrites(APIBaseTest):
entries = ActivityLog.objects.filter(team_id=self.team.pk, scope="Team", activity="updated")
assert entries.count() == 3
assert {entry.user_id for entry in entries} == {self.user.pk}
+
+
+class TestConversionGoalIdIsOneName(APIBaseTest):
+ def setUp(self):
+ super().setUp()
+ self.base_url = f"/api/projects/{self.team.pk}/marketing_analytics/conversion_goals"
+ self.explain_url = f"/api/projects/{self.team.pk}/marketing_analytics/explain_conversion_goal"
+ self.organization_membership.level = OrganizationMembership.Level.ADMIN
+ self.organization_membership.save()
+
+ def test_the_list_calls_the_id_conversion_goal_id(self):
+ goal = self.client.post(f"{self.base_url}/create", {"goal": goal_payload("Sign ups")}, format="json")
+ created = goal.json()["goal"]
+
+ listed = _summary_for(created["conversion_goal_id"])
+ with patch(_LIST_TARGET, new=AsyncMock(return_value=listed)):
+ response = self.client.get(self.base_url)
+
+ assert response.status_code == 200, response.json()
+ # The name every downstream endpoint asks for, so a caller can chain them.
+ assert response.json()["goals"][0]["conversion_goal_id"] == created["conversion_goal_id"]
+
+ def test_explain_takes_conversion_goal_id(self):
+ response = self.client.get(self.explain_url, {"conversion_goal_id": "does-not-exist"})
+
+ # 404 means the parameter was read and the lookup ran; 400 would mean it was never accepted.
+ assert response.status_code == 404, response.status_code
+
+ def test_explain_no_longer_answers_to_goal_id(self):
+ response = self.client.get(self.explain_url, {"goal_id": "does-not-exist"})
+
+ assert response.status_code == 400
+
+ def test_update_and_delete_take_the_same_name(self):
+ created = self.client.post(f"{self.base_url}/create", {"goal": goal_payload("Sign ups")}, format="json").json()[
+ "goal"
+ ]
+ goal_id = created["conversion_goal_id"]
+
+ update = self.client.patch(
+ f"{self.base_url}/{goal_id}/update", {"goal": {"counts_as_customer": True}}, format="json"
+ )
+ delete = self.client.delete(f"{self.base_url}/{goal_id}/delete")
+
+ assert (update.status_code, delete.status_code) == (200, 200), (update.json(), delete.json())
diff --git a/products/marketing_analytics/backend/test_max_tools.py b/products/marketing_analytics/backend/test_max_tools.py
index 00396d1e66ed..4cb46e15982a 100644
--- a/products/marketing_analytics/backend/test_max_tools.py
+++ b/products/marketing_analytics/backend/test_max_tools.py
@@ -119,7 +119,7 @@ def _make_data_source_entry(
def _make_goal_summary(
*,
- id="goal-1",
+ conversion_goal_id="goal-1",
name="Purchase",
kind="EventsNode",
target_label="purchase",
@@ -133,7 +133,7 @@ def _make_goal_summary(
misconfig_reason=None,
):
return ConversionGoalSummary(
- id=id,
+ conversion_goal_id=conversion_goal_id,
name=name,
kind=kind,
target_label=target_label,
@@ -409,7 +409,7 @@ class TestFormatConversionGoalsForLlm(BaseTest):
def test_populated_goals_includes_goal_names(self):
response = ConversionGoalsListResponse(
- goals=[_make_goal_summary(name="Signup"), _make_goal_summary(id="goal-2", name="Purchase")],
+ goals=[_make_goal_summary(name="Signup"), _make_goal_summary(conversion_goal_id="goal-2", name="Purchase")],
attribution_window_days=30,
attribution_mode="last_touch",
has_misconfigured=False,
@@ -450,7 +450,7 @@ class TestFormatGoalLine(BaseTest):
assert "EventsNode" in result
def test_include_id_prepends_id(self):
- goal = _make_goal_summary(id="abc-123")
+ goal = _make_goal_summary(conversion_goal_id="abc-123")
result = _format_goal_line(goal, include_id=True)
assert "abc-123" in result
@@ -539,7 +539,7 @@ class TestFormatDataSourcesForLlm(BaseTest):
class TestFormatExplainGoalForLlm(BaseTest):
def _make_explanation(self, *, kind="EventsNode", total_count=200):
return GoalExplanation(
- goal_id="goal-1",
+ conversion_goal_id="goal-1",
goal_name="Signup",
kind=kind,
period=DateRange(date_from="2025-04-01", date_to="2025-05-01"),
@@ -874,7 +874,7 @@ class TestMarketingExplainConversionGoalTool(BaseTest):
async def test_arun_impl_success(self):
tool = self._setup_tool()
explanation = GoalExplanation(
- goal_id="goal-1",
+ conversion_goal_id="goal-1",
goal_name="Signup",
kind="EventsNode",
period=DateRange(date_from="2025-04-01", date_to="2025-05-01"),
@@ -893,7 +893,7 @@ class TestMarketingExplainConversionGoalTool(BaseTest):
"products.marketing_analytics.backend.max_tools.explain_conversion_goal",
new=AsyncMock(return_value=explanation),
):
- content, artifact = await tool._arun_impl(goal_id="goal-1")
+ content, artifact = await tool._arun_impl(conversion_goal_id="goal-1")
assert isinstance(content, str)
assert isinstance(artifact, dict)
@@ -907,11 +907,11 @@ class TestMarketingExplainConversionGoalTool(BaseTest):
"products.marketing_analytics.backend.max_tools.explain_conversion_goal",
new=AsyncMock(side_effect=ValueError("Goal 'missing-id' not found")),
):
- content, artifact = await tool._arun_impl(goal_id="missing-id")
+ content, artifact = await tool._arun_impl(conversion_goal_id="missing-id")
assert "Could not explain" in content
assert artifact["error"] == "goal_not_found"
- assert artifact["goal_id"] == "missing-id"
+ assert artifact["conversion_goal_id"] == "missing-id"
class TestMarketingListConversionGoalsTool(BaseTest):
diff --git a/products/marketing_analytics/frontend/generated/api.schemas.ts b/products/marketing_analytics/frontend/generated/api.schemas.ts
index 60988f06eefb..fc9ade4cb2e8 100644
--- a/products/marketing_analytics/frontend/generated/api.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.schemas.ts
@@ -54,8 +54,8 @@ export const ConversionGoalKindEnumApi = {
} as const
export interface ConversionGoalSummaryApi {
- /** Unique id of the goal (event name, action id, or DW goal id) */
- id: string
+ /** Id of the goal. Pass this to the explain, update and delete endpoints. */
+ conversion_goal_id: string
/** Display name of the conversion goal */
name: string
/** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
@@ -1448,8 +1448,8 @@ export interface GoalEventSampleApi {
}
export interface GoalExplanationApi {
- /** Id of the explained conversion goal */
- goal_id: string
+ /** conversion_goal_id of the explained goal */
+ conversion_goal_id: string
/** Display name of the conversion goal */
goal_name: string
/** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
@@ -1890,6 +1890,11 @@ export type MarketingAnalyticsDiagnoseRetrieveParams = {
}
export type MarketingAnalyticsExplainConversionGoalRetrieveParams = {
+ /**
+ * conversion_goal_id of the goal to explain, as returned by the conversion_goals list endpoint.
+ * @minLength 1
+ */
+ conversion_goal_id: string
/**
* ISO start; defaults to 30 days ago
* @nullable
@@ -1900,11 +1905,6 @@ export type MarketingAnalyticsExplainConversionGoalRetrieveParams = {
* @nullable
*/
date_to?: string | null
- /**
- * Id of the conversion goal to explain (from list_conversion_goals).
- * @minLength 1
- */
- goal_id: string
}
export type MarketingAnalyticsSetupPlanRetrieveParams = {
diff --git a/products/marketing_analytics/frontend/generated/api.zod.schemas.ts b/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
index 428f0d93e96b..091728036157 100644
--- a/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.zod.schemas.ts
@@ -19,7 +19,7 @@ export type ConversionGoalKindEnumApi = zod.input<typeof ConversionGoalKindEnumA
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)'),
+ conversion_goal_id: zod.string().describe('Id of the goal. Pass this to the explain, update and delete endpoints.'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
.enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
@@ -70,7 +70,9 @@ export const ConversionGoalsListResponseApi = zod.object({
goals: zod
.array(
zod.object({
- id: zod.string().describe('Unique id of the goal (event name, action id, or DW goal id)'),
+ conversion_goal_id: zod
+ .string()
+ .describe('Id of the goal. Pass this to the explain, update and delete endpoints.'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
.enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
@@ -557,7 +559,9 @@ export const MarketingDiagnosticResponseApi = zod.object({
goals: zod
.array(
zod.object({
- id: zod.string().describe('Unique id of the goal (event name, action id, or DW goal id)'),
+ conversion_goal_id: zod
+ .string()
+ .describe('Id of the goal. Pass this to the explain, update and delete endpoints.'),
name: zod.string().describe('Display name of the conversion goal'),
kind: zod
.enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
@@ -668,7 +672,7 @@ export type GoalEventSampleApi = zod.input<typeof GoalEventSampleApi>
export type GoalEventSampleApiOutput = zod.output<typeof GoalEventSampleApi>
export const GoalExplanationApi = zod.object({
- goal_id: zod.string().describe('Id of the explained conversion goal'),
+ conversion_goal_id: zod.string().describe('conversion_goal_id of the explained goal'),
goal_name: zod.string().describe('Display name of the conversion goal'),
kind: zod
.enum(['EventsNode', 'ActionsNode', 'DataWarehouseNode'])
diff --git a/products/marketing_analytics/mcp/tools.yaml b/products/marketing_analytics/mcp/tools.yaml
index 3766fa3f5e1e..267cc23a22dd 100644
--- a/products/marketing_analytics/mcp/tools.yaml
+++ b/products/marketing_analytics/mcp/tools.yaml
@@ -23,9 +23,10 @@ tools:
idempotent: true
title: List conversion goals
description: >
- List the configured marketing conversion goals for the current project. Each goal returns its kind
- (EventsNode / ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated
- split. Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs
+ List the configured marketing conversion goals for the current project. Each goal returns its
+ conversion_goal_id — the value the explain, update and delete tools take — plus its kind (EventsNode /
+ ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated split.
+ Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs
events_with_unmatched_utm_source (add a custom source mapping). is_approximate is true when the 30d count
may differ from the dashboard's attribution-windowed number.
feature_flag: marketing-analytics-mcp
@@ -40,13 +41,16 @@ tools:
idempotent: false
title: Create conversion goal
description: >
- Add one conversion goal to the project. Send the goal shape: kind (EventsNode for a PostHog event,
- ActionsNode for an action, DataWarehouseNode for an external table), the target (event name, action id or
- table), conversion_goal_name, and schema_map naming the fields that hold utm_campaign, utm_source, the
- timestamp and the distinct id. conversion_goal_id is part of the goal shape but is assigned by the server
- here, so send an empty string for it. Existing goals are left untouched. Set counts_as_customer when
- converting means the person became a customer, and counts_as_revenue when the conversion value is money.
- Call marketing-analytics-conversion-goals first to see what already exists — goal names must be unique.
+ Add one conversion goal to the project. Everything goes inside a single `goal` object — fields sent at the
+ top level are rejected. Required inside it: conversion_goal_name, schema_map naming the fields that hold
+ utm_campaign, utm_source, the timestamp and the distinct id, and conversion_goal_id (assigned by the server,
+ so send an empty string). Also send kind (EventsNode for a PostHog event, ActionsNode for an action,
+ DataWarehouseNode for an external table) and its target: `event` for EventsNode, `id` for ActionsNode, and
+ `id` + table_name + id_field + timestamp_field + distinct_id_field for DataWarehouseNode. Omitting math
+ counts conversions; set it to sum with math_property to total a value. Unknown fields are rejected. Existing
+ goals are left untouched. Set counts_as_customer when converting means the person became a customer, and
+ counts_as_revenue when the conversion value is money. Call marketing-analytics-conversion-goals first to see
+ what already exists — goal names must be unique.
feature_flag: marketing-analytics-mcp
marketing-analytics-data-sources:
operation: marketing_analytics_data_sources_retrieve
@@ -74,8 +78,9 @@ tools:
idempotent: true
title: Delete conversion goal
description: >
- Remove one conversion goal from the project, identified by its conversion_goal_id. The other goals stay in
- place. Dashboards and reports built on this goal will stop showing it, so confirm with the user first.
+ Remove one conversion goal from the project, identified by its conversion_goal_id — call
+ marketing-analytics-conversion-goals first to get it. The other goals stay in place. Dashboards and reports
+ built on this goal will stop showing it, so confirm with the user first.
feature_flag: marketing-analytics-mcp
marketing-analytics-diagnose:
operation: marketing_analytics_diagnose_retrieve
@@ -112,7 +117,8 @@ tools:
attribution calculation (first-touch / last-touch / multi-touch weighting is applied by the dashboard, not
here). Use when the user asks "what utm_sources are behind my N conversions?" or "where do these conversions
come from?". Only EventsNode and ActionsNode goals are explained at the event level; DataWarehouseNode goals
- short-circuit with a note.
+ short-circuit with a note. Requires conversion_goal_id — call marketing-analytics-conversion-goals first and
+ pass the conversion_goal_id of the goal you want.
feature_flag: marketing-analytics-mcp
marketing-analytics-setup-plan-retrieve:
operation: marketing_analytics_setup_plan_retrieve
@@ -170,9 +176,10 @@ tools:
idempotent: true
title: Update conversion goal
description: >
- Change one conversion goal in place, identified by its conversion_goal_id. Only the fields you send are
- changed and the goal keeps its position in the list. Use this to retarget a goal, rename it, or set
- counts_as_customer / counts_as_revenue on a goal that already exists.
+ Change one conversion goal in place, identified by its conversion_goal_id — call
+ marketing-analytics-conversion-goals first to get it. The patch goes inside a single `goal` object; only the
+ fields you send are changed and the goal keeps its position in the list. Use this to retarget a goal, rename
+ it, or set counts_as_customer / counts_as_revenue on a goal that already exists.
feature_flag: marketing-analytics-mcp
marketing-analytics-utm-audit:
operation: marketing_analytics_utm_audit_retrieve
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 6679141673fd..39e663e33161 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -6647,7 +6647,7 @@
}
},
"marketing-analytics-conversion-goals": {
- "description": "List the configured marketing conversion goals for the current project. Each goal returns its kind (EventsNode / ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated split. Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs events_with_unmatched_utm_source (add a custom source mapping). is_approximate is true when the 30d count may differ from the dashboard's attribution-windowed number.",
+ "description": "List the configured marketing conversion goals for the current project. Each goal returns its conversion_goal_id — the value the explain, update and delete tools take — plus its kind (EventsNode / ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated split. Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs events_with_unmatched_utm_source (add a custom source mapping). is_approximate is true when the 30d count may differ from the dashboard's attribution-windowed number.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "List conversion goals",
@@ -6662,7 +6662,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-create-conversion-goal": {
- "description": "Add one conversion goal to the project. Send the goal shape: kind (EventsNode for a PostHog event, ActionsNode for an action, DataWarehouseNode for an external table), the target (event name, action id or table), conversion_goal_name, and schema_map naming the fields that hold utm_campaign, utm_source, the timestamp and the distinct id. conversion_goal_id is part of the goal shape but is assigned by the server here, so send an empty string for it. Existing goals are left untouched. Set counts_as_customer when converting means the person became a customer, and counts_as_revenue when the conversion value is money. Call marketing-analytics-conversion-goals first to see what already exists — goal names must be unique.",
+ "description": "Add one conversion goal to the project. Everything goes inside a single `goal` object — fields sent at the top level are rejected. Required inside it: conversion_goal_name, schema_map naming the fields that hold utm_campaign, utm_source, the timestamp and the distinct id, and conversion_goal_id (assigned by the server, so send an empty string). Also send kind (EventsNode for a PostHog event, ActionsNode for an action, DataWarehouseNode for an external table) and its target: `event` for EventsNode, `id` for ActionsNode, and `id` + table_name + id_field + timestamp_field + distinct_id_field for DataWarehouseNode. Omitting math counts conversions; set it to sum with math_property to total a value. Unknown fields are rejected. Existing goals are left untouched. Set counts_as_customer when converting means the person became a customer, and counts_as_revenue when the conversion value is money. Call marketing-analytics-conversion-goals first to see what already exists — goal names must be unique.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Create conversion goal",
@@ -6692,7 +6692,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-delete-conversion-goal": {
- "description": "Remove one conversion goal from the project, identified by its conversion_goal_id. The other goals stay in place. Dashboards and reports built on this goal will stop showing it, so confirm with the user first.",
+ "description": "Remove one conversion goal from the project, identified by its conversion_goal_id — call marketing-analytics-conversion-goals first to get it. The other goals stay in place. Dashboards and reports built on this goal will stop showing it, so confirm with the user first.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Delete conversion goal",
@@ -6722,7 +6722,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-explain-conversion-goal": {
- "description": "Break down the events that COUNT toward a conversion goal by their own utm_source, utm_campaign, and matched integration. Returns recent sample events for inspection. This is a flat per-event breakdown of the conversion events themselves — NOT an analysis of the user's prior journey, and NOT the dashboard's attribution calculation (first-touch / last-touch / multi-touch weighting is applied by the dashboard, not here). Use when the user asks \"what utm_sources are behind my N conversions?\" or \"where do these conversions come from?\". Only EventsNode and ActionsNode goals are explained at the event level; DataWarehouseNode goals short-circuit with a note.",
+ "description": "Break down the events that COUNT toward a conversion goal by their own utm_source, utm_campaign, and matched integration. Returns recent sample events for inspection. This is a flat per-event breakdown of the conversion events themselves — NOT an analysis of the user's prior journey, and NOT the dashboard's attribution calculation (first-touch / last-touch / multi-touch weighting is applied by the dashboard, not here). Use when the user asks \"what utm_sources are behind my N conversions?\" or \"where do these conversions come from?\". Only EventsNode and ActionsNode goals are explained at the event level; DataWarehouseNode goals short-circuit with a note. Requires conversion_goal_id — call marketing-analytics-conversion-goals first and pass the conversion_goal_id of the goal you want.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Explain a conversion goal",
@@ -6767,7 +6767,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-update-conversion-goal": {
- "description": "Change one conversion goal in place, identified by its conversion_goal_id. Only the fields you send are changed and the goal keeps its position in the list. Use this to retarget a goal, rename it, or set counts_as_customer / counts_as_revenue on a goal that already exists.",
+ "description": "Change one conversion goal in place, identified by its conversion_goal_id — call marketing-analytics-conversion-goals first to get it. The patch goes inside a single `goal` object; only the fields you send are changed and the goal keeps its position in the list. Use this to retarget a goal, rename it, or set counts_as_customer / counts_as_revenue on a goal that already exists.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Update conversion goal",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index a5b3fa11aa20..8091fb08b53f 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -6999,7 +6999,7 @@
}
},
"marketing-analytics-conversion-goals": {
- "description": "List the configured marketing conversion goals for the current project. Each goal returns its kind (EventsNode / ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated split. Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs events_with_unmatched_utm_source (add a custom source mapping). is_approximate is true when the 30d count may differ from the dashboard's attribution-windowed number.",
+ "description": "List the configured marketing conversion goals for the current project. Each goal returns its conversion_goal_id — the value the explain, update and delete tools take — plus its kind (EventsNode / ActionsNode / DataWarehouseNode), target, last-30d count, and the integrated vs non-integrated split. Non-integrated breaks into two buckets with OPPOSITE fixes: events_without_utm_source (tag UTMs) vs events_with_unmatched_utm_source (add a custom source mapping). is_approximate is true when the 30d count may differ from the dashboard's attribution-windowed number.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "List conversion goals",
@@ -7014,7 +7014,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-create-conversion-goal": {
- "description": "Add one conversion goal to the project. Send the goal shape: kind (EventsNode for a PostHog event, ActionsNode for an action, DataWarehouseNode for an external table), the target (event name, action id or table), conversion_goal_name, and schema_map naming the fields that hold utm_campaign, utm_source, the timestamp and the distinct id. conversion_goal_id is part of the goal shape but is assigned by the server here, so send an empty string for it. Existing goals are left untouched. Set counts_as_customer when converting means the person became a customer, and counts_as_revenue when the conversion value is money. Call marketing-analytics-conversion-goals first to see what already exists — goal names must be unique.",
+ "description": "Add one conversion goal to the project. Everything goes inside a single `goal` object — fields sent at the top level are rejected. Required inside it: conversion_goal_name, schema_map naming the fields that hold utm_campaign, utm_source, the timestamp and the distinct id, and conversion_goal_id (assigned by the server, so send an empty string). Also send kind (EventsNode for a PostHog event, ActionsNode for an action, DataWarehouseNode for an external table) and its target: `event` for EventsNode, `id` for ActionsNode, and `id` + table_name + id_field + timestamp_field + distinct_id_field for DataWarehouseNode. Omitting math counts conversions; set it to sum with math_property to total a value. Unknown fields are rejected. Existing goals are left untouched. Set counts_as_customer when converting means the person became a customer, and counts_as_revenue when the conversion value is money. Call marketing-analytics-conversion-goals first to see what already exists — goal names must be unique.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Create conversion goal",
@@ -7044,7 +7044,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-delete-conversion-goal": {
- "description": "Remove one conversion goal from the project, identified by its conversion_goal_id. The other goals stay in place. Dashboards and reports built on this goal will stop showing it, so confirm with the user first.",
+ "description": "Remove one conversion goal from the project, identified by its conversion_goal_id — call marketing-analytics-conversion-goals first to get it. The other goals stay in place. Dashboards and reports built on this goal will stop showing it, so confirm with the user first.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Delete conversion goal",
@@ -7074,7 +7074,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-explain-conversion-goal": {
- "description": "Break down the events that COUNT toward a conversion goal by their own utm_source, utm_campaign, and matched integration. Returns recent sample events for inspection. This is a flat per-event breakdown of the conversion events themselves — NOT an analysis of the user's prior journey, and NOT the dashboard's attribution calculation (first-touch / last-touch / multi-touch weighting is applied by the dashboard, not here). Use when the user asks \"what utm_sources are behind my N conversions?\" or \"where do these conversions come from?\". Only EventsNode and ActionsNode goals are explained at the event level; DataWarehouseNode goals short-circuit with a note.",
+ "description": "Break down the events that COUNT toward a conversion goal by their own utm_source, utm_campaign, and matched integration. Returns recent sample events for inspection. This is a flat per-event breakdown of the conversion events themselves — NOT an analysis of the user's prior journey, and NOT the dashboard's attribution calculation (first-touch / last-touch / multi-touch weighting is applied by the dashboard, not here). Use when the user asks \"what utm_sources are behind my N conversions?\" or \"where do these conversions come from?\". Only EventsNode and ActionsNode goals are explained at the event level; DataWarehouseNode goals short-circuit with a note. Requires conversion_goal_id — call marketing-analytics-conversion-goals first and pass the conversion_goal_id of the goal you want.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Explain a conversion goal",
@@ -7119,7 +7119,7 @@
"feature_flag": "marketing-analytics-mcp"
},
"marketing-analytics-update-conversion-goal": {
- "description": "Change one conversion goal in place, identified by its conversion_goal_id. Only the fields you send are changed and the goal keeps its position in the list. Use this to retarget a goal, rename it, or set counts_as_customer / counts_as_revenue on a goal that already exists.",
+ "description": "Change one conversion goal in place, identified by its conversion_goal_id — call marketing-analytics-conversion-goals first to get it. The patch goes inside a single `goal` object; only the fields you send are changed and the goal keeps its position in the list. Use this to retarget a goal, rename it, or set counts_as_customer / counts_as_revenue on a goal that already exists.",
"category": "Marketing analytics",
"feature": "marketing_analytics",
"summary": "Update conversion goal",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index ed5a2abda3f8..f5a4b30b5afa 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -17087,8 +17087,8 @@ export namespace Schemas {
export type ConversionGoalPatch = PartialConversionGoalFilter1 | PartialConversionGoalFilter2 | PartialConversionGoalFilter3;
export interface ConversionGoalSummary {
- /** Unique id of the goal (event name, action id, or DW goal id) */
- id: string;
+ /** Id of the goal. Pass this to the explain, update and delete endpoints. */
+ conversion_goal_id: string;
/** Display name of the conversion goal */
name: string;
/** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
@@ -36395,8 +36395,8 @@ export namespace Schemas {
}
export interface GoalExplanation {
- /** Id of the explained conversion goal */
- goal_id: string;
+ /** conversion_goal_id of the explained goal */
+ conversion_goal_id: string;
/** Display name of the conversion goal */
goal_name: string;
/** Goal type: EventsNode (PostHog event), ActionsNode (PostHog action), or DataWarehouseNode (external table)
@@ -87114,6 +87114,11 @@ export namespace Schemas {
};
export type MarketingAnalyticsExplainConversionGoalRetrieveParams = {
+ /**
+ * conversion_goal_id of the goal to explain, as returned by the conversion_goals list endpoint.
+ * @minLength 1
+ */
+ conversion_goal_id: string;
/**
* ISO start; defaults to 30 days ago
* @nullable
@@ -87124,11 +87129,6 @@ export namespace Schemas {
* @nullable
*/
date_to?: string | null;
- /**
- * Id of the conversion goal to explain (from list_conversion_goals).
- * @minLength 1
- */
- goal_id: string;
};
export type MarketingAnalyticsSetupPlanRetrieveParams = {
diff --git a/services/mcp/src/generated/marketing_analytics/api.ts b/services/mcp/src/generated/marketing_analytics/api.ts
index 0a648a529868..9419cb17a6ab 100644
--- a/services/mcp/src/generated/marketing_analytics/api.ts
+++ b/services/mcp/src/generated/marketing_analytics/api.ts
@@ -16746,9 +16746,12 @@ export const MarketingAnalyticsExplainConversionGoalRetrieveParams = /* @__PURE_
})
export const MarketingAnalyticsExplainConversionGoalRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ conversion_goal_id: zod
+ .string()
+ .min(1)
+ .describe('conversion_goal_id of the goal to explain, as returned by the conversion_goals list endpoint.'),
date_from: zod.string().nullish().describe('ISO start; defaults to 30 days ago'),
date_to: zod.string().nullish().describe('ISO end; defaults to now'),
- goal_id: zod.string().min(1).describe('Id of the conversion goal to explain (from list_conversion_goals).'),
})
/**
diff --git a/services/mcp/src/tools/generated/marketing_analytics.ts b/services/mcp/src/tools/generated/marketing_analytics.ts
index 82e39a9e9afd..91495a4d24e1 100644
--- a/services/mcp/src/tools/generated/marketing_analytics.ts
+++ b/services/mcp/src/tools/generated/marketing_analytics.ts
@@ -136,9 +136,9 @@ const marketingAnalyticsExplainConversionGoal = (): ToolBase<
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/marketing_analytics/explain_conversion_goal/`,
query: {
+ conversion_goal_id: params.conversion_goal_id,
date_from: params.date_from,
date_to: params.date_to,
- goal_id: params.goal_id,
},
})
return result