: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(insights): capture an event when date exclusions change (#83617)
Sam Pennington89689e171f5a
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex ed3a67222cd2..717ce3c0a6d3 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -1507,6 +1507,15 @@ export interface eventUsageLogicActions {reportInsightCompareChanged: (queryKind: string | undefined) => {queryKind: string | undefined}+ reportInsightDateExclusionsChanged: (+ queryKind: string | undefined,+ excludeIncompletePeriods: boolean,+ excludedDaysOfWeekCount: number+ ) => {+ excludedDaysOfWeekCount: number+ excludeIncompletePeriods: boolean+ queryKind: string | undefined+ }reportInsightDatePickerOpened: (queryKind: string | undefined) => {queryKind: string | undefined}@@ -2253,6 +2262,11 @@ export const eventUsageLogic = kea<eventUsageLogicType>([reportPropertyGroupFilterRemoved: true,reportPropertyGroupFilterDuplicated: true,reportInsightDateRangeChanged: (queryKind: string | undefined) => ({ queryKind }),+ reportInsightDateExclusionsChanged: (+ queryKind: string | undefined,+ excludeIncompletePeriods: boolean,+ excludedDaysOfWeekCount: number+ ) => ({ queryKind, excludeIncompletePeriods, excludedDaysOfWeekCount }),reportInsightDatePickerOpened: (queryKind: string | undefined) => ({ queryKind }),reportInsightDragToZoomed: (queryKind: string | undefined) => ({ queryKind }),reportInsightBreakdownChanged: (queryKind: string | undefined) => ({ queryKind }),@@ -3946,6 +3960,13 @@ export const eventUsageLogic = kea<eventUsageLogicType>([reportInsightDateRangeChanged: ({ queryKind }) => {posthog.capture('insight date range changed', { query_kind: queryKind })},+ reportInsightDateExclusionsChanged: ({ queryKind, excludeIncompletePeriods, excludedDaysOfWeekCount }) => {+ posthog.capture('insight date exclusions changed', {+ query_kind: queryKind,+ exclude_incomplete_periods: excludeIncompletePeriods,+ excluded_days_of_week_count: excludedDaysOfWeekCount,+ })+ },reportInsightDatePickerOpened: ({ queryKind }) => {posthog.capture('insight date picker opened', { query_kind: queryKind })},diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsxindex d609b83a9a5b..e5e97f5ca76b 100644--- a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx@@ -28,7 +28,7 @@ export function InsightDateFilter({ disabled }: InsightDateFilterProps): JSX.Eleconst { dateRange, interval, querySource, trendsFilter, isTrends } = useValues(insightVizDataLogic(insightProps))const { updateDateRange, updateQuerySource } = useActions(insightVizDataLogic(insightProps))const { insightData } = useValues(insightVizDataLogic(insightProps))- const { reportInsightDatePickerOpened } = useActions(eventUsageLogic)+ const { reportInsightDatePickerOpened, reportInsightDateExclusionsChanged } = useActions(eventUsageLogic)// The picker speaks excluded days; the query schema stores included daysconst excludedDaysOfWeek = getExcludedDaysOfWeek(dateRange)@@ -54,12 +54,20 @@ export function InsightDateFilter({ disabled }: InsightDateFilterProps): JSX.Ele}const handleExclusionsChange = (next: DateFilterExclusions): void => {const nextExcludedDaysOfWeek = parseIsoDaysOfWeek(next.days)- if (showDaysOfWeekExclusions && !daysOfWeekSetsEqual(nextExcludedDaysOfWeek, excludedDaysOfWeek)) {- updateQuerySource(computeDaysOfWeekUpdate(nextExcludedDaysOfWeek, dateRange))+ const daysChanged = showDaysOfWeekExclusions && !daysOfWeekSetsEqual(nextExcludedDaysOfWeek, excludedDaysOfWeek)+ const incompleteChanged = next.incomplete !== exclusions.incomplete+ const daysUpdate = daysChanged ? computeDaysOfWeekUpdate(nextExcludedDaysOfWeek, dateRange) : null+ if (daysUpdate) {+ updateQuerySource(daysUpdate)}- if (next.incomplete !== exclusions.incomplete) {+ if (incompleteChanged) {updateDateRange({ excludeIncompletePeriods: next.incomplete ? true : null }, true)}+ if (daysChanged || incompleteChanged) {+ // Report what got persisted, not what was picked: a full-week selection normalizes back to "exclude nothing"+ const persistedExcludedDays = daysUpdate ? getExcludedDaysOfWeek(daysUpdate.dateRange) : excludedDaysOfWeek+ reportInsightDateExclusionsChanged(querySource?.kind, next.incomplete, persistedExcludedDays.length)+ }}return (