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(insights): experiment surfacing Subscribe as a prominent header button (#62529)

Matt Puaded3de35803f
diff --git a/frontend/src/lib/components/Scenes/InsightSubscribeProminentButton.tsx b/frontend/src/lib/components/Scenes/InsightSubscribeProminentButton.tsx
new file mode 100644
index 000000000000..83e86d643968
--- /dev/null
+++ b/frontend/src/lib/components/Scenes/InsightSubscribeProminentButton.tsx
@@ -0,0 +1,71 @@
+import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
+import posthog from 'posthog-js'
+
+import { IconBell } from '@posthog/icons'
+import { useFeatureFlagVariantKey } from '@posthog/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { IconWithCount } from 'lib/lemon-ui/icons/icons'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { userLogic } from 'scenes/userLogic'
+
+import { AvailableFeature, InsightShortId } from '~/types'
+
+import { subscriptionsLogic } from '../Subscriptions/subscriptionsLogic'
+import { urlForSubscriptions } from '../Subscriptions/utils'
+
+interface InsightSubscribeProminentButtonProps {
+ insightShortId: InsightShortId
+}
+
+function SubscribeIcon({ insightShortId }: { insightShortId: InsightShortId }): JSX.Element {
+ const { hasAvailableFeature } = useValues(userLogic)
+ const { subscriptions } = useValues(subscriptionsLogic({ insightShortId }))
+
+ // Mirror the side-panel SceneSubscribeButton: show the active-subscription count badge so
+ // the test arm carries the same "you're already subscribed" signal as the control arm.
+ if (!hasAvailableFeature(AvailableFeature.SUBSCRIPTIONS)) {
+ return <IconBell />
+ }
+
+ return (
+ <IconWithCount count={subscriptions?.length} showZero={false}>
+ <IconBell />
+ </IconWithCount>
+ )
+}
+
+/**
+ * Experiment (insight-subscribe-prominent-button): promotes "Subscribe" from the buried
+ * side-panel action to a visible header button. Reading the flag variant here is the
+ * experiment exposure, so this is mounted only for subscribe-eligible insights to keep the
+ * exposed population aligned with the control arm.
+ */
+export function InsightSubscribeProminentButton({
+ insightShortId,
+}: InsightSubscribeProminentButtonProps): JSX.Element | null {
+ const { push } = useActions(router)
+ const variant = useFeatureFlagVariantKey(FEATURE_FLAGS.INSIGHT_SUBSCRIBE_PROMINENT_BUTTON)
+
+ if (variant !== 'test') {
+ return null
+ }
+
+ return (
+ <LemonButton
+ type="secondary"
+ size="small"
+ icon={<SubscribeIcon insightShortId={insightShortId} />}
+ data-attr="insight-subscribe-prominent-button"
+ onClick={() => {
+ posthog.capture('insight subscribe prominent button clicked', {
+ insight_short_id: insightShortId,
+ })
+ push(urlForSubscriptions({ insightShortId }))
+ }}
+ >
+ Subscribe
+ </LemonButton>
+ )
+}
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 0f5f06c83ed7..e6132bac7d36 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -463,6 +463,7 @@ export const FEATURE_FLAGS = {
SCENE_ALERTS_LABEL_EXPERIMENT: 'scene-alerts-label-experiment', // owner: @mattp #team-analytics-platform multivariate=control,get-notified,monitor-changes,set-up-alert
SCENE_MENU_BAR: 'scene-menu-bar', // owner: @adamleithp #team-platform-ux, gates the per-scene MenuBar above SceneTitleSection
SCENE_SUBSCRIBE_LABEL_EXPERIMENT: 'scene-subscribe-label-experiment', // owner: @mattp #team-analytics-platform multivariate=control,recurring-updates,scheduled-notifications,scheduled-reports
+ INSIGHT_SUBSCRIBE_PROMINENT_BUTTON: 'insight-subscribe-prominent-button', // owner: @mattp #team-analytics-platform multivariate=control,test
SCHEDULE_FEATURE_FLAG_VARIANTS_UPDATE: 'schedule-feature-flag-variants-update', // owner: @gustavo #team-feature-flags
SCHEMA_ENFORCEMENT_REJECT: 'schema-enforcement-reject', // owner: @aspicer, gates the ability to set schema enforcement mode to "reject"
SCHEMA_MANAGEMENT: 'schema-management', // owner: @aspicer
diff --git a/frontend/src/scenes/insights/InsightPageHeader.tsx b/frontend/src/scenes/insights/InsightPageHeader.tsx
index d73429886d3c..92a630bd96f6 100644
--- a/frontend/src/scenes/insights/InsightPageHeader.tsx
+++ b/frontend/src/scenes/insights/InsightPageHeader.tsx
@@ -4,6 +4,7 @@ import { useMemo } from 'react'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { areAlertsSupportedForInsight } from 'lib/components/Alerts/insightAlertsLogic'
+import { InsightSubscribeProminentButton } from 'lib/components/Scenes/InsightSubscribeProminentButton'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { insightDataLogic } from 'scenes/insights/insightDataLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
@@ -37,8 +38,16 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
const { insightMode, filtersOverride, variablesOverride, dashboardId } = useValues(insightSceneLogic)
const { setInsightMode } = useActions(insightSceneLogic)
- const { insightProps, canEditInsight, insight, insightChanged, insightSaving, hasDashboardItemId, insightLoading } =
- useValues(insightLogic(insightLogicProps))
+ const {
+ insightProps,
+ canEditInsight,
+ insight,
+ insightChanged,
+ insightSaving,
+ // `dashboardItemId` is legacy naming for the insight's own short_id — this is true when the insight is saved, not when it's on a dashboard
+ hasDashboardItemId: isSavedInsight,
+ insightLoading,
+ } = useValues(insightLogic(insightLogicProps))
const { setInsightMetadata, setInsightMetadataLocal, saveAs, saveInsight } = useActions(
insightLogic(insightLogicProps)
)
@@ -60,7 +69,7 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
const readDataMaxToolProps = useMemo(
() =>
- hasDashboardItemId && insight?.short_id
+ isSavedInsight && insight?.short_id
? {
identifier: 'read_data' as const,
context: {
@@ -73,12 +82,12 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
},
}
: undefined,
- [hasDashboardItemId, insight?.short_id, insight?.id, insightDisplayName, query]
+ [isSavedInsight, insight?.short_id, insight?.id, insightDisplayName, query]
)
useMaxTool({
identifier: 'upsert_alert',
- active: canCreateAlertForInsight && hasDashboardItemId && !!insight.id,
+ active: canCreateAlertForInsight && isSavedInsight && !!insight.id,
context: useMemo(
() => ({
insight_id: insight.id,
@@ -125,7 +134,7 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
maxToolProps={readDataMaxToolProps}
actions={
<>
- {insightMode === ItemMode.Edit && hasDashboardItemId && (
+ {insightMode === ItemMode.Edit && isSavedInsight && (
<LemonButton
type="secondary"
onClick={() => {
@@ -139,6 +148,10 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
</LemonButton>
)}
+ {insightMode !== ItemMode.Edit && isSavedInsight && insight.short_id && (
+ <InsightSubscribeProminentButton insightShortId={insight.short_id} />
+ )}
+
{insightMode !== ItemMode.Edit ? (
canEditInsight && (
<AccessControlAction
@@ -184,7 +197,7 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
? saveInsight(redirectToViewMode)
: saveInsight(redirectToViewMode, getLastNewFolder() ?? 'Unfiled/Insights')
}
- isSaved={hasDashboardItemId}
+ isSaved={isSavedInsight}
addingToDashboard={!!insight.dashboards?.length && !insight.id}
insightSaving={insightSaving}
insightChanged={insightChanged || queryChanged}