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.

refactor(dashboards): move dashboard event tracking into dashboardEvents (#123708)

Paul D'Ambra6b917ef877d5
diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
index 6327a771dbc0..1c421dcaf2d4 100644
--- a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
+++ b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
@@ -31,6 +31,7 @@ import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { capitalizeFirstLetter } from 'lib/utils/strings'
+import { reportDashboardInsightMetaUpdated } from 'scenes/dashboard/dashboardEvents'
import { getEffectiveDateOverride } from 'scenes/dashboard/dashboardUtils'
import { dataRetentionBannerLogic } from 'scenes/insights/dataRetention/dataRetentionBannerLogic'
import { exceedsRetention } from 'scenes/insights/dataRetention/exceedsRetention'
@@ -216,7 +217,7 @@ export function InsightMeta({
const { copyImage } = useActions(captureImageLogic)
const { isCapturing: isCapturingImage } = useValues(captureImageLogic)
const { updateInsightDirect } = useActions(insightsModel)
- const { reportDashboardInsightMetaUpdated, reportInsightResultsCopiedToClipboard } = useActions(eventUsageLogic)
+ const { reportInsightResultsCopiedToClipboard } = useActions(eventUsageLogic)
const { featureFlags } = useValues(featureFlagLogic)
const showCompactTile =
diff --git a/frontend/src/lib/utils/eventUsageLogic.test.ts b/frontend/src/lib/utils/eventUsageLogic.test.ts
index ce6a599603d0..833309477af0 100644
--- a/frontend/src/lib/utils/eventUsageLogic.test.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.test.ts
@@ -14,21 +14,13 @@ import {
BaseMathType,
BehavioralEventType,
ChartDisplayType,
- type DashboardTile,
- type DashboardType,
FilterLogicalOperator,
FunnelVizType,
PropertyFilterType,
StepOrderValue,
} from '~/types'
-import {
- dashboardViewedProperties,
- eventUsageLogic,
- getEventPropertiesForMetric,
- sanitizeDashboard,
- sanitizeQuery,
-} from './eventUsageLogic'
+import { eventUsageLogic, getEventPropertiesForMetric, sanitizeQuery } from './eventUsageLogic'
describe('eventUsageLogic', () => {
describe('experiments list viewed', () => {
@@ -377,108 +369,6 @@ describe('eventUsageLogic', () => {
})
})
- it('keeps metric variable definitions out of a sanitized dashboard', () => {
- const metricVariables = [{ name: 'env', source: 'sql', query: 'SELECT private_value' }]
- const tile = { id: 1, insight: { id: 2, filter_override_context: { dashboard: { metricVariables } } } }
- const dashboard = { id: 7, tiles: [tile], filters: { metricVariables }, persisted_filters: { metricVariables } }
-
- const sanitized = sanitizeDashboard(dashboard as unknown as DashboardType)
-
- expect(JSON.stringify(sanitized)).not.toContain('private_value')
- })
-
- describe('dashboardViewedProperties', () => {
- const dashboard = (tiles: Partial<DashboardTile>[]): DashboardType =>
- ({
- id: 7,
- created_at: '2026-01-01T00:00:00Z',
- is_shared: false,
- pinned: true,
- creation_mode: 'default',
- created_by: { uuid: 'creator' },
- tiles,
- }) as unknown as DashboardType
-
- const insightTile = (query: unknown, is_sample = false): Partial<DashboardTile> =>
- ({ insight: { query, is_sample } }) as unknown as Partial<DashboardTile>
-
- const cases: [string, Partial<DashboardTile>[], Record<string, unknown>][] = [
- ['no tiles', [], { item_count: 0, sample_items_count: 0 }],
- [
- 'an insight tile with a query',
- [insightTile({ kind: NodeKind.InsightVizNode, source: { kind: NodeKind.TrendsQuery, series: [] } })],
- { item_count: 1, text_count: 1, uses_data_warehouse_source: false, data_warehouse_tiles_count: 0 },
- ],
- ['an insight tile without a query', [insightTile(null)], { item_count: 1, empty_count: 1 }],
- [
- 'a sample insight tile that reads the warehouse',
- [insightTile({ kind: NodeKind.TrendsQuery, series: [{ kind: NodeKind.DataWarehouseNode }] }, true)],
- {
- item_count: 1,
- text_count: 1,
- sample_items_count: 1,
- uses_data_warehouse_source: true,
- data_warehouse_tiles_count: 1,
- },
- ],
- [
- 'text and widget tiles',
- [{ text: { body: 'hi' } }, { text: { body: 'there' } }, { widget: {} }] as Partial<DashboardTile>[],
- { item_count: 3, text_tiles_count: 2, widget_tiles_count: 1 },
- ],
- [
- 'groups once however many tiles share a key',
- [
- { group_key: 'a' },
- { group_key: 'a' },
- { group_key: 'b' },
- { group_key: null },
- ] as Partial<DashboardTile>[],
- { item_count: 4, text_tiles_count: 4, group_count: 2 },
- ],
- ]
-
- it.each(cases)('counts %s', (_, tiles, expected) => {
- expect(dashboardViewedProperties(dashboard(tiles), null, 'viewer')).toEqual({
- created_at: '2026-01-01T00:00:00Z',
- is_shared: false,
- pinned: true,
- creation_mode: 'default',
- viewer_is_creator: false,
- created_by_system: false,
- dashboard_id: 7,
- group_display: 'sections',
- group_count: 0,
- lastRefreshed: undefined,
- refreshAge: undefined,
- sample_items_count: 0,
- uses_data_warehouse_source: false,
- data_warehouse_tiles_count: 0,
- ...expected,
- })
- })
-
- it('reports the dashboard group display', () => {
- const withTabs = { ...dashboard([]), customization: { group_display: 'tabs' } } as unknown as DashboardType
- expect(dashboardViewedProperties(withTabs, null, 'viewer')).toMatchObject({ group_display: 'tabs' })
- })
-
- const viewerCases: [string, { uuid: string } | null, string | undefined, boolean | undefined][] = [
- ['the creator views it', { uuid: 'creator' }, 'creator', true],
- ['another user views it', { uuid: 'creator' }, 'viewer', false],
- ['the viewer is unknown', { uuid: 'creator' }, undefined, undefined],
- ['the system created it', null, 'viewer', undefined],
- ]
-
- it.each(viewerCases)('reports viewer_is_creator when %s', (_, created_by, viewerUuid, expected) => {
- const withCreator = { ...dashboard([]), created_by } as unknown as DashboardType
- expect(dashboardViewedProperties(withCreator, null, viewerUuid)).toMatchObject({
- viewer_is_creator: expected,
- created_by_system: created_by === null,
- })
- })
- })
-
it('reports only the kind for a legacy metric', () => {
const metric = {
kind: NodeKind.ExperimentFunnelsQuery,
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 819c36c661de..787a9367d7be 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -2,8 +2,6 @@ import { MakeLogicType, actions, connect, kea, listeners, path } from 'kea'
import posthog from 'posthog-js'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
-import type { Dayjs } from 'lib/dayjs'
-import { now } from 'lib/dayjs'
import type { IntegrationConnectSurface, IntegrationLinkExistingCounts } from 'lib/integrations/utils'
import { TimeToSeeDataPayload } from 'lib/internalMetrics'
import { preflightLogic } from 'lib/logic/preflightLogic'
@@ -56,10 +54,6 @@ import {
import {
ChartDisplayType,
CohortType,
- DashboardTileSpacing,
- DashboardMode,
- DashboardTile,
- DashboardType,
Experiment,
ExperimentHoldoutType,
ExperimentIdType,
@@ -68,7 +62,6 @@ import {
PropertyFilterType,
InsightModel,
type SDK,
- TileGroupDisplay,
} from '~/types'
import { captureBIWorksheetAction } from 'products/business_intelligence/frontend/biEditorAnalytics'
@@ -98,16 +91,6 @@ export enum DashboardEventSource {
DashboardVariableOverride = 'dashboard_variable_override',
}
-export type DashboardFilterChangeType =
- | 'date'
- | 'properties'
- | 'breakdown'
- | 'variable'
- | 'interval'
- | 'test_accounts'
- | 'compare'
- | 'metric_variables'
-
export enum InsightEventSource {
LongPress = 'long_press',
MoreDropdown = 'more_dropdown',
@@ -608,34 +591,6 @@ export function sanitizeInsight(insight: Partial<InsightModel> | null): object |
return sanitizedInsight
}
-function sanitizeTile(tile: DashboardTile | null): object | undefined {
- if (!tile) {
- return undefined
- }
-
- return {
- ...tile,
- insight: tile.insight ? sanitizeInsight(tile.insight) : undefined,
- }
-}
-
-export function sanitizeDashboard(dashboard: DashboardType | null): object | null {
- if (!dashboard) {
- return null
- }
-
- // Remove breakdown color entries, as they carry raw breakdown values (user data) — report only their count
- const { breakdown_colors, ...sanitizedDashboard } = dashboard
-
- return {
- ...sanitizedDashboard,
- breakdown_colors_count: breakdown_colors?.length ?? 0,
- filters: filtersForAnalytics(dashboard.filters ?? {}),
- persisted_filters: dashboard.persisted_filters ? filtersForAnalytics(dashboard.persisted_filters) : null,
- tiles: dashboard.tiles?.map((tile) => sanitizeTile(tile)) || [],
- }
-}
-
function countBehavioralFilters(value: unknown): number {
if (Array.isArray(value)) {
return value.reduce((count, item) => count + countBehavioralFilters(item), 0)
@@ -712,69 +667,6 @@ function funnelProperties(querySource: InsightQueryNode): SanitizedQuery {
}
}
-function increment(counts: Record<string, any>, key: string): void {
- counts[key] = (counts[key] || 0) + 1
-}
-
-function insightTileCountKey(tile: DashboardTile): string {
- const query = isNodeWithSource(tile.insight?.query) ? tile.insight.query.source : tile.insight?.query
- return `${query?.kind || !!tile.text ? 'text' : 'empty'}_count`
-}
-
-function countDashboardTiles(tiles: DashboardTile[], properties: Record<string, any>): void {
- for (const tile of tiles) {
- if (tile.insight) {
- increment(properties, insightTileCountKey(tile))
- properties.sample_items_count += tile.insight.is_sample ? 1 : 0
- if (queryUsesDataWarehouse(tile.insight.query)) {
- properties.uses_data_warehouse_source = true
- properties.data_warehouse_tiles_count += 1
- }
- } else if (tile.widget) {
- increment(properties, 'widget_tiles_count')
- } else {
- increment(properties, 'text_tiles_count')
- }
- }
-}
-
-export function tileGroupProperties(
- groupDisplay: TileGroupDisplay | undefined,
- tiles: DashboardTile[]
-): { group_display: TileGroupDisplay; group_count: number } {
- return {
- group_display: groupDisplay ?? 'sections',
- group_count: new Set(tiles.map((tile) => tile.group_key).filter(Boolean)).size,
- }
-}
-
-export function dashboardViewedProperties(
- dashboard: DashboardType,
- lastRefreshed: Dayjs | null,
- viewerUuid: string | undefined
-): Record<string, any> {
- const { created_at, is_shared, pinned, creation_mode, id } = dashboard
- const properties: Record<string, any> = {
- created_at,
- is_shared,
- pinned,
- creation_mode,
- viewer_is_creator:
- dashboard.created_by?.uuid && viewerUuid ? dashboard.created_by.uuid === viewerUuid : undefined,
- sample_items_count: 0,
- item_count: dashboard.tiles?.length || 0,
- created_by_system: !dashboard.created_by,
- dashboard_id: id,
- ...tileGroupProperties(dashboard.customization?.group_display, dashboard.tiles || []),
- lastRefreshed: lastRefreshed?.toISOString(),
- refreshAge: lastRefreshed ? now().diff(lastRefreshed, 'seconds') : undefined,
- uses_data_warehouse_source: false,
- data_warehouse_tiles_count: 0,
- }
- countDashboardTiles(dashboard.tiles || [], properties)
- return properties
-}
-
/** Takes a query and returns an object with "useful" properties that don't contain sensitive data. */
export function sanitizeQuery(query: Node | null): SanitizedQuery {
const payload: SanitizedQuery = {
@@ -938,95 +830,6 @@ export interface eventUsageLogicActions {
journeyName: string
stepCount: number
}
- reportDashboardAddMenuOpened: (
- source: 'header',
- dashboardId: number
- ) => {
- dashboardId: number
- source: 'header'
- }
- reportDashboardEditModeDiscardPrompt: (
- dashboard: DashboardType | null,
- action: 'discarded' | 'kept_editing' | 'shown'
- ) => {
- action: 'discarded' | 'kept_editing' | 'shown'
- dashboard: DashboardType | null
- }
- reportDashboardEmptyAddChartClicked: (dashboardId: number | undefined) => {
- dashboardId: number | undefined
- }
- reportDashboardEmptyAiPromptSubmitted: (
- dashboardId: number | undefined,
- promptType: 'custom_prompt' | 'starter_question'
- ) => {
- dashboardId: number | undefined
- promptType: 'custom_prompt' | 'starter_question'
- }
- reportDashboardEmptyWebAnalyticsClicked: (dashboardId: number | undefined) => {
- dashboardId: number | undefined
- }
- reportDashboardFiltersChanged: (
- dashboard: DashboardType | null,
- changeType: DashboardFilterChangeType,
- properties: Record<string, boolean | number | string | null | undefined>
- ) => {
- changeType: DashboardFilterChangeType
- dashboard: DashboardType | null
- properties: Record<string, boolean | number | string | null | undefined>
- }
- reportDashboardInsightDeleteAfterRemovalClicked: (otherDashboardCount: number) => {
- otherDashboardCount: number
- }
- reportDashboardInsightMetaUpdated: (
- dashboardId: number | undefined,
- insightId: number,
- attribute: 'description' | 'name'
- ) => {
- attribute: 'description' | 'name'
- dashboardId: number | undefined
- insightId: number
- }
- reportDashboardLayoutEditModeEntered: (
- dashboard: DashboardType | null,
- source: DashboardEventSource,
- layoutZoom: number | null
- ) => {
- dashboard: DashboardType | null
- layoutZoom: number | null
- source: DashboardEventSource
- }
- reportDashboardModeToggled: (
- dashboard: DashboardType | null,
- mode: DashboardMode | null,
- source: DashboardEventSource | null,
- layoutZoom: number | null,
- layoutEditMode?: boolean
- ) => {
- dashboard: DashboardType | null
- layoutEditMode: boolean | undefined
- layoutZoom: number | null
- mode: DashboardMode | null
- source: DashboardEventSource | null
- }
- reportDashboardMoveInitiated: (
- method: 'bulk' | 'single',
- count: number
- ) => {
- count: number
- method: 'bulk' | 'single'
- }
- reportDashboardTileDensityConfigured: (tileDensity: DashboardTileSpacing) => {
- tileDensity: DashboardTileSpacing
- }
- reportDashboardTileRepositioned: (
- dashboardId: number,
- action: 'moved' | 'resized',
- layoutZoom: number
- ) => {
- action: 'moved' | 'resized'
- dashboardId: number
- layoutZoom: number
- }
reportDataManagementDefinitionClickEdit: (type: TaxonomicFilterGroupType) => {
type: TaxonomicFilterGroupType
}
@@ -1729,47 +1532,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportProjectCreationSubmitted: (projectCount: number, nameLength: number) => ({ projectCount, nameLength }),
reportProjectNoticeDismissed: (key: string) => ({ key }),
reportProjectNoticeShown: (variant: string) => ({ variant }),
- reportDashboardModeToggled: (
- dashboard: DashboardType | null,
- mode: DashboardMode | null,
- source: DashboardEventSource | null,
- layoutZoom: number | null,
- layoutEditMode?: boolean
- ) => ({ dashboard, mode, source, layoutZoom, layoutEditMode }),
- reportDashboardLayoutEditModeEntered: (
- dashboard: DashboardType | null,
- source: DashboardEventSource,
- layoutZoom: number | null
- ) => ({ dashboard, source, layoutZoom }),
- reportDashboardFiltersChanged: (
- dashboard: DashboardType | null,
- changeType: DashboardFilterChangeType,
- properties: Record<string, string | number | boolean | null | undefined>
- ) => ({ dashboard, changeType, properties }),
- reportDashboardTileDensityConfigured: (tileDensity: DashboardTileSpacing) => ({ tileDensity }),
- reportDashboardEditModeDiscardPrompt: (
- dashboard: DashboardType | null,
- action: 'shown' | 'discarded' | 'kept_editing'
- ) => ({ dashboard, action }),
- reportDashboardMoveInitiated: (method: 'single' | 'bulk', count: number) => ({ method, count }),
- reportDashboardInsightDeleteAfterRemovalClicked: (otherDashboardCount: number) => ({ otherDashboardCount }),
- reportDashboardTileRepositioned: (dashboardId: number, action: 'moved' | 'resized', layoutZoom: number) => ({
- dashboardId,
- action,
- layoutZoom,
- }),
- reportDashboardInsightMetaUpdated: (
- dashboardId: number | undefined,
- insightId: number,
- attribute: 'name' | 'description'
- ) => ({ dashboardId, insightId, attribute }),
- /** Empty-state AI prompt chips (ai-first empty dashboard only). */
- reportDashboardEmptyAiPromptSubmitted: (
- dashboardId: number | undefined,
- promptType: 'custom_prompt' | 'starter_question'
- ) => ({ dashboardId, promptType }),
- reportDashboardEmptyAddChartClicked: (dashboardId: number | undefined) => ({ dashboardId }),
- reportDashboardEmptyWebAnalyticsClicked: (dashboardId: number | undefined) => ({ dashboardId }),
reportTimezoneComponentViewed: (
component: 'label' | 'indicator',
project_timezone?: string,
@@ -1782,7 +1544,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportSessionTableVersionUpdated: (version: string) => ({ version }),
reportCustomChannelTypeRulesUpdated: (numRules: number) => ({ numRules }),
reportCreatedDashboardFromModal: true,
- reportDashboardAddMenuOpened: (source: 'header', dashboardId: number) => ({ source, dashboardId }),
/** Dashboard created via PostHog web app from a template (new dashboard modal / template chooser). */
reportSavedInsightToDashboard: (insight: Partial<InsightModel> | null, dashboardId: number | null) => ({
insight,
@@ -2220,82 +1981,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportDataTableColumnsUpdated: async ({ context_type }) => {
posthog.capture('data table columns updated', { context_type })
},
- reportDashboardModeToggled: async ({ dashboard, mode, source, layoutZoom, layoutEditMode }) => {
- posthog.capture('dashboard mode toggled', {
- dashboard_id: dashboard?.id,
- dashboard: sanitizeDashboard(dashboard),
- mode,
- source,
- layout_zoom: layoutZoom ?? undefined,
- layout_edit_mode: layoutEditMode ?? undefined,
- })
- },
- reportDashboardLayoutEditModeEntered: async ({ dashboard, source, layoutZoom }) => {
- posthog.capture('dashboard layout edit mode entered', {
- dashboard_id: dashboard?.id,
- dashboard: sanitizeDashboard(dashboard),
- source,
- layout_zoom: layoutZoom ?? undefined,
- })
- },
- reportDashboardFiltersChanged: async ({ dashboard, changeType, properties }) => {
- posthog.capture('dashboard filters changed', {
- dashboard_id: dashboard?.id,
- change_type: changeType,
- ...properties,
- })
- },
- reportDashboardTileDensityConfigured: async ({ tileDensity }) => {
- posthog.capture('dashboard tile density configured', { tile_density: tileDensity })
- },
- reportDashboardEditModeDiscardPrompt: async ({ dashboard, action }) => {
- posthog.capture('dashboard edit mode discard prompt', {
- dashboard_id: dashboard?.id,
- dashboard: sanitizeDashboard(dashboard),
- action,
- })
- },
- reportDashboardMoveInitiated: async ({ method, count }) => {
- posthog.capture('dashboard move initiated', { method, count })
- },
- reportDashboardTileRepositioned: async ({ dashboardId, action, layoutZoom }) => {
- posthog.capture('dashboard tile repositioned', {
- dashboard_id: dashboardId,
- action,
- layout_zoom: layoutZoom,
- })
- },
- reportDashboardInsightMetaUpdated: async ({ dashboardId, insightId, attribute }) => {
- posthog.capture('dashboard insight meta updated', {
- dashboard_id: dashboardId,
- insight_id: insightId,
- attribute,
- })
- },
- reportDashboardInsightDeleteAfterRemovalClicked: async ({ otherDashboardCount }) => {
- posthog.capture('dashboard insight delete after removal clicked', {
- other_dashboard_count: otherDashboardCount,
- })
- },
- reportDashboardEmptyAiPromptSubmitted: async ({ dashboardId, promptType }) => {
- posthog.capture('dashboard empty ai prompt submitted', {
- dashboard_id: dashboardId,
- prompt_type: promptType,
- source: 'web',
- })
- },
- reportDashboardEmptyAddChartClicked: async ({ dashboardId }) => {
- posthog.capture('dashboard empty add chart clicked', {
- dashboard_id: dashboardId,
- source: 'web',
- })
- },
- reportDashboardEmptyWebAnalyticsClicked: async ({ dashboardId }) => {
- posthog.capture('dashboard empty web analytics clicked', {
- dashboard_id: dashboardId,
- source: 'web',
- })
- },
reportTimezoneComponentViewed: async (payload) => {
posthog.capture('timezone component viewed', payload)
},
@@ -2329,9 +2014,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportCreatedDashboardFromModal: async () => {
posthog.capture('created new dashboard from modal')
},
- reportDashboardAddMenuOpened: async ({ source, dashboardId }) => {
- posthog.capture('dashboard add menu opened', { source, dashboard_id: dashboardId })
- },
reportSavedInsightToDashboard: async ({ insight, dashboardId }) => {
if (isBIVisualizationNode(insight?.query)) {
captureBIWorksheetAction('added_to_dashboard', insight.query.config, { insight_id: insight.id })
diff --git a/frontend/src/scenes/dashboard/DashboardAiPromptComposer.tsx b/frontend/src/scenes/dashboard/DashboardAiPromptComposer.tsx
index 6b6518bda821..f93ab53b64ea 100644
--- a/frontend/src/scenes/dashboard/DashboardAiPromptComposer.tsx
+++ b/frontend/src/scenes/dashboard/DashboardAiPromptComposer.tsx
@@ -5,9 +5,9 @@ import type { FormEvent } from 'react'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea/LemonTextArea'
import { Link } from 'lib/lemon-ui/Link'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { dashboardAiPromptComposerLogic } from './dashboardAiPromptComposerLogic'
+import { reportDashboardEmptyAiPromptSubmitted } from './dashboardEvents'
function reportDashboardEmptyAiPromptClicked(
promptLabel: string,
@@ -127,7 +127,6 @@ export function DashboardAiPromptComposer({
}: DashboardAiPromptComposerProps): JSX.Element {
const { prompt, promptSource } = useValues(dashboardAiPromptComposerLogic)
const { setPrompt } = useActions(dashboardAiPromptComposerLogic)
- const { reportDashboardEmptyAiPromptSubmitted } = useActions(eventUsageLogic)
const submitPrompt = (event: FormEvent<HTMLFormElement>): void => {
event.preventDefault()
diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
index 82deb57f72b6..b21e889df087 100644
--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
@@ -10,7 +10,7 @@ import { LemonBadge } from 'lib/lemon-ui/LemonBadge'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonMenu, LemonMenuItem, LemonMenuItems } from 'lib/lemon-ui/LemonMenu'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
-import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
import { MaxTool } from 'scenes/max/MaxTool'
import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
@@ -22,6 +22,7 @@ import { DashboardCustomizeMenu } from 'products/dashboards/frontend/components/
import { DashboardAddTileHandlers, DashboardAddTileKey, getDashboardAddTileOptions } from './dashboardAddTileOptions'
import { DashboardCustomizeButton } from './DashboardCustomizeButton'
+import { reportDashboardAddMenuOpened } from './dashboardEvents'
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
import { DashboardSubscribeButton } from './DashboardSubscribeButton'
@@ -61,7 +62,6 @@ export function DashboardAddTileButton(): JSX.Element | null {
openImageTileModal,
openButtonTileModal,
} = useActions(dashboardLogic)
- const { reportDashboardAddMenuOpened } = useActions(eventUsageLogic)
if (!dashboard || tiles.length === 0) {
return null
diff --git a/frontend/src/scenes/dashboard/DashboardItems.test.tsx b/frontend/src/scenes/dashboard/DashboardItems.test.tsx
index 1382f994dac8..f95ac1ed668e 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.test.tsx
+++ b/frontend/src/scenes/dashboard/DashboardItems.test.tsx
@@ -5,7 +5,6 @@ import { useActions, useAsyncActions, useValues } from 'kea'
import { router } from 'kea-router'
import type { PositionStrategy } from 'react-grid-layout/core'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import { dashboardsModel } from '~/models/dashboardsModel'
@@ -39,7 +38,6 @@ jest.mock('~/models/insightsModel', () => ({
}))
jest.mock('lib/utils/eventUsageLogic', () => ({
- eventUsageLogic: { __mock: 'eventUsageLogic' },
DashboardEventSource: {
CardEdgeHover: 'CardEdgeHover',
CardDragHandle: 'CardDragHandle',
@@ -303,12 +301,6 @@ describe('DashboardItems', () => {
}
}
- if (logic === eventUsageLogic) {
- return {
- reportDashboardTileRepositioned: jest.fn(),
- }
- }
-
if (logic === router) {
return {
push: jest.fn(),
diff --git a/frontend/src/scenes/dashboard/DashboardItems.tsx b/frontend/src/scenes/dashboard/DashboardItems.tsx
index 5f5ae9f0f805..87178912ee08 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.tsx
+++ b/frontend/src/scenes/dashboard/DashboardItems.tsx
@@ -15,8 +15,9 @@ import { ApiError } from 'lib/api'
import { EditModeEdge, useResizeHandleScrollbarPassThrough } from 'lib/components/Cards/InsightCard/EditModeEdgeOverlay'
import { TileDecorations } from 'lib/components/TileDecorations/TileDecorations'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
-import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
import { objectsEqual } from 'lib/utils/objects'
+import { reportDashboardTileRepositioned } from 'scenes/dashboard/dashboardEvents'
import { DashboardLoadAction, dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import {
BREAKPOINTS,
@@ -146,7 +147,6 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsP
moveTileToSection,
} = useActions(dashboardLogic)
const { updateWidgetTile } = useAsyncActions(dashboardLogic)
- const { reportDashboardTileRepositioned } = useActions(eventUsageLogic)
const { push } = useActions(router)
const { data: surveyLinkedInsights, loading: surveyLinkedInsightsLoading } = useSurveyLinkedInsights({
// Dashboard pages hide the survey suggestion in compact headers; notebook embeds also use this component and can show it.
diff --git a/frontend/src/scenes/dashboard/DashboardZoomControl.tsx b/frontend/src/scenes/dashboard/DashboardZoomControl.tsx
index 5edd66d5fb80..32793310373f 100644
--- a/frontend/src/scenes/dashboard/DashboardZoomControl.tsx
+++ b/frontend/src/scenes/dashboard/DashboardZoomControl.tsx
@@ -4,9 +4,9 @@ import posthog from 'posthog-js'
import { LemonButton } from '@posthog/lemon-ui'
import { Shortcut } from 'lib/components/Shortcuts/Shortcut'
-import { sanitizeDashboard } from 'lib/utils/eventUsageLogic'
import { Scene } from 'scenes/sceneTypes'
+import { sanitizeDashboard } from './dashboardEvents'
import { dashboardLogic } from './dashboardLogic'
interface DashboardZoomControlProps {
diff --git a/frontend/src/scenes/dashboard/EmptyDashboardComponent.tsx b/frontend/src/scenes/dashboard/EmptyDashboardComponent.tsx
index 97100cec8b65..560acf4e7c7e 100644
--- a/frontend/src/scenes/dashboard/EmptyDashboardComponent.tsx
+++ b/frontend/src/scenes/dashboard/EmptyDashboardComponent.tsx
@@ -9,7 +9,6 @@ import { AccessControlAction } from 'lib/components/AccessControlAction'
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonMenu } from 'lib/lemon-ui/LemonMenu'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { urls } from 'scenes/urls'
@@ -18,6 +17,7 @@ import { AccessControlLevel, AccessControlResourceType, DashboardType, SidePanel
import { addInsightToDashboardLogic } from './addInsightToDashboardModalLogic'
import { DashboardAiPromptComposer } from './DashboardAiPromptComposer'
+import { reportDashboardEmptyAddChartClicked, reportDashboardEmptyWebAnalyticsClicked } from './dashboardEvents'
import { DASHBOARD_CANNOT_EDIT_MESSAGE } from './DashboardHeader'
import { getAddTileMenuItems } from './DashboardHeaderActions'
import { dashboardLogic } from './dashboardLogic'
@@ -47,7 +47,6 @@ function DashboardEmptyActions({
onAddWidget: () => void
onOpenAiWithPrompt: (prompt: string) => void
}): JSX.Element {
- const { reportDashboardEmptyAddChartClicked, reportDashboardEmptyWebAnalyticsClicked } = useActions(eventUsageLogic)
const chipDisabledReason = !canEdit ? DASHBOARD_CANNOT_EDIT_MESSAGE : aiDisabledReason || undefined
const handleAddInsight = (): void => {
reportDashboardEmptyAddChartClicked(dashboard?.id)
diff --git a/frontend/src/scenes/dashboard/QuillDashboardAddTileButton.tsx b/frontend/src/scenes/dashboard/QuillDashboardAddTileButton.tsx
index 41741cb50086..283034ca718f 100644
--- a/frontend/src/scenes/dashboard/QuillDashboardAddTileButton.tsx
+++ b/frontend/src/scenes/dashboard/QuillDashboardAddTileButton.tsx
@@ -13,13 +13,13 @@ import {
} from '@posthog/quill'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { MaxTool } from 'scenes/max/MaxTool'
import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { DashboardAddTileKey, getDashboardAddTileOptions } from './dashboardAddTileOptions'
+import { reportDashboardAddMenuOpened } from './dashboardEvents'
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
// pinned: autocapture data-attrs for the header's Add menu items
@@ -41,7 +41,6 @@ export function QuillDashboardAddTileButton(): JSX.Element | null {
openImageTileModal,
openButtonTileModal,
} = useActions(dashboardLogic)
- const { reportDashboardAddMenuOpened } = useActions(eventUsageLogic)
if (!dashboard || tiles.length === 0) {
return null
diff --git a/frontend/src/scenes/dashboard/dashboardEvents.test.ts b/frontend/src/scenes/dashboard/dashboardEvents.test.ts
new file mode 100644
index 000000000000..cf67e2dcb8be
--- /dev/null
+++ b/frontend/src/scenes/dashboard/dashboardEvents.test.ts
@@ -0,0 +1,108 @@
+import { NodeKind } from '~/queries/schema/schema-general'
+import type { DashboardTile, DashboardType } from '~/types'
+
+import { dashboardViewedProperties, sanitizeDashboard } from './dashboardEvents'
+
+describe('dashboardEvents', () => {
+ it('keeps metric variable definitions out of a sanitized dashboard', () => {
+ const metricVariables = [{ name: 'env', source: 'sql', query: 'SELECT private_value' }]
+ const tile = { id: 1, insight: { id: 2, filter_override_context: { dashboard: { metricVariables } } } }
+ const dashboard = { id: 7, tiles: [tile], filters: { metricVariables }, persisted_filters: { metricVariables } }
+
+ const sanitized = sanitizeDashboard(dashboard as unknown as DashboardType)
+
+ expect(JSON.stringify(sanitized)).not.toContain('private_value')
+ })
+
+ describe('dashboardViewedProperties', () => {
+ const dashboard = (tiles: Partial<DashboardTile>[]): DashboardType =>
+ ({
+ id: 7,
+ created_at: '2026-01-01T00:00:00Z',
+ is_shared: false,
+ pinned: true,
+ creation_mode: 'default',
+ created_by: { uuid: 'creator' },
+ tiles,
+ }) as unknown as DashboardType
+
+ const insightTile = (query: unknown, is_sample = false): Partial<DashboardTile> =>
+ ({ insight: { query, is_sample } }) as unknown as Partial<DashboardTile>
+
+ const cases: [string, Partial<DashboardTile>[], Record<string, unknown>][] = [
+ ['no tiles', [], { item_count: 0, sample_items_count: 0 }],
+ [
+ 'an insight tile with a query',
+ [insightTile({ kind: NodeKind.InsightVizNode, source: { kind: NodeKind.TrendsQuery, series: [] } })],
+ { item_count: 1, text_count: 1, uses_data_warehouse_source: false, data_warehouse_tiles_count: 0 },
+ ],
+ ['an insight tile without a query', [insightTile(null)], { item_count: 1, empty_count: 1 }],
+ [
+ 'a sample insight tile that reads the warehouse',
+ [insightTile({ kind: NodeKind.TrendsQuery, series: [{ kind: NodeKind.DataWarehouseNode }] }, true)],
+ {
+ item_count: 1,
+ text_count: 1,
+ sample_items_count: 1,
+ uses_data_warehouse_source: true,
+ data_warehouse_tiles_count: 1,
+ },
+ ],
+ [
+ 'text and widget tiles',
+ [{ text: { body: 'hi' } }, { text: { body: 'there' } }, { widget: {} }] as Partial<DashboardTile>[],
+ { item_count: 3, text_tiles_count: 2, widget_tiles_count: 1 },
+ ],
+ [
+ 'groups once however many tiles share a key',
+ [
+ { group_key: 'a' },
+ { group_key: 'a' },
+ { group_key: 'b' },
+ { group_key: null },
+ ] as Partial<DashboardTile>[],
+ { item_count: 4, text_tiles_count: 4, group_count: 2 },
+ ],
+ ]
+
+ it.each(cases)('counts %s', (_, tiles, expected) => {
+ expect(dashboardViewedProperties(dashboard(tiles), null, 'viewer')).toEqual({
+ created_at: '2026-01-01T00:00:00Z',
+ is_shared: false,
+ pinned: true,
+ creation_mode: 'default',
+ viewer_is_creator: false,
+ created_by_system: false,
+ dashboard_id: 7,
+ group_display: 'sections',
+ group_count: 0,
+ lastRefreshed: undefined,
+ refreshAge: undefined,
+ sample_items_count: 0,
+ uses_data_warehouse_source: false,
+ data_warehouse_tiles_count: 0,
+ ...expected,
+ })
+ })
+
+ it('reports the dashboard group display', () => {
+ const withTabs = { ...dashboard([]), customization: { group_display: 'tabs' } } as unknown as DashboardType
+ expect(dashboardViewedProperties(withTabs, null, 'viewer')).toMatchObject({ group_display: 'tabs' })
+ })
+
+ const viewerCases: [string, { uuid: string } | null, string | undefined, boolean | undefined][] = [
+ ['the creator views it', { uuid: 'creator' }, 'creator', true],
+ ['another user views it', { uuid: 'creator' }, 'viewer', false],
+ ['the viewer is unknown', { uuid: 'creator' }, undefined, undefined],
+ ['the system created it', null, 'viewer', undefined],
+ ]
+
+ it.each(viewerCases)('reports viewer_is_creator when %s', (_, created_by, viewerUuid, expected) => {
+ const withCreator = { ...dashboard([]), created_by } as unknown as DashboardType
+ expect(dashboardViewedProperties(withCreator, null, viewerUuid)).toMatchObject({
+ viewer_is_creator: expected,
+ created_by_system: created_by === null,
+ })
+ })
+ })
+})
diff --git a/frontend/src/scenes/dashboard/dashboardEvents.ts b/frontend/src/scenes/dashboard/dashboardEvents.ts
new file mode 100644
index 000000000000..2c2bf51e438b
--- /dev/null
+++ b/frontend/src/scenes/dashboard/dashboardEvents.ts
@@ -0,0 +1,230 @@
+import posthog from 'posthog-js'
+
+import type { Dayjs } from 'lib/dayjs'
+import { now } from 'lib/dayjs'
+import { DashboardEventSource, filtersForAnalytics, sanitizeInsight } from 'lib/utils/eventUsageLogic'
+
+import { isNodeWithSource, queryUsesDataWarehouse } from '~/queries/utils'
+import { DashboardMode, DashboardTile, DashboardTileSpacing, DashboardType, TileGroupDisplay } from '~/types'
+
+export type DashboardFilterChangeType =
+ | 'date'
+ | 'properties'
+ | 'breakdown'
+ | 'variable'
+ | 'interval'
+ | 'test_accounts'
+ | 'compare'
+ | 'metric_variables'
+
+function sanitizeTile(tile: DashboardTile | null): object | undefined {
+ if (!tile) {
+ return undefined
+ }
+
+ return {
+ ...tile,
+ insight: tile.insight ? sanitizeInsight(tile.insight) : undefined,
+ }
+}
+
+export function sanitizeDashboard(dashboard: DashboardType | null): object | null {
+ if (!dashboard) {
+ return null
+ }
+
+ // Remove breakdown color entries, as they carry raw breakdown values (user data) — report only their count
+ const { breakdown_colors, ...sanitizedDashboard } = dashboard
+
+ return {
+ ...sanitizedDashboard,
+ breakdown_colors_count: breakdown_colors?.length ?? 0,
+ filters: filtersForAnalytics(dashboard.filters ?? {}),
+ persisted_filters: dashboard.persisted_filters ? filtersForAnalytics(dashboard.persisted_filters) : null,
+ tiles: dashboard.tiles?.map((tile) => sanitizeTile(tile)) || [],
+ }
+}
+
+function increment(counts: Record<string, any>, key: string): void {
+ counts[key] = (counts[key] || 0) + 1
+}
+
+function insightTileCountKey(tile: DashboardTile): string {
+ const query = isNodeWithSource(tile.insight?.query) ? tile.insight.query.source : tile.insight?.query
+ return `${query?.kind || !!tile.text ? 'text' : 'empty'}_count`
+}
+
+function countDashboardTiles(tiles: DashboardTile[], properties: Record<string, any>): void {
+ for (const tile of tiles) {
+ if (tile.insight) {
+ increment(properties, insightTileCountKey(tile))
+ properties.sample_items_count += tile.insight.is_sample ? 1 : 0
+ if (queryUsesDataWarehouse(tile.insight.query)) {
+ properties.uses_data_warehouse_source = true
+ properties.data_warehouse_tiles_count += 1
+ }
+ } else if (tile.widget) {
+ increment(properties, 'widget_tiles_count')
+ } else {
+ increment(properties, 'text_tiles_count')
+ }
+ }
+}
+
+export function tileGroupProperties(
+ groupDisplay: TileGroupDisplay | undefined,
+ tiles: DashboardTile[]
+): { group_display: TileGroupDisplay; group_count: number } {
+ return {
+ group_display: groupDisplay ?? 'sections',
+ group_count: new Set(tiles.map((tile) => tile.group_key).filter(Boolean)).size,
+ }
+}
+
+export function dashboardViewedProperties(
+ dashboard: DashboardType,
+ lastRefreshed: Dayjs | null,
+ viewerUuid: string | undefined
+): Record<string, any> {
+ const { created_at, is_shared, pinned, creation_mode, id } = dashboard
+ const properties: Record<string, any> = {
+ created_at,
+ is_shared,
+ pinned,
+ creation_mode,
+ viewer_is_creator:
+ dashboard.created_by?.uuid && viewerUuid ? dashboard.created_by.uuid === viewerUuid : undefined,
+ sample_items_count: 0,
+ item_count: dashboard.tiles?.length || 0,
+ created_by_system: !dashboard.created_by,
+ dashboard_id: id,
+ ...tileGroupProperties(dashboard.customization?.group_display, dashboard.tiles || []),
+ lastRefreshed: lastRefreshed?.toISOString(),
+ refreshAge: lastRefreshed ? now().diff(lastRefreshed, 'seconds') : undefined,
+ uses_data_warehouse_source: false,
+ data_warehouse_tiles_count: 0,
+ }
+ countDashboardTiles(dashboard.tiles || [], properties)
+ return properties
+}
+
+export function reportDashboardModeToggled(
+ dashboard: DashboardType | null,
+ mode: DashboardMode | null,
+ source: DashboardEventSource | null,
+ layoutZoom: number | null,
+ layoutEditMode?: boolean
+): void {
+ posthog.capture('dashboard mode toggled', {
+ dashboard_id: dashboard?.id,
+ dashboard: sanitizeDashboard(dashboard),
+ mode,
+ source,
+ layout_zoom: layoutZoom ?? undefined,
+ layout_edit_mode: layoutEditMode ?? undefined,
+ })
+}
+
+export function reportDashboardLayoutEditModeEntered(
+ dashboard: DashboardType | null,
+ source: DashboardEventSource,
+ layoutZoom: number | null
+): void {
+ posthog.capture('dashboard layout edit mode entered', {
+ dashboard_id: dashboard?.id,
+ dashboard: sanitizeDashboard(dashboard),
+ source,
+ layout_zoom: layoutZoom ?? undefined,
+ })
+}
+
+export function reportDashboardFiltersChanged(
+ dashboard: DashboardType | null,
+ changeType: DashboardFilterChangeType,
+ properties: Record<string, string | number | boolean | null | undefined>
+): void {
+ posthog.capture('dashboard filters changed', {
+ dashboard_id: dashboard?.id,
+ change_type: changeType,
+ ...properties,
+ })
+}
+
+export function reportDashboardTileDensityConfigured(tileDensity: DashboardTileSpacing): void {
+ posthog.capture('dashboard tile density configured', { tile_density: tileDensity })
+}
+
+export function reportDashboardEditModeDiscardPrompt(
+ dashboard: DashboardType | null,
+ action: 'shown' | 'discarded' | 'kept_editing'
+): void {
+ posthog.capture('dashboard edit mode discard prompt', {
+ dashboard_id: dashboard?.id,
+ dashboard: sanitizeDashboard(dashboard),
+ action,
+ })
+}
+
+export function reportDashboardMoveInitiated(method: 'single' | 'bulk', count: number): void {
+ posthog.capture('dashboard move initiated', { method, count })
+}
+
+export function reportDashboardInsightDeleteAfterRemovalClicked(otherDashboardCount: number): void {
+ posthog.capture('dashboard insight delete after removal clicked', {
+ other_dashboard_count: otherDashboardCount,
+ })
+}
+
+export function reportDashboardTileRepositioned(
+ dashboardId: number,
+ action: 'moved' | 'resized',
+ layoutZoom: number
+): void {
+ posthog.capture('dashboard tile repositioned', {
+ dashboard_id: dashboardId,
+ action,
+ layout_zoom: layoutZoom,
+ })
+}
+
+export function reportDashboardInsightMetaUpdated(
+ dashboardId: number | undefined,
+ insightId: number,
+ attribute: 'name' | 'description'
+): void {
+ posthog.capture('dashboard insight meta updated', {
+ dashboard_id: dashboardId,
+ insight_id: insightId,
+ attribute,
+ })
+}
+
+/** Empty-state AI prompt chips (ai-first empty dashboard only). */
+export function reportDashboardEmptyAiPromptSubmitted(
+ dashboardId: number | undefined,
+ promptType: 'custom_prompt' | 'starter_question'
+): void {
+ posthog.capture('dashboard empty ai prompt submitted', {
+ dashboard_id: dashboardId,
+ prompt_type: promptType,
+ source: 'web',
+ })
+}
+
+export function reportDashboardEmptyAddChartClicked(dashboardId: number | undefined): void {
+ posthog.capture('dashboard empty add chart clicked', {
+ dashboard_id: dashboardId,
+ source: 'web',
+ })
+}
+
+export function reportDashboardEmptyWebAnalyticsClicked(dashboardId: number | undefined): void {
+ posthog.capture('dashboard empty web analytics clicked', {
+ dashboard_id: dashboardId,
+ source: 'web',
+ })
+}
+
+export function reportDashboardAddMenuOpened(source: 'header', dashboardId: number): void {
+ posthog.capture('dashboard add menu opened', { source, dashboard_id: dashboardId })
+}
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
index 90b8e7eb59c3..9742f3b7c474 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts
+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
@@ -1604,10 +1604,7 @@ describe('dashboardLogic', () => {
it('previews tile spacing immediately and persists only the final choice', async () => {
await expectLogic(logic).toFinishAllListeners()
;(api.update as jest.Mock).mockClear()
- const reportTileDensityConfigured = jest.spyOn(
- eventUsageLogic.actions,
- 'reportDashboardTileDensityConfigured'
- )
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
jest.useFakeTimers()
try {
@@ -1627,7 +1624,7 @@ describe('dashboardLogic', () => {
layout_compaction: DashboardGridCompaction.Vertical,
grid_spacing: 'relaxed',
})
- expect(reportTileDensityConfigured).toHaveBeenCalledWith('relaxed')
+ expect(capture).toHaveBeenCalledWith('dashboard tile density configured', { tile_density: 'relaxed' })
} finally {
jest.useRealTimers()
}
@@ -1635,10 +1632,7 @@ describe('dashboardLogic', () => {
it('reports the tile density when reset to standard', async () => {
await expectLogic(logic).toFinishAllListeners()
- const reportTileDensityConfigured = jest.spyOn(
- eventUsageLogic.actions,
- 'reportDashboardTileDensityConfigured'
- )
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
jest.useFakeTimers()
try {
@@ -1647,7 +1641,7 @@ describe('dashboardLogic', () => {
await jest.advanceTimersByTimeAsync(750)
await expectLogic(logic).toFinishAllListeners()
- expect(reportTileDensityConfigured).toHaveBeenCalledWith('standard')
+ expect(capture).toHaveBeenCalledWith('dashboard tile density configured', { tile_density: 'standard' })
} finally {
jest.useRealTimers()
}
@@ -2992,12 +2986,8 @@ describe('dashboardLogic', () => {
})
it('reports filter changes separately from layout edit mode entry', async () => {
- const reportFiltersChanged = jest.spyOn(eventUsageLogic.actions, 'reportDashboardFiltersChanged')
- const reportLayoutEditEntered = jest.spyOn(
- eventUsageLogic.actions,
- 'reportDashboardLayoutEditModeEntered'
- )
- const reportModeToggled = jest.spyOn(eventUsageLogic.actions, 'reportDashboardModeToggled')
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
+ const capturedEvents = (): string[] => capture.mock.calls.map(([event]) => event)
await expectLogic(logic).toFinishAllListeners()
@@ -3008,22 +2998,19 @@ describe('dashboardLogic', () => {
)
}).toFinishAllListeners()
- expect(reportLayoutEditEntered).not.toHaveBeenCalled()
- expect(reportModeToggled).not.toHaveBeenCalled()
+ expect(capturedEvents()).not.toContain('dashboard layout edit mode entered')
+ expect(capturedEvents()).not.toContain('dashboard mode toggled')
await expectLogic(logic, () => {
logic.actions.setDates('-7d', null)
}).toFinishAllListeners()
- expect(reportFiltersChanged).toHaveBeenCalledWith(
- expect.objectContaining({ id: 5 }),
- 'date',
- expect.objectContaining({ date_from: '-7d', date_to: null })
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard filters changed',
+ expect.objectContaining({ dashboard_id: 5, change_type: 'date', date_from: '-7d', date_to: null })
)
- reportFiltersChanged.mockClear()
- reportLayoutEditEntered.mockClear()
- reportModeToggled.mockClear()
+ capture.mockClear()
await expectLogic(logic, () => {
logic.actions.setDashboardEditing(
@@ -3032,17 +3019,18 @@ describe('dashboardLogic', () => {
)
}).toFinishAllListeners()
- expect(reportLayoutEditEntered).toHaveBeenCalledWith(
- expect.objectContaining({ id: 5 }),
- DashboardEventSource.SceneCommonButtons,
- 1
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard layout edit mode entered',
+ expect.objectContaining({
+ dashboard_id: 5,
+ source: DashboardEventSource.SceneCommonButtons,
+ layout_zoom: 1,
+ })
)
- expect(reportModeToggled).not.toHaveBeenCalled()
- expect(reportFiltersChanged).not.toHaveBeenCalled()
+ expect(capturedEvents()).not.toContain('dashboard mode toggled')
+ expect(capturedEvents()).not.toContain('dashboard filters changed')
- reportFiltersChanged.mockRestore()
- reportLayoutEditEntered.mockRestore()
- reportModeToggled.mockRestore()
+ capture.mockRestore()
})
it('filter edits preserve layout editing', async () => {
@@ -5936,10 +5924,7 @@ describe('dashboardLogic', () => {
it('offers to delete a removed insight and explains its other dashboard usage', async () => {
const { fireEvent, render } = await import('@testing-library/react')
- const reportDeleteClicked = jest.spyOn(
- eventUsageLogic.actions,
- 'reportDashboardInsightDeleteAfterRemovalClicked'
- )
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
const insightTile = logic.values.insightTiles[0]
const insight = insightTile.insight!
@@ -5959,7 +5944,9 @@ describe('dashboardLogic', () => {
const toastContent = lemonToastInfoSpy.mock.calls.at(-1)?.[0]
const { getByText } = render(toastContent)
fireEvent.click(getByText('Delete insight everywhere'))
- expect(reportDeleteClicked).toHaveBeenCalledWith(1)
+ expect(capture).toHaveBeenCalledWith('dashboard insight delete after removal clicked', {
+ other_dashboard_count: 1,
+ })
expect(lemonToastDismissSpy).not.toHaveBeenCalled()
const dialogProps = lemonDialogOpenSpy.mock.calls.at(-1)?.[0]
@@ -5977,7 +5964,7 @@ describe('dashboardLogic', () => {
getDialogText('This deletes the insight and removes it from every dashboard. You can undo this action.')
).not.toBeNull()
- reportDeleteClicked.mockRestore()
+ capture.mockRestore()
})
})
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index 2c652990b09e..1818e541e9af 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -46,20 +46,23 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'
import { deleteInsightWithUndo } from 'lib/utils/deleteWithUndo'
import { clearDOMTextSelection, getJSHeapMemory, uuid } from 'lib/utils/dom'
+import { DashboardEventSource, eventUsageLogic, filtersForAnalytics, sanitizeQuery } from 'lib/utils/eventUsageLogic'
+import { objectsEqual } from 'lib/utils/objects'
+import { shouldCancelQuery } from 'lib/utils/requests'
+import { toParams } from 'lib/utils/url'
+import { addInsightToDashboardLogic } from 'scenes/dashboard/addInsightToDashboardModalLogic'
import {
- DashboardEventSource,
DashboardFilterChangeType,
dashboardViewedProperties,
- eventUsageLogic,
+ reportDashboardEditModeDiscardPrompt,
+ reportDashboardFiltersChanged,
+ reportDashboardInsightDeleteAfterRemovalClicked,
+ reportDashboardLayoutEditModeEntered,
+ reportDashboardModeToggled,
+ reportDashboardTileDensityConfigured,
sanitizeDashboard,
- filtersForAnalytics,
- sanitizeQuery,
tileGroupProperties,
-} from 'lib/utils/eventUsageLogic'
-import { objectsEqual } from 'lib/utils/objects'
-import { shouldCancelQuery } from 'lib/utils/requests'
-import { toParams } from 'lib/utils/url'
-import { addInsightToDashboardLogic } from 'scenes/dashboard/addInsightToDashboardModalLogic'
+} from 'scenes/dashboard/dashboardEvents'
import { BREAKPOINTS, dashboardToSaveableTemplate, getDashboardTileDisplayName } from 'scenes/dashboard/dashboardUtils'
import { liveDashboardIds } from 'scenes/dashboard/liveDashboardIds'
import { calculateDuplicateLayout, calculateLayouts } from 'scenes/dashboard/tileLayouts'
@@ -4985,9 +4988,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
data-attr="delete-removed-insight"
className="!m-0"
onClick={() => {
- eventUsageLogic.actions.reportDashboardInsightDeleteAfterRemovalClicked(
- otherDashboardIds.size
- )
+ reportDashboardInsightDeleteAfterRemovalClicked(otherDashboardIds.size)
deleteInsight()
}}
>
@@ -5126,7 +5127,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
dashboardsModel.actions.updateDashboardSuccess(dashboard, {
layoutsPersisted: true,
})
- eventUsageLogic.actions.reportDashboardTileDensityConfigured(tileSpacing)
+ reportDashboardTileDensityConfigured(tileSpacing)
} catch {
if (!cache.pendingDashboardTileSpacing) {
actions.setDashboardTileSpacing(persistedTileSpacing)
@@ -5923,7 +5924,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
discard()
return
}
- eventUsageLogic.actions.reportDashboardEditModeDiscardPrompt(values.dashboard, 'shown')
+ reportDashboardEditModeDiscardPrompt(values.dashboard, 'shown')
LemonDialog.open({
title: 'Discard unsaved changes?',
description:
@@ -5932,7 +5933,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
children: 'Discard changes',
status: 'danger',
onClick: () => {
- eventUsageLogic.actions.reportDashboardEditModeDiscardPrompt(values.dashboard, 'discarded')
+ reportDashboardEditModeDiscardPrompt(values.dashboard, 'discarded')
discard()
},
'data-attr': 'dashboard-edit-mode-discard-confirm',
@@ -5940,7 +5941,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
secondaryButton: {
children: 'Keep editing',
onClick: () => {
- eventUsageLogic.actions.reportDashboardEditModeDiscardPrompt(values.dashboard, 'kept_editing')
+ reportDashboardEditModeDiscardPrompt(values.dashboard, 'kept_editing')
},
},
})
@@ -6017,7 +6018,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
}
if (editing?.layout) {
- eventUsageLogic.actions.reportDashboardLayoutEditModeEntered(
+ reportDashboardLayoutEditModeEntered(
values.dashboard,
source,
values.layoutEditMode ? values.layoutZoom : null
@@ -6026,7 +6027,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
},
setDashboardMode: async ({ mode, source }) => {
if (mode || source) {
- eventUsageLogic.actions.reportDashboardModeToggled(
+ reportDashboardModeToggled(
values.dashboard,
mode,
source,
@@ -6183,7 +6184,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
remainingInsightIds: new Set(values.insightTiles.map((tile) => tile.insight!.short_id)),
}
cache.pendingFilterChange = filterChange
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, changeType, {
+ reportDashboardFiltersChanged(values.dashboard, changeType, {
...properties,
filter_change_id: filterChange.id,
supersedes_filter_change_id: previousChange?.id,
diff --git a/frontend/src/scenes/dashboard/dashboards/dashboardsLogic.ts b/frontend/src/scenes/dashboard/dashboards/dashboardsLogic.ts
index bf9925ed692a..72d0b53253e8 100644
--- a/frontend/src/scenes/dashboard/dashboards/dashboardsLogic.ts
+++ b/frontend/src/scenes/dashboard/dashboards/dashboardsLogic.ts
@@ -8,8 +8,8 @@ import { Sorting } from 'lib/lemon-ui/LemonTable/sorting'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { buildUserScopedPersistenceConfig } from 'lib/logic/persistence'
import { trackedActionToUrl } from 'lib/logic/scenes/trackedActionToUrl'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { objectClean, objectsEqual } from 'lib/utils/objects'
+import { reportDashboardMoveInitiated } from 'scenes/dashboard/dashboardEvents'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
@@ -160,13 +160,6 @@ export interface dashboardsLogicActions {
onStillSelected: (ids: number[]) => void
}
} // dashboardsModel
- reportDashboardMoveInitiated: (
- method: 'bulk' | 'single',
- count: number
- ) => {
- count: number
- method: 'bulk' | 'single'
- } // eventUsageLogic
openMoveToModal: (items: FileSystemEntry[]) => {
items: FileSystemEntry[]
} // moveToLogic
@@ -316,8 +309,6 @@ export const dashboardsLogic = kea<dashboardsLogicType>([
['bulkDeleteDashboards', 'bulkDeleteDashboardsSuccess', 'reloadDashboardsSuccess'],
moveToLogic,
['openMoveToModal'],
- eventUsageLogic,
- ['reportDashboardMoveInitiated'],
projectTreeDataLogic,
['movedItem'],
],
@@ -775,7 +766,7 @@ export const dashboardsLogic = kea<dashboardsLogicType>([
if (moving.length === 0) {
return
}
- actions.reportDashboardMoveInitiated(method, moving.length)
+ reportDashboardMoveInitiated(method, moving.length)
actions.openMoveToModal(moving)
cache.awaitingMove = { ids: new Set(ids), onStillSelected }
},