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(dashboards): experiment on subscribe placement (#69054)

Matt Pua8204a700448e
diff --git a/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts b/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts
index 177cca430c50..73e5189802b7 100644
--- a/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts
+++ b/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts
@@ -189,6 +189,13 @@ export const subscriptionLogic = kea<subscriptionLogicType>([
if (updatedSub.id !== props.id) {
router.actions.replace(urlForSubscription(updatedSub.id, props))
+ posthog.capture('subscription created', {
+ resource_type: isAi ? 'ai' : props.dashboardId ? 'dashboard' : 'insight',
+ dashboard_id: props.dashboardId,
+ insight_short_id: props.insightShortId,
+ subscription_id: updatedSub.id,
+ target_type: updatedSub.target_type,
+ })
}
// If a subscriptionsLogic for this insight/dashboard is mounted already, refresh both
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index b52ca111175d..350a8e0a3343 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -277,6 +277,7 @@ export const FEATURE_FLAGS = {
DASHBOARD_INLINE_TILE_INSERTION: 'dashboard-inline-tile-insertion', // owner: @MattPua #team-analytics-platform
DASHBOARD_LAYOUT_DISCARD_PROMPT: 'dashboard-layout-discard-prompt', // owner: @cory.s #team-analytics-platform
DASHBOARD_QUICK_FILTERS_EXPERIMENT: 'dashboard-quick-filters-experiment', // owner: @vdekrijger #team-product-analytics multivariate=control,test
+ DASHBOARD_SUBSCRIBE_PLACEMENT: 'dashboard-subscribe-placement', // owner: @MattPua #team-analytics-platform multivariate=control,button,menu
DASHBOARD_TEMPLATE_CHOOSER_EXPERIMENT: 'dashboard-template-chooser-experiment', // owner: @mattp #team-analytics-platform multivariate=control,simple,new
DASHBOARD_WIDGETS: 'dashboard-widgets', // owner: @mattp #team-analytics-platform
DASHBOARDS_LIST_VIEW: 'dashboards-list-view', // owner: @vdekrijger #team-product-analytics multivariate=control,tree
diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
index 9a2a7682bd15..7980dd9f6d6e 100644
--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
@@ -19,6 +19,7 @@ import { AccessControlLevel, AccessControlResourceType, DashboardMode } from '~/
import { addInsightToDashboardLogic } from './addInsightToDashboardModalLogic'
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
+import { DashboardSubscribeExperiment } from './DashboardSubscribeExperiment'
export function getAddTileMenuItems({
dashboardId,
@@ -214,8 +215,10 @@ export function EditModeActions(): JSX.Element {
return (
<>
+ <DashboardSubscribeExperiment placement="button" />
{layoutEditMode && <DashboardEditSaveCancelButtons />}
<DashboardAddTileButton />
+ <DashboardSubscribeExperiment placement="menu" />
</>
)
}
@@ -247,6 +250,7 @@ export function ViewModeActions(): JSX.Element {
return (
<>
+ <DashboardSubscribeExperiment placement="button" />
<LemonButton
type="secondary"
data-attr="dashboard-share-button"
@@ -281,6 +285,7 @@ export function ViewModeActions(): JSX.Element {
</Shortcut>
)}
<DashboardAddTileButton />
+ <DashboardSubscribeExperiment placement="menu" />
</>
)
}
diff --git a/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.scss b/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.scss
new file mode 100644
index 000000000000..a8d901ccb7a2
--- /dev/null
+++ b/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.scss
@@ -0,0 +1,36 @@
+.DashboardSubscribeBell {
+ transform-origin: top center;
+}
+
+@media (prefers-reduced-motion: no-preference) {
+ .LemonButton:hover .DashboardSubscribeBell {
+ animation: DashboardSubscribeExperiment__ring 0.7s ease-in-out;
+ }
+}
+
+@keyframes DashboardSubscribeExperiment__ring {
+ 0%,
+ 100% {
+ transform: rotate(0);
+ }
+
+ 15% {
+ transform: rotate(16deg);
+ }
+
+ 30% {
+ transform: rotate(-14deg);
+ }
+
+ 45% {
+ transform: rotate(10deg);
+ }
+
+ 60% {
+ transform: rotate(-6deg);
+ }
+
+ 75% {
+ transform: rotate(3deg);
+ }
+}
diff --git a/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.tsx b/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.tsx
new file mode 100644
index 000000000000..00a0674d1f89
--- /dev/null
+++ b/frontend/src/scenes/dashboard/DashboardSubscribeExperiment.tsx
@@ -0,0 +1,100 @@
+import './DashboardSubscribeExperiment.scss'
+
+import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
+import posthog from 'posthog-js'
+
+import { IconBell, IconEllipsis } from '@posthog/icons'
+import { useFeatureFlagVariantKey } from '@posthog/react'
+
+import { subscriptionsLogic } from 'lib/components/Subscriptions/subscriptionsLogic'
+import { urlForSubscriptions } from 'lib/components/Subscriptions/utils'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { IconWithCount } from 'lib/lemon-ui/icons/icons'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonMenu } from 'lib/lemon-ui/LemonMenu'
+import { userLogic } from 'scenes/userLogic'
+
+import { AvailableFeature } from '~/types'
+
+import { dashboardLogic } from './dashboardLogic'
+
+type SubscribePlacement = 'button' | 'menu'
+
+function SubscribeCountIcon({ dashboardId }: { dashboardId: number }): JSX.Element {
+ const { subscriptions } = useValues(subscriptionsLogic({ dashboardId }))
+
+ return (
+ <IconWithCount count={subscriptions?.length} showZero={false}>
+ <IconBell className="DashboardSubscribeBell" fontSize="16" />
+ </IconWithCount>
+ )
+}
+
+function SubscribeIcon({ dashboardId }: { dashboardId: number }): JSX.Element {
+ const { hasAvailableFeature } = useValues(userLogic)
+
+ // Only read the count when the subscriptions logic is already mounted (e.g. side panel opened),
+ // so an experiment arm never triggers an extra fetch just to render this badge.
+ if (!hasAvailableFeature(AvailableFeature.SUBSCRIPTIONS) || !subscriptionsLogic.isMounted({ dashboardId })) {
+ return <IconBell className="DashboardSubscribeBell" fontSize="16" />
+ }
+
+ return <SubscribeCountIcon dashboardId={dashboardId} />
+}
+
+// Both placements mount in the header; each renders only when it matches the assigned variant.
+export function DashboardSubscribeExperiment({ placement }: { placement: SubscribePlacement }): JSX.Element | null {
+ const { dashboard, canEditDashboard } = useValues(dashboardLogic)
+ const { push } = useActions(router)
+ const variant = useFeatureFlagVariantKey(FEATURE_FLAGS.DASHBOARD_SUBSCRIBE_PLACEMENT)
+
+ if (!dashboard || !canEditDashboard || variant !== placement) {
+ return null
+ }
+
+ const dashboardId = dashboard.id
+ const openSubscriptions = (): void => {
+ posthog.capture('dashboard subscribe clicked', {
+ dashboard_id: dashboardId,
+ variant,
+ surface: placement,
+ })
+ push(urlForSubscriptions({ dashboardId }))
+ }
+
+ if (placement === 'menu') {
+ return (
+ <LemonMenu
+ items={[
+ {
+ label: 'Subscribe',
+ icon: <SubscribeIcon dashboardId={dashboardId} />,
+ onClick: openSubscriptions,
+ 'data-attr': 'dashboard-subscribe-menu-item',
+ },
+ ]}
+ >
+ <LemonButton
+ type="tertiary"
+ size="small"
+ icon={<IconEllipsis fontSize="16" />}
+ data-attr="dashboard-subscribe-menu"
+ aria-label="More actions"
+ />
+ </LemonMenu>
+ )
+ }
+
+ return (
+ <LemonButton
+ type="tertiary"
+ size="small"
+ icon={<SubscribeIcon dashboardId={dashboardId} />}
+ data-attr="dashboard-subscribe-prominent-button"
+ onClick={openSubscriptions}
+ >
+ Subscribe
+ </LemonButton>
+ )
+}