Skip to content

feat(subscriptions): attribute insight query type on subscription analytics events - #70511

Merged
MattPua merged 1 commit into
masterfrom
posthog-code/subscription-insight-query-kind-analytics
Jul 13, 2026
Merged

feat(subscriptions): attribute insight query type on subscription analytics events#70511
MattPua merged 1 commit into
masterfrom
posthog-code/subscription-insight-query-kind-analytics

Conversation

@mjwarren3

Copy link
Copy Markdown
Contributor

Problem

Insight subscription analytics events (insight subscription created / insight subscription updated) captured the resource type, delivery target, and schedule — but nothing about the insight itself. That means we can't answer a basic product question: which kinds of insights (trends, funnels, retention, paths, …) do people actually subscribe to? The only insight reference on the event was the short_id buried in $current_url, and the insight itself lives in each customer's own project, so there was no way to slice subscriptions by insight type.

Changes

Enrich Subscription.get_analytics_metadata() so that for insight subscriptions it includes the subscribed insight's query type via the existing Insight.get_analytics_query_kinds() helper — adding query_kind (e.g. InsightVizNode) and query_source_kind (e.g. TrendsQuery, FunnelsQuery, RetentionQuery).

These are the same keys the insight created / insight updated events already emit, so subscription events become sliceable by insight type using a consistent taxonomy. Dashboard and AI-prompt subscriptions are unaffected (the keys are only added when a real insight is attached). No new events, no schema/migration changes — this only adds properties to an existing analytics event.

How did you test this code?

Added two focused unit tests to posthog/models/test/test_subscription_model.py:

  • test_analytics_metadata_includes_insight_query_kind — an insight subscription whose insight has a TrendsQuery emits query_kind/query_source_kind. Catches a regression where insight-type attribution is dropped or wired to the wrong keys.
  • test_analytics_metadata_omits_query_kind_for_non_insight_subscription — a dashboard subscription does not carry those keys, guarding the insight-only gating.

Note: this environment has no dev stack (no hogli/pytest), so I could not execute the suite locally — please rely on CI. The change mirrors the already-tested insight created/insight updated attribution pattern.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Built with the PostHog Slack app, following a thread investigating June's subscription growth. The question "what type of insights are users subscribing to?" turned out to be unanswerable from current instrumentation — this closes that gap. Chose to reuse Insight.get_analytics_query_kinds() and its exact key names (rather than invent new ones) so subscription events share the insight taxonomy and existing dashboards/queries keep working. Scoped to insight subs to keep the surface minimal; dashboard tile-type attribution could be a follow-up. Skill invoked: /writing-tests (to gate the added tests).


Created with PostHog from a Slack thread

…lytics events

Insight subscription analytics events (`insight subscription created/updated`) recorded resource/target/schedule metadata but nothing about the insight itself, so we couldn't tell which kinds of insights (trends, funnels, retention, ...) people subscribe to.

Enrich `Subscription.get_analytics_metadata()` for insight subscriptions with the subscribed insight's `get_analytics_query_kinds()` (`query_kind`, `query_source_kind`) — the same keys the `insight created/updated` events already emit, so subscriptions can be sliced by insight type with a consistent taxonomy. Only added for insight subscriptions; dashboard and AI-prompt subs are unaffected.

Generated-By: PostHog Code
Task-Id: 99d3062b-59e6-43d3-9a2a-797b02b25883
@MattPua
MattPua marked this pull request as ready for review July 13, 2026 16:10
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 13, 2026 16:11
@MattPua
MattPua enabled auto-merge (squash) July 13, 2026 16:11
@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

Playwright — all passed

All tests passed.

View test results →

@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@MattPua
MattPua merged commit 9c7cb39 into master Jul 13, 2026
302 of 313 checks passed
@MattPua
MattPua deleted the posthog-code/subscription-insight-query-kind-analytics branch July 13, 2026 16:29
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-13 16:57 UTC Run
prod-us ✅ Deployed 2026-07-13 17:12 UTC Run
prod-eu ✅ Deployed 2026-07-13 17:14 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants