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(marketing-analytics): capture which metric groups users hide on apply (#122585)

Paul D'Ambra601175869747
diff --git a/products/marketing_analytics/frontend/overview/overviewMetricConfiguration.ts b/products/marketing_analytics/frontend/overview/overviewMetricConfiguration.ts
index 1ee1aa53d38a..959aa510cf68 100644
--- a/products/marketing_analytics/frontend/overview/overviewMetricConfiguration.ts
+++ b/products/marketing_analytics/frontend/overview/overviewMetricConfiguration.ts
@@ -24,6 +24,17 @@ export function defaultOverviewMetricConfiguration(): OverviewMetricConfiguratio
}
}
+export type OverviewHiddenGroups = 'none' | OverviewMetricGroup | 'both'
+
+export function hiddenOverviewMetricGroups(configuration: OverviewMetricConfiguration): OverviewHiddenGroups {
+ const platforms = configuration.platforms.hidden.length > 0
+ const posthog = configuration.posthog.hidden.length > 0
+ if (platforms && posthog) {
+ return 'both'
+ }
+ return platforms ? 'platforms' : posthog ? 'posthog' : 'none'
+}
+
export function overviewMetricsForGroup(
items: OverviewMetricCardItem[],
group: OverviewMetricGroup,
diff --git a/products/marketing_analytics/frontend/overview/overviewMetricsLogic.test.ts b/products/marketing_analytics/frontend/overview/overviewMetricsLogic.test.ts
index 8b3fc19fc0b7..4fa4c71bf1e5 100644
--- a/products/marketing_analytics/frontend/overview/overviewMetricsLogic.test.ts
+++ b/products/marketing_analytics/frontend/overview/overviewMetricsLogic.test.ts
@@ -1,5 +1,9 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
+import { expectLogic } from 'kea-test-utils'
+
+import { marketingAnalyticsLogic } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic'
+
import type { OverviewMetricCardItem } from '~/queries/nodes/OverviewGrid/OverviewMetricCardGrid'
import { initKeaTests } from '~/test/init'
@@ -51,6 +55,38 @@ describe('overview metric configuration', () => {
unmountRestored()
})
+ it.each([
+ ['none', [], []],
+ ['platforms', ['Cost'], []],
+ ['posthog', [], ['Trial started']],
+ ['both', ['Cost'], ['Trial started']],
+ ])(
+ 'reports %s when applying with those groups hidden, and nothing on cancel',
+ async (value, platforms, posthogHidden) => {
+ const logic = overviewMetricsLogic({ viewKey: 'ad-performance' })
+ const unmount = logic.mount()
+ logic.actions.configureMetrics(logic.values.configuration)
+ logic.actions.updateDraftGroup('platforms', { hidden: platforms })
+ logic.actions.updateDraftGroup('posthog', { hidden: posthogHidden })
+ await expectLogic(logic, () => logic.actions.closeConfiguration()).toNotHaveDispatchedActions([
+ 'reportDashboardControlUsed',
+ ])
+ logic.actions.configureMetrics(logic.values.configuration)
+ logic.actions.updateDraftGroup('platforms', { hidden: platforms })
+ logic.actions.updateDraftGroup('posthog', { hidden: posthogHidden })
+ await expectLogic(logic, () =>
+ logic.actions.applyConfiguration(logic.values.draftConfiguration!)
+ ).toDispatchActions([
+ marketingAnalyticsLogic.actionCreators.reportDashboardControlUsed(
+ 'overview',
+ 'metric_configuration_applied',
+ value
+ ),
+ ])
+ unmount()
+ }
+ )
+
it('keeps platform metrics separate, appends new goals, and drops removed metrics from saved ordering', () => {
const configuration = defaultOverviewMetricConfiguration()
configuration.platforms.order = ['Clicks', 'Cost']
diff --git a/products/marketing_analytics/frontend/overview/overviewMetricsLogic.ts b/products/marketing_analytics/frontend/overview/overviewMetricsLogic.ts
index 891f52d12c21..2538a4a2e9c6 100644
--- a/products/marketing_analytics/frontend/overview/overviewMetricsLogic.ts
+++ b/products/marketing_analytics/frontend/overview/overviewMetricsLogic.ts
@@ -1,12 +1,14 @@
-import { LogicWrapper, MakeLogicType, actions, kea, key, path, props, reducers } from 'kea'
+import { LogicWrapper, MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers } from 'kea'
import { buildTeamScopedPersistenceConfig } from 'lib/logic/persistence'
+import { marketingAnalyticsLogic } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic'
import {
OverviewMetricConfiguration,
OverviewMetricGroup,
OverviewMetricGroupConfiguration,
defaultOverviewMetricConfiguration,
+ hiddenOverviewMetricGroups,
} from './overviewMetricConfiguration'
export interface OverviewMetricsLogicProps {
@@ -30,6 +32,7 @@ export interface overviewMetricsLogicActions {
configuration: Partial<OverviewMetricGroupConfiguration>
}
resetDraft: () => void
+ reportDashboardControlUsed: (section: string, control: string, value?: boolean | string) => void
setGroupCollapsed: (
group: OverviewMetricGroup,
collapsed: boolean
@@ -47,6 +50,7 @@ export const overviewMetricsLogic: LogicWrapper<overviewMetricsLogicType> = kea<
key(({ viewKey }) => viewKey),
// The path is the storage key for saved metric preferences.
path((key) => ['products', 'marketingAnalytics', 'overviewMetricsLogic', key]),
+ connect(() => ({ actions: [marketingAnalyticsLogic, ['reportDashboardControlUsed']] })),
actions({
configureMetrics: (configuration: OverviewMetricConfiguration) => ({ configuration }),
closeConfiguration: () => ({}),
@@ -82,4 +86,13 @@ export const overviewMetricsLogic: LogicWrapper<overviewMetricsLogicType> = kea<
},
],
})),
+ listeners(({ actions }) => ({
+ applyConfiguration: ({ configuration }) => {
+ actions.reportDashboardControlUsed(
+ 'overview',
+ 'metric_configuration_applied',
+ hiddenOverviewMetricGroups(configuration)
+ )
+ },
+ })),
])