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): track dashboard usage and setup entry points (#102616)

Javier Bahamondes539cd96d6313
diff --git a/frontend/src/scenes/marketing-analytics/NewMarketingAnalyticsDashboard.test.tsx b/frontend/src/scenes/marketing-analytics/NewMarketingAnalyticsDashboard.test.tsx
index 4ebe0b91a2cf..82b39c40c070 100644
--- a/frontend/src/scenes/marketing-analytics/NewMarketingAnalyticsDashboard.test.tsx
+++ b/frontend/src/scenes/marketing-analytics/NewMarketingAnalyticsDashboard.test.tsx
@@ -7,7 +7,11 @@ jest.mock('scenes/marketing-analytics/Setup/sectionRouting', () => ({ suggestion
jest.mock('scenes/marketing-analytics/Setup/SuggestionRow', () => ({ SuggestionRow: () => null }))
-jest.mock('kea', () => ({ ...jest.requireActual('kea'), useValues: jest.fn(), useActions: () => ({}) }))
+jest.mock('kea', () => ({
+ ...jest.requireActual('kea'),
+ useValues: jest.fn(),
+ useActions: () => new Proxy({}, { get: () => jest.fn() }),
+}))
jest.mock('@posthog/lemon-ui', () => ({
LemonBanner: () => null,
LemonCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
diff --git a/frontend/src/scenes/marketing-analytics/Setup/SetupTab.tsx b/frontend/src/scenes/marketing-analytics/Setup/SetupTab.tsx
index 9adbd2211e17..63421aee77d0 100644
--- a/frontend/src/scenes/marketing-analytics/Setup/SetupTab.tsx
+++ b/frontend/src/scenes/marketing-analytics/Setup/SetupTab.tsx
@@ -50,7 +50,7 @@ export function SetupTab(): JSX.Element {
useValues(setupPlanLogic)
const { loadSetupPlan, reviewSuggestion, confirmReviewedSuggestion, confirmReviewedBatch } =
useActions(setupPlanLogic)
- const { integrationSettingsModal } = useValues(marketingAnalyticsSettingsLogic)
+ const { integrationSettingsModal, setupEntryPointLabel } = useValues(marketingAnalyticsSettingsLogic)
const { closeIntegrationSettingsModal } = useActions(marketingAnalyticsSettingsLogic)
// Keep the audit gated for one release so the two flags can roll independently;
@@ -72,7 +72,11 @@ export function SetupTab(): JSX.Element {
const active = sections.find((section) => section.key === setupSection) ?? sections[0]
useEffect(() => {
- posthog.capture('marketing analytics setup section viewed', { section: active.key })
+ posthog.capture('marketing analytics setup section viewed', {
+ section: active.key,
+ entry_point: setupEntryPointLabel,
+ })
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [active.key])
return (
@@ -125,7 +129,7 @@ export function SetupTab(): JSX.Element {
onClose={() => reviewSuggestion(null)}
onConfirm={(item) => {
// Navigate ops finish here; everything else goes to the server.
- if (item.apply && runNavigateOp(item.apply)) {
+ if (item.apply && runNavigateOp(item.apply, setupEntryPointLabel)) {
reviewSuggestion(null)
return
}
diff --git a/frontend/src/scenes/marketing-analytics/Setup/navigateOps.ts b/frontend/src/scenes/marketing-analytics/Setup/navigateOps.ts
index 930afda29b27..6f887fa3d4fe 100644
--- a/frontend/src/scenes/marketing-analytics/Setup/navigateOps.ts
+++ b/frontend/src/scenes/marketing-analytics/Setup/navigateOps.ts
@@ -12,11 +12,12 @@ import type { ApplyOp } from 'scenes/web-analytics/tabs/marketing-analytics/fron
* New tabs throughout: the user is midway through a checklist and navigating away
* loses their place in it.
*/
-export function runNavigateOp(op: ApplyOp): boolean {
+export function runNavigateOp(op: ApplyOp, entryPoint: string): boolean {
if (['open_oauth', 'open_source_wizard', 'open_settings'].includes(op.op)) {
posthog.capture('marketing analytics setup navigation opened', {
destination: op.op,
integration: op.kind,
+ entry_point: entryPoint,
})
}
switch (op.op) {
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts
index 1535fad7dfab..82d01eb37fee 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts
@@ -1,6 +1,7 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -22,10 +23,13 @@ import {
import { initKeaTests } from '~/test/init'
import { ExternalDataSource } from '~/types'
-import { MarketingAnalyticsTab, marketingAnalyticsLogic } from './marketingAnalyticsLogic'
+import { MarketingAnalyticsTab, SetupSection, marketingAnalyticsLogic } from './marketingAnalyticsLogic'
+import { marketingAnalyticsSettingsLogic } from './marketingAnalyticsSettingsLogic'
import { marketingAnalyticsTableLogic } from './marketingAnalyticsTableLogic'
import { marketingAnalyticsTilesLogic } from './marketingAnalyticsTilesLogic'
+jest.mock('posthog-js')
+
// Kea builds this from the reducer's path and name. It is pinned in the logic, so a rename cannot
// silently point the reducer at a different key and abandon what someone already saved.
const STORAGE_KEY = `${MOCK_TEAM_ID}__.scenes.webAnalytics.marketingAnalyticsLogic.integrationFilter`
@@ -243,4 +247,41 @@ describe('marketingAnalyticsLogic', () => {
integrationFilter: { integrationSourceIds: ['source-1'] },
})
})
+
+ it.each(['tab', 'scene'] as const)(
+ 'clears the dashboard setup entry point when leaving the %s',
+ async (destination) => {
+ const settings = marketingAnalyticsSettingsLogic()
+ const unmountSettings = settings.mount()
+ logic = marketingAnalyticsLogic()
+ logic.mount()
+
+ await expectLogic(logic, () =>
+ logic.actions.openSetup(SetupSection.CONVERSION_GOALS, 'dashboard_customer_cards')
+ )
+ .toFinishAllListeners()
+ .toMatchValues({
+ activeTab: MarketingAnalyticsTab.SETUP,
+ setupSection: SetupSection.CONVERSION_GOALS,
+ setupEntryPoint: 'dashboard_customer_cards',
+ })
+ expect(posthog.capture).toHaveBeenCalledWith('marketing analytics dashboard setup opened', {
+ entry_point: 'dashboard_customer_cards',
+ section: SetupSection.CONVERSION_GOALS,
+ })
+
+ await expectLogic(logic, () => logic.actions.setSetupSection(SetupSection.SOURCES))
+ .toFinishAllListeners()
+ .toMatchValues({ setupEntryPoint: 'dashboard_customer_cards' })
+ if (destination === 'tab') {
+ await expectLogic(logic, () =>
+ logic.actions.setActiveTab(MarketingAnalyticsTab.DASHBOARD)
+ ).toFinishAllListeners()
+ } else {
+ logic.unmount()
+ }
+ expect(settings.values.setupEntryPoint).toBeNull()
+ unmountSettings()
+ }
+ )
})
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
index 04912f548c38..713e8bd9303a 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
@@ -1,5 +1,17 @@
-import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'
+import {
+ MakeLogicType,
+ actions,
+ afterMount,
+ beforeUnmount,
+ connect,
+ kea,
+ listeners,
+ path,
+ reducers,
+ selectors,
+} from 'kea'
import { actionToUrl, router } from 'kea-router'
+import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -40,7 +52,7 @@ import type { PaginatedResponse } from '../../../../../../lib/api'
import type { FeatureFlagsSet } from '../../../../../../lib/logic/featureFlagLogic'
import type { ProductIntentProperties } from '../../../../../../lib/utils/product-intents'
import { defaultConversionGoalFilter } from '../components/settings/constants'
-import { marketingAnalyticsSettingsLogic } from './marketingAnalyticsSettingsLogic'
+import { SetupEntryPoint, marketingAnalyticsSettingsLogic } from './marketingAnalyticsSettingsLogic'
import { externalAdsCostTile } from './marketingCostTile'
import {
MarketingDashboardMapper,
@@ -95,6 +107,11 @@ export enum SetupSection {
export const DEFAULT_SETUP_SECTION = SetupSection.SUGGESTIONS
+export interface DashboardGoalsConfigured {
+ customerGoal: boolean
+ revenueGoal: boolean
+}
+
/** Where a tab key lands once Setup absorbs it. Applied by the scene, which is what
* knows whether Setup is rendering — with its flag off `integration-health` is still a
* real tab and resolves on its own. */
@@ -245,6 +262,7 @@ export interface marketingAnalyticsLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
conversion_goals: ConversionGoalFilter[] // marketingAnalyticsSettingsLogic
filter_test_accounts: boolean // marketingAnalyticsSettingsLogic
+ setupEntryPoint: SetupEntryPoint | null // marketingAnalyticsSettingsLogic
sources_map: Record<string, SourceMap> // marketingAnalyticsSettingsLogic
dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // sourceManagementLogic
dataWarehouseSourcesLoading: boolean // sourceManagementLogic
@@ -333,6 +351,9 @@ export interface marketingAnalyticsLogicActions {
addOrUpdateConversionGoal: (conversionGoal: ConversionGoalFilter) => {
conversionGoal: ConversionGoalFilter
} // marketingAnalyticsSettingsLogic
+ setSetupEntryPoint: (entryPoint: SetupEntryPoint | null) => {
+ entryPoint: SetupEntryPoint | null
+ } // marketingAnalyticsSettingsLogic
updateFilterTestAccounts: (filterTestAccounts: boolean) => {
filterTestAccounts: boolean
} // marketingAnalyticsSettingsLogic
@@ -400,6 +421,29 @@ export interface marketingAnalyticsLogicActions {
loadConversionGoal: (goal: ConversionGoalFilter) => {
goal: ConversionGoalFilter
}
+ openSetup: (
+ section: SetupSection,
+ entryPoint: SetupEntryPoint
+ ) => {
+ entryPoint: SetupEntryPoint
+ section: SetupSection
+ }
+ reportDashboardControlUsed: (
+ section: string,
+ control: string,
+ value?: boolean | string
+ ) => {
+ control: string
+ section: string
+ value: boolean | string | undefined
+ }
+ reportDashboardSectionViewed: (
+ section: string,
+ configured: DashboardGoalsConfigured
+ ) => {
+ configured: DashboardGoalsConfigured
+ section: string
+ }
saveConversionGoal: () => {
value: true
}
@@ -629,7 +673,7 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
teamLogic,
['baseCurrency'],
marketingAnalyticsSettingsLogic,
- ['sources_map', 'conversion_goals', 'filter_test_accounts'],
+ ['sources_map', 'conversion_goals', 'filter_test_accounts', 'setupEntryPoint'],
sourceManagementLogic,
['dataWarehouseTables', 'dataWarehouseSourcesLoading', 'dataWarehouseSources'],
featureFlagLogic,
@@ -641,7 +685,7 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
dataNodeCollectionLogic({ key: MARKETING_ANALYTICS_DATA_COLLECTION_NODE_ID }),
['reloadAll'],
marketingAnalyticsSettingsLogic,
- ['addOrUpdateConversionGoal', 'updateFilterTestAccounts'],
+ ['addOrUpdateConversionGoal', 'updateFilterTestAccounts', 'setSetupEntryPoint'],
teamLogic,
['addProductIntent'],
],
@@ -650,6 +694,16 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
setAdPerformanceConversionGoals: (include: boolean) => ({ include }),
setActiveTab: (tab: MarketingAnalyticsTab) => ({ tab }),
setSetupSection: (section: SetupSection) => ({ section }),
+ openSetup: (section: SetupSection, entryPoint: SetupEntryPoint) => ({ section, entryPoint }),
+ reportDashboardSectionViewed: (section: string, configured: DashboardGoalsConfigured) => ({
+ section,
+ configured,
+ }),
+ reportDashboardControlUsed: (section: string, control: string, value?: string | boolean) => ({
+ section,
+ control,
+ value,
+ }),
// Low-level state setters (used by listeners)
setDraftConversionGoal: (goal: ConversionGoalFilter | null) => ({ goal }),
@@ -1424,6 +1478,27 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
}
return {
+ openSetup: ({ section, entryPoint }) => {
+ actions.setSetupEntryPoint(entryPoint)
+ posthog.capture('marketing analytics dashboard setup opened', { entry_point: entryPoint, section })
+ actions.setSetupSection(section)
+ actions.setActiveTab(MarketingAnalyticsTab.SETUP)
+ },
+ setActiveTab: ({ tab }) => {
+ if (tab !== MarketingAnalyticsTab.SETUP && values.setupEntryPoint) {
+ actions.setSetupEntryPoint(null)
+ }
+ },
+ reportDashboardSectionViewed: ({ section, configured }) => {
+ posthog.capture('marketing analytics dashboard section viewed', {
+ section,
+ customer_goal_configured: configured.customerGoal,
+ revenue_goal_configured: configured.revenueGoal,
+ })
+ },
+ reportDashboardControlUsed: ({ section, control, value }) => {
+ posthog.capture('marketing analytics dashboard control used', { section, control, value })
+ },
// Track dashboard interactions for filters and chart controls
setDates: trackDashboardInteraction,
setDateInterval: trackDashboardInteraction,
@@ -1506,6 +1581,9 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
},
}
}),
+ beforeUnmount(({ actions }) => {
+ actions.setSetupEntryPoint(null)
+ }),
afterMount(({ actions }) => {
// Read URL params on initial mount (one-time sync from URL)
const searchParams = new URLSearchParams(router.values.location.search)
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.test.ts
index 93f5943da91a..f029c58df48b 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.test.ts
@@ -1,15 +1,121 @@
+import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
+import { useMocks } from '~/mocks/jest'
import { ConversionGoalFilter, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { TeamType } from '~/types'
import { marketingAnalyticsSettingsLogic } from './marketingAnalyticsSettingsLogic'
+jest.mock('posthog-js')
+
describe('marketing settings project changes', () => {
- beforeEach(() => initKeaTests())
+ beforeEach(() => {
+ jest.mocked(posthog.capture).mockClear()
+ useMocks({
+ patch: {
+ '/api/environments/:team_id': async ({ request }) => [
+ 200,
+ { ...teamLogic.values.currentTeam, ...((await request.json()) as Partial<TeamType>) },
+ ],
+ },
+ })
+ initKeaTests()
+ })
+
+ it('reports manual goal saves with the surface they came from', async () => {
+ const logic = marketingAnalyticsSettingsLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ const goal: ConversionGoalFilter = {
+ kind: NodeKind.EventsNode,
+ event: 'purchase',
+ conversion_goal_id: 'purchases',
+ conversion_goal_name: 'Purchases',
+ schema_map: {},
+ }
+
+ logic.actions.setSetupEntryPoint('dashboard_goal_suggestions')
+ await expectLogic(logic, () => logic.actions.addOrUpdateConversionGoal(goal)).toFinishAllListeners()
+ expect(posthog.capture).toHaveBeenCalledWith('marketing analytics settings updated', {
+ field: 'conversion_goals',
+ entry_point: 'project_settings',
+ })
+
+ await expectLogic(router, () => router.actions.push(urls.marketingAnalyticsApp())).toFinishAllListeners()
+ logic.actions.setSetupEntryPoint(null)
+ await expectLogic(logic, () => logic.actions.updateAttributionWindowDays(14)).toFinishAllListeners()
+ expect(posthog.capture).toHaveBeenCalledWith('marketing analytics settings updated', {
+ field: 'attribution_window_days',
+ entry_point: 'direct',
+ })
+ logic.actions.setSetupEntryPoint('dashboard_goal_suggestions')
+ await expectLogic(logic, () => logic.actions.removeConversionGoal('purchases')).toFinishAllListeners()
+ expect(posthog.capture).toHaveBeenCalledWith('marketing analytics settings updated', {
+ field: 'conversion_goals',
+ entry_point: 'dashboard_goal_suggestions',
+ })
+ logic.unmount()
+ })
+
+ it.each([200, 500])('reports a pending save only after a successful response (%s)', async (status) => {
+ const logic = marketingAnalyticsSettingsLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ let completeRequest!: () => void
+ const responseReady = new Promise<void>((resolve) => {
+ completeRequest = resolve
+ })
+ useMocks({
+ patch: {
+ '/api/environments/:team_id': async ({ request }) => {
+ const payload = (await request.json()) as Partial<TeamType>
+ await responseReady
+ return [status, { ...teamLogic.values.currentTeam, ...payload }]
+ },
+ },
+ })
+ await expectLogic(router, () => router.actions.push(urls.marketingAnalyticsApp())).toFinishAllListeners()
+ logic.actions.setSetupEntryPoint('dashboard_goal_suggestions')
+ const save = expectLogic(logic, () => logic.actions.updateAttributionWindowDays(14)).toDispatchActions([
+ teamLogic.actionTypes.updateCurrentTeam,
+ ])
+ await save
+ expect(posthog.capture).not.toHaveBeenCalledWith('marketing analytics settings updated', expect.anything())
+
+ logic.actions.setSetupEntryPoint(null)
+ router.actions.push(urls.settings('project'))
+ completeRequest()
+ await expectLogic(teamLogic).toFinishAllListeners()
+ const updates = jest
+ .mocked(posthog.capture)
+ .mock.calls.filter(([event]) => event === 'marketing analytics settings updated')
+ expect(updates).toEqual(
+ status === 200
+ ? [
+ [
+ 'marketing analytics settings updated',
+ { field: 'attribution_window_days', entry_point: 'dashboard_goal_suggestions' },
+ ],
+ ]
+ : []
+ )
+
+ await expectLogic(teamLogic, () =>
+ teamLogic.actions.updateCurrentTeam({ name: 'Updated project' })
+ ).toFinishAllListeners()
+ expect(
+ jest
+ .mocked(posthog.capture)
+ .mock.calls.filter(([event]) => event === 'marketing analytics settings updated')
+ ).toEqual(updates)
+ logic.unmount()
+ })
it('does not submit goals when changing the test-account filter', async () => {
const logic = marketingAnalyticsSettingsLogic()
@@ -22,6 +128,7 @@ describe('marketing settings project changes', () => {
}),
])
.toFinishAllListeners()
+ expect(posthog.capture).not.toHaveBeenCalledWith('marketing analytics settings updated', expect.anything())
logic.unmount()
})
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts
index 5eddb1d1bd08..7a1815f8d01b 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts
@@ -1,8 +1,12 @@
import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
+import { router } from 'kea-router'
+import posthog from 'posthog-js'
import api from 'lib/api'
+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
import {
AttributionMode,
@@ -61,6 +65,13 @@ const createEmptyConfig = (): MarketingAnalyticsConfig => ({
const isNativeMarketingSource = (value: string): value is NativeMarketingSource =>
VALID_NATIVE_MARKETING_SOURCES.includes(value as NativeMarketingSource)
+/** Lives here, not in marketingAnalyticsLogic: the logics that report it connect here and must not import the scene logic. */
+export type SetupEntryPoint =
+ | 'dashboard_source_suggestions'
+ | 'dashboard_goal_suggestions'
+ | 'dashboard_customer_cards'
+ | 'dashboard_revenue_banner'
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface marketingAnalyticsSettingsLogicValues {
dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // sourceManagementLogic
@@ -84,6 +95,8 @@ export interface marketingAnalyticsSettingsLogicValues {
marketingAnalyticsConfig: MarketingAnalyticsConfig | null
marketingAnalyticsConfigLoading: boolean
savedMarketingAnalyticsConfig: MarketingAnalyticsConfig
+ setupEntryPoint: SetupEntryPoint | null
+ setupEntryPointLabel: string
sources_map: Record<string, SourceMap>
testMappingResults: Record<string, TestMappingResult>
}
@@ -151,6 +164,9 @@ export interface marketingAnalyticsSettingsLogicActions {
}[]
integration: string
}
+ setSetupEntryPoint: (entryPoint: SetupEntryPoint | null) => {
+ entryPoint: SetupEntryPoint | null
+ }
setTestMappingResult: (
tableId: string,
result: TestMappingResult
@@ -201,6 +217,7 @@ export interface marketingAnalyticsSettingsLogicActions {
export interface marketingAnalyticsSettingsLogicMeta {
__keaTypeGenInternalSelectorTypes: {
sources_map: (marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => Record<string, SourceMap>
+ setupEntryPointLabel: (setupEntryPoint: SetupEntryPoint | null) => string
conversion_goals: (marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => ConversionGoalFilter[]
attribution_window_days: (marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => number
attribution_mode: (marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => AttributionMode
@@ -279,6 +296,7 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
initialCampaignName: string = ''
) => ({ integration, initialTab, initialUtmValue, initialCampaignName }),
closeIntegrationSettingsModal: true,
+ setSetupEntryPoint: (entryPoint: SetupEntryPoint | null) => ({ entryPoint }),
testMapping: (tableId: string, sourceMap: SourceMap) => ({ tableId, sourceMap }),
setTestMappingResult: (tableId: string, result: TestMappingResult) => ({ tableId, result }),
}),
@@ -467,6 +485,12 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
}),
},
],
+ setupEntryPoint: [
+ null as SetupEntryPoint | null,
+ {
+ setSetupEntryPoint: (_, { entryPoint }) => entryPoint,
+ },
+ ],
testMappingResults: [
{} as Record<string, TestMappingResult>,
{
@@ -486,6 +510,10 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
(s) => [s.marketingAnalyticsConfig],
(marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => marketingAnalyticsConfig?.sources_map || {},
],
+ setupEntryPointLabel: [
+ (s) => [s.setupEntryPoint],
+ (setupEntryPoint: SetupEntryPoint | null): string => setupEntryPoint ?? 'direct',
+ ],
conversion_goals: [
(s) => [s.marketingAnalyticsConfig],
(marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => {
@@ -552,9 +580,23 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
],
}),
listeners(({ actions, values }) => {
+ const pendingSettingsUpdates = new WeakMap<
+ Partial<TeamType>,
+ { field: keyof MarketingAnalyticsConfig; entry_point: string }
+ >()
+
const updateCurrentTeam = (field: keyof MarketingAnalyticsConfig): void => {
if (values.marketingAnalyticsConfig) {
const payload = { marketing_analytics_config: { [field]: values.marketingAnalyticsConfig[field] } }
+ if (field !== 'filter_test_accounts') {
+ // The same settings components render under project settings, outside the marketing app.
+ const inMarketingApp =
+ removeProjectIdIfPresent(router.values.location.pathname) === urls.marketingAnalyticsApp()
+ pendingSettingsUpdates.set(payload, {
+ field,
+ entry_point: inMarketingApp ? values.setupEntryPointLabel : 'project_settings',
+ })
+ }
actions.updateCurrentTeam(payload)
}
}
@@ -576,6 +618,13 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
}
return {
+ [teamLogic.actionTypes.updateCurrentTeamSuccess]: ({ payload }) => {
+ const properties = payload && pendingSettingsUpdates.get(payload)
+ if (properties) {
+ pendingSettingsUpdates.delete(payload)
+ posthog.capture('marketing analytics settings updated', properties)
+ }
+ },
updateSourceMapping: trackSourceConfigured,
updateConversionGoals: () => trackSettingsUpdated('conversion_goals'),
addOrUpdateConversionGoal: () => trackSettingsUpdated('conversion_goals'),
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.test.ts
index df5eb1892164..a74bbe64e76f 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.test.ts
@@ -81,6 +81,7 @@ describe('setupPlanLogic', () => {
expect(applyRequests[0].ops).toEqual([suggestion().apply])
expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup change completed', {
source: 'setup_tab',
+ entry_point: 'direct',
operation_types: ['add_custom_source_mapping'],
requested_count: 1,
applied_count: 0,
@@ -88,6 +89,21 @@ describe('setupPlanLogic', () => {
})
})
+ it('attributes a change to the dashboard surface that opened Setup', async () => {
+ marketingAnalyticsSettingsLogic.actions.setSetupEntryPoint('dashboard_source_suggestions')
+ await expectLogic(logic, () => logic.actions.reviewSuggestion(suggestion())).toFinishAllListeners()
+ await expectLogic(logic, () => logic.actions.applySuggestion(suggestion())).toFinishAllListeners()
+
+ expect(posthog.capture).toHaveBeenCalledWith(
+ 'marketing analytics setup suggestion reviewed',
+ expect.objectContaining({ entry_point: 'dashboard_source_suggestions' })
+ )
+ expect(posthog.capture).toHaveBeenCalledWith(
+ 'marketing analytics setup change completed',
+ expect.objectContaining({ entry_point: 'dashboard_source_suggestions' })
+ )
+ })
+
it('collapses the row optimistically once the op succeeds', async () => {
await expectLogic(logic, () => logic.actions.loadSetupPlan()).toFinishAllListeners()
expect(logic.values.visibleSuggestions).toHaveLength(1)
@@ -135,6 +151,7 @@ describe('setupPlanLogic', () => {
expect(applyRequests[0].ops).toEqual(UNDO_OPS)
expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup change completed', {
source: 'setup_tab',
+ entry_point: 'direct',
operation_types: ['remove_custom_source_mapping'],
requested_count: 1,
applied_count: 0,
@@ -153,10 +170,17 @@ describe('setupPlanLogic', () => {
await expectLogic(logic, () => logic.actions.loadSetupPlan()).toFinishAllListeners()
expect(logic.values.safeBatch.map((s) => s.id)).toEqual([suggestion().id])
+ marketingAnalyticsSettingsLogic.actions.setSetupEntryPoint('dashboard_source_suggestions')
+ logic.actions.reviewSafeBatch()
+ expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup batch reviewed', {
+ count: 1,
+ entry_point: 'dashboard_source_suggestions',
+ })
await expectLogic(logic, () => logic.actions.applyAllSafe()).toFinishAllListeners()
expect(applyRequests[0].ops).toEqual([suggestion().apply])
expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup change completed', {
source: 'apply_all_safe',
+ entry_point: 'dashboard_source_suggestions',
operation_types: ['add_custom_source_mapping'],
requested_count: 1,
applied_count: 0,
@@ -244,6 +268,7 @@ describe('setupPlanLogic', () => {
expect(logic.values.reviewingSuggestion).not.toBeNull()
expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup change failed', {
source: 'setup_tab',
+ entry_point: 'direct',
operation_types: ['add_custom_source_mapping'],
requested_count: 1,
is_undo: false,
@@ -280,6 +305,7 @@ describe('setupPlanLogic', () => {
expect(applyRequests).toHaveLength(0)
expect(posthog.capture).toHaveBeenCalledWith('marketing analytics setup suggestion dismissed', {
kind: 'add_source_mapping',
+ entry_point: 'direct',
})
})
@@ -297,6 +323,7 @@ describe('setupPlanLogic', () => {
kind: 'add_source_mapping',
source: 'deterministic',
integration: 'MetaAds',
+ entry_point: 'direct',
},
],
])
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.ts
index 79dccc2edffd..9e1a850824f8 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/setupPlanLogic.ts
@@ -83,6 +83,7 @@ interface ApplyResponse {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface setupPlanLogicValues {
+ setupEntryPointLabel: string // marketingAnalyticsSettingsLogic
currentTeamId: number | null // teamLogic
appliedCount: number
applyingIds: string[]
@@ -222,7 +223,7 @@ export type setupPlanLogicType = MakeLogicType<
export const setupPlanLogic = kea<setupPlanLogicType>([
path(['scenes', 'web-analytics', 'tabs', 'marketing-analytics', 'frontend', 'logic', 'setupPlanLogic']),
connect(() => ({
- values: [teamLogic, ['currentTeamId']],
+ values: [teamLogic, ['currentTeamId'], marketingAnalyticsSettingsLogic, ['setupEntryPointLabel']],
actions: [
teamLogic,
['loadCurrentTeam'],
@@ -416,39 +417,60 @@ export const setupPlanLogic = kea<setupPlanLogicType>([
kind: suggestion.kind,
source: suggestion.source,
integration: suggestion.integration,
+ entry_point: values.setupEntryPointLabel,
})
}
},
reviewSafeBatch: () => {
- posthog.capture('marketing analytics setup batch reviewed', { count: values.safeBatch.length })
+ posthog.capture('marketing analytics setup batch reviewed', {
+ count: values.safeBatch.length,
+ entry_point: values.setupEntryPointLabel,
+ })
},
dismissSuggestion: ({ id }) => {
const suggestion = values.suggestions.find((item) => item.id === id)
if (suggestion) {
- posthog.capture('marketing analytics setup suggestion dismissed', { kind: suggestion.kind })
+ posthog.capture('marketing analytics setup suggestion dismissed', {
+ kind: suggestion.kind,
+ entry_point: values.setupEntryPointLabel,
+ })
}
},
restoreSuggestion: ({ id }) => {
const suggestion = values.suggestions.find((item) => item.id === id)
if (suggestion) {
- posthog.capture('marketing analytics setup suggestion restored', { kind: suggestion.kind })
+ posthog.capture('marketing analytics setup suggestion restored', {
+ kind: suggestion.kind,
+ entry_point: values.setupEntryPointLabel,
+ })
}
},
restoreAllDismissed: () => {
- posthog.capture('marketing analytics setup suggestions restored')
+ posthog.capture('marketing analytics setup suggestions restored', {
+ entry_point: values.setupEntryPointLabel,
+ })
},
toggleShowDismissed: () => {
- posthog.capture('marketing analytics setup dismissed toggled', { shown: values.showDismissed })
+ posthog.capture('marketing analytics setup dismissed toggled', {
+ shown: values.showDismissed,
+ entry_point: values.setupEntryPointLabel,
+ })
},
focusCapability: () => {
- posthog.capture('marketing analytics setup capability filtered', { capability: values.focusedCapability })
+ posthog.capture('marketing analytics setup capability filtered', {
+ capability: values.focusedCapability,
+ entry_point: values.setupEntryPointLabel,
+ })
},
loadSetupPlan: ({ refresh } = {}) => {
if (refresh) {
- posthog.capture('marketing analytics setup rescan requested')
+ posthog.capture('marketing analytics setup rescan requested', {
+ entry_point: values.setupEntryPointLabel,
+ })
}
},
retrySync: async ({ suggestionId, targets }) => {
+ const entryPoint = values.setupEntryPointLabel
// Goes straight to the warehouse endpoint rather than through
// apply_setup_ops: the warehouse owns this action and its permissions, and
// the apply endpoint only mutates marketing config.
@@ -466,6 +488,7 @@ export const setupPlanLogic = kea<setupPlanLogicType>([
}
}
posthog.capture('marketing analytics setup sync retry completed', {
+ entry_point: entryPoint,
requested_count: targets.length,
failed_count: failed.length,
})
@@ -565,6 +588,7 @@ export const setupPlanLogic = kea<setupPlanLogicType>([
const inFlight = options.suggestionIds ?? []
const properties = {
source: options.source,
+ entry_point: values.setupEntryPointLabel,
operation_types: [...new Set(ops.map(({ op }) => op))],
requested_count: ops.length,
is_undo: !options.undoable,
diff --git a/products/marketing_analytics/frontend/dashboard/NewMarketingAnalyticsDashboard.tsx b/products/marketing_analytics/frontend/dashboard/NewMarketingAnalyticsDashboard.tsx
index 64c854054c7d..1a8c889019ab 100644
--- a/products/marketing_analytics/frontend/dashboard/NewMarketingAnalyticsDashboard.tsx
+++ b/products/marketing_analytics/frontend/dashboard/NewMarketingAnalyticsDashboard.tsx
@@ -15,7 +15,6 @@ import { AttributionTab } from 'scenes/web-analytics/tabs/marketing-analytics/fr
import { AttributionTable } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/components/AttributionTab/AttributionTable'
import { RetentionTab } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/components/RetentionTab/RetentionTab'
import {
- MarketingAnalyticsTab,
SetupSection,
marketingAnalyticsLogic,
} from 'scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic'
@@ -103,22 +102,17 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
} = useValues(marketingAcquisitionLogic)
const { setCustomerGoalId, toggleTrafficSort, setTrafficChartMetric } = useActions(marketingAcquisitionLogic)
const { dateFilter, compareFilter, shouldFilterTestAccounts } = useValues(marketingAnalyticsLogic)
- const { setDates, setCompareFilter, setActiveTab, setSetupSection } = useActions(marketingAnalyticsLogic)
+ const { setDates, setCompareFilter, openSetup, reportDashboardSectionViewed, reportDashboardControlUsed } =
+ useActions(marketingAnalyticsLogic)
const { setupPlan, setupPlanLoading, visibleSuggestions } = useValues(setupPlanLogic)
const { loadSetupPlan, reviewSuggestion } = useActions(setupPlanLogic)
const [sourcesExpanded, setSourcesExpanded] = useLocalStorage('marketing-source-suggestions-expanded', false)
const sourceSuggestions = visibleSuggestions.filter((suggestion) => suggestion.kind === 'connect_source')
- const reviewSources = (): void => {
- setSetupSection(SetupSection.SOURCES)
- setActiveTab(MarketingAnalyticsTab.SETUP)
- }
+ const reviewSources = (): void => openSetup(SetupSection.SOURCES, 'dashboard_source_suggestions')
const [goalsExpanded, setGoalsExpanded] = useLocalStorage('marketing-goal-suggestions-expanded', false)
const goalSuggestions = suggestionsForSection(visibleSuggestions, SetupSection.CONVERSION_GOALS)
- const reviewGoals = (): void => {
- setSetupSection(SetupSection.CONVERSION_GOALS)
- setActiveTab(MarketingAnalyticsTab.SETUP)
- }
+ const reviewGoals = (): void => openSetup(SetupSection.CONVERSION_GOALS, 'dashboard_goal_suggestions')
const requestedSetupPlan = useRef(false)
useEffect(() => {
@@ -128,6 +122,20 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
}
}, [setupPlan, setupPlanLoading, loadSetupPlan])
+ const reportedSection = useRef<string | null>(null)
+ useEffect(() => {
+ if (currentTeamLoading || reportedSection.current === activeSection) {
+ return
+ }
+ reportedSection.current = activeSection
+ reportDashboardSectionViewed(activeSection, {
+ customerGoal: !!customerConversionGoal,
+ revenueGoal: !!revenueQuery,
+ })
+ }, [activeSection, currentTeamLoading, customerConversionGoal, revenueQuery, reportDashboardSectionViewed])
+ const reportControl = (control: string, value?: string | boolean): void =>
+ reportDashboardControlUsed(activeSection, control, value)
+
const dateRange = { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo }
const query: WebOverviewQuery = {
kind: NodeKind.WebOverviewQuery,
@@ -153,10 +161,7 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
} = useValues(customerOverviewLogic)
const { loadData: loadCustomers } = useActions(customerOverviewLogic)
const customerOverview = customerResponse as WebOverviewQueryResponse | undefined
- const reviewCustomerGoals = (): void => {
- setSetupSection(SetupSection.CONVERSION_GOALS)
- setActiveTab(MarketingAnalyticsTab.SETUP)
- }
+ const reviewCustomerGoals = (): void => openSetup(SetupSection.CONVERSION_GOALS, 'dashboard_customer_cards')
return (
<div className="mt-4 flex flex-col gap-4">
@@ -172,6 +177,7 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
(activeSection === 'acquisition' && !!customerConversionGoal && customersLoading)
}
onClick={() => {
+ reportControl('reload_summary')
loadData('force_async')
if (activeSection === 'acquisition' && customerConversionGoal) {
loadCustomers('force_async')
@@ -193,7 +199,10 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
embedded
size="small"
activeKey={sourcesExpanded ? 'sources' : null}
- onChange={(key) => setSourcesExpanded(key !== null)}
+ onChange={(key) => {
+ reportControl('source_suggestions', key !== null)
+ setSourcesExpanded(key !== null)
+ }}
panels={[
{
key: 'sources',
@@ -226,7 +235,10 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
embedded
size="small"
activeKey={goalsExpanded ? 'goals' : null}
- onChange={(key) => setGoalsExpanded(key !== null)}
+ onChange={(key) => {
+ reportControl('goal_suggestions', key !== null)
+ setGoalsExpanded(key !== null)
+ }}
panels={[
{
key: 'goals',
@@ -329,7 +341,10 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
<LemonSelect
aria-label="Customer goal"
value={selectedCustomerGoal?.conversion_goal_id}
- onChange={setCustomerGoalId}
+ onChange={(value) => {
+ reportControl('customer_goal')
+ setCustomerGoalId(value)
+ }}
options={customerGoals.map((goal) => ({
value: goal.conversion_goal_id,
label: goal.conversion_goal_name,
@@ -377,7 +392,12 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
/>
<LemonSelect
value={selectedRevenueGoalId}
- onChange={(value) => value && setRevenueGoalId(value)}
+ onChange={(value) => {
+ if (value) {
+ reportControl('revenue_goal')
+ setRevenueGoalId(value)
+ }
+ }}
options={revenueGoals.map((goal) => ({
value: goal.conversion_goal_id,
label: goal.conversion_goal_name,
@@ -386,7 +406,10 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
/>
<LemonSelect
value={breakdownBy}
- onChange={setBreakdownBy}
+ onChange={(value) => {
+ reportControl('revenue_breakdown', value)
+ setBreakdownBy(value)
+ }}
options={Object.values(MarketingAnalyticsAttributionBreakdown).map((value) => ({
value,
label: BREAKDOWN_LABELS[value],
@@ -408,10 +431,7 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
type="info"
action={{
children: 'Review in Setup',
- onClick: () => {
- setSetupSection(SetupSection.CONVERSION_GOALS)
- setActiveTab(MarketingAnalyticsTab.SETUP)
- },
+ onClick: () => openSetup(SetupSection.CONVERSION_GOALS, 'dashboard_revenue_banner'),
}}
>
Choose an event or action goal that sums an amount and mark it as Revenue in Setup.
@@ -430,7 +450,12 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
<LemonSelect
size="small"
value={trafficChartMetric}
- onChange={(value) => value && setTrafficChartMetric(value)}
+ onChange={(value) => {
+ if (value) {
+ reportControl('chart_metric', value)
+ setTrafficChartMetric(value)
+ }
+ }}
options={TRAFFIC_CHART_METRICS.map(({ value, label }) => ({
value,
label,
@@ -477,7 +502,10 @@ export function NewMarketingAnalyticsDashboard(): JSX.Element {
<span>Breakdown by</span>
<LemonSelect
value={trafficBreakdown}
- onChange={setTrafficBreakdown}
+ onChange={(value) => {
+ reportControl('traffic_breakdown', value)
+ setTrafficBreakdown(value)
+ }}
options={TRAFFIC_BREAKDOWNS}
aria-label="Traffic breakdown"
/>