feat(subscriptions): attribute insight query type on subscription analytics events - #70511
Merged
MattPua merged 1 commit intoJul 13, 2026
Merged
Conversation
…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
marked this pull request as ready for review
July 13, 2026 16:10
MattPua
approved these changes
Jul 13, 2026
MattPua
enabled auto-merge (squash)
July 13, 2026 16:11
Contributor
🤖 CI report |
MattPua
deleted the
posthog-code/subscription-insight-query-kind-analytics
branch
July 13, 2026 16:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingInsight.get_analytics_query_kinds()helper — addingquery_kind(e.g.InsightVizNode) andquery_source_kind(e.g.TrendsQuery,FunnelsQuery,RetentionQuery).These are the same keys the
insight created/insight updatedevents 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 aTrendsQueryemitsquery_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-testedinsight created/insight updatedattribution 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