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(insights): capture insight date picker opened event (#70980)

Sam Pennington03c8383ad849
diff --git a/frontend/src/lib/components/DateFilter/DateFilter.tsx b/frontend/src/lib/components/DateFilter/DateFilter.tsx
index a10efded3ab8..3e366da2224b 100644
--- a/frontend/src/lib/components/DateFilter/DateFilter.tsx
+++ b/frontend/src/lib/components/DateFilter/DateFilter.tsx
@@ -1,7 +1,7 @@
import { Placement } from '@floating-ui/react'
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
-import { forwardRef, useRef, useState } from 'react'
+import { forwardRef, useEffect, useRef, useState } from 'react'
import { IconCalendar, IconInfo } from '@posthog/icons'
import { LemonButton, LemonButtonProps, LemonDivider, LemonSwitch, Popover } from '@posthog/lemon-ui'
@@ -60,6 +60,8 @@ export interface DateFilterProps {
* `showCustomRelativeRange` are ignored when this is set.
*/
allowSingleAndRange?: boolean
+ /** Called when the dropdown opens (true) or closes (false). Used for interaction analytics. */
+ onOpenChange?: (open: boolean) => void
}
interface RawDateFilterProps extends DateFilterProps {
@@ -111,6 +113,7 @@ export const DateFilter = forwardRef<HTMLButtonElement, RawDateFilterProps>(func
showJumpToTimestamp = false,
showCustomRelativeRange = false,
allowSingleAndRange = false,
+ onOpenChange,
},
ref
) {
@@ -160,6 +163,20 @@ export const DateFilter = forwardRef<HTMLButtonElement, RawDateFilterProps>(func
fixedRangeGranularity,
} = useValues(dateFilterLogic(logicProps))
+ // Hold the callback in a ref so the visibility effect below depends only on `isVisible` —
+ // callers pass an inline function, which would otherwise re-run the effect every render.
+ const onOpenChangeRef = useRef(onOpenChange)
+ useEffect(() => {
+ onOpenChangeRef.current = onOpenChange
+ })
+ const wasVisibleRef = useRef(isVisible)
+ useEffect(() => {
+ if (isVisible !== wasVisibleRef.current) {
+ wasVisibleRef.current = isVisible
+ onOpenChangeRef.current?.(isVisible)
+ }
+ }, [isVisible])
+
const { weekStartDay } = useValues(teamLogic)
const optionsRef = useRef<HTMLDivElement | null>(null)
const rollingDateRangeRef = useRef<HTMLDivElement | null>(null)
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 7477961cae16..bb1ace49bd55 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -427,6 +427,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportPropertyGroupFilterRemoved: true,
reportPropertyGroupFilterDuplicated: true,
reportInsightDateRangeChanged: (queryKind: string | undefined) => ({ queryKind }),
+ reportInsightDatePickerOpened: (queryKind: string | undefined) => ({ queryKind }),
reportInsightDragToZoomed: (queryKind: string | undefined) => ({ queryKind }),
reportInsightBreakdownChanged: (queryKind: string | undefined) => ({ queryKind }),
reportInsightCompareChanged: (queryKind: string | undefined) => ({ queryKind }),
@@ -1941,6 +1942,9 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportInsightDateRangeChanged: ({ queryKind }) => {
posthog.capture('insight date range changed', { query_kind: queryKind })
},
+ reportInsightDatePickerOpened: ({ queryKind }) => {
+ posthog.capture('insight date picker opened', { query_kind: queryKind })
+ },
reportInsightDragToZoomed: ({ queryKind }) => {
posthog.capture('insight drag to zoomed', { query_kind: queryKind })
},
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
index beb64e1e00c7..fbc5e5eb0b3e 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightDateFilter.tsx
@@ -5,6 +5,7 @@ import { IconCalendar } from '@posthog/icons'
import { DateFilter } from 'lib/components/DateFilter/DateFilter'
import { dateMapping } from 'lib/utils/dateFilters'
import { alignResolvedDateRangeToInterval } from 'lib/utils/datetime'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
@@ -14,9 +15,10 @@ type InsightDateFilterProps = {
export function InsightDateFilter({ disabled }: InsightDateFilterProps): JSX.Element {
const { insightProps, editingDisabledReason } = useValues(insightLogic)
- const { dateRange, interval } = useValues(insightVizDataLogic(insightProps))
+ const { dateRange, interval, querySource } = useValues(insightVizDataLogic(insightProps))
const { updateDateRange } = useActions(insightVizDataLogic(insightProps))
const { insightData } = useValues(insightVizDataLogic(insightProps))
+ const { reportInsightDatePickerOpened } = useActions(eventUsageLogic)
return (
<DateFilter
@@ -28,6 +30,11 @@ export function InsightDateFilter({ disabled }: InsightDateFilterProps): JSX.Ele
allowFixedRangeWithTime
disabled={disabled}
disabledReason={editingDisabledReason}
+ onOpenChange={(open) => {
+ if (open) {
+ reportInsightDatePickerOpened(querySource?.kind)
+ }
+ }}
onChange={(date_from, date_to, explicit_date) => {
// Prevent debouncing when toggling the exact time range toggle as it glitches the animation
const ignoreDebounce = dateRange?.explicitDate !== explicit_date
diff --git a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.tsx b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.tsx
index 16de5f1e51e2..60c5afb9dd5a 100644
--- a/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.tsx
+++ b/frontend/src/scenes/insights/filters/InsightDateFilter/InsightQuillDateFilter.tsx
@@ -23,6 +23,7 @@ import { selectionKeyOf, type DateRangeSelection } from 'lib/components/DateFilt
import { dateRangeForSelection, selectionForDateRange } from 'lib/components/DateFilter/dateRangeSelection'
import { QuillDateFilter } from 'lib/components/DateFilter/QuillDateFilter'
import { dateFilterToText, dateMapping } from 'lib/utils/dateFilters'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { teamLogic } from 'scenes/teamLogic'
@@ -47,8 +48,9 @@ type InsightQuillDateFilterProps = {
export function InsightQuillDateFilter({ disabled }: InsightQuillDateFilterProps): JSX.Element {
const { insightProps, editingDisabledReason } = useValues(insightLogic)
- const { dateRange, trendsFilter, isTrends, isRetention } = useValues(insightVizDataLogic(insightProps))
+ const { dateRange, trendsFilter, isTrends, isRetention, querySource } = useValues(insightVizDataLogic(insightProps))
const { updateDateRange, updateQuerySource } = useActions(insightVizDataLogic(insightProps))
+ const { reportInsightDatePickerOpened } = useActions(eventUsageLogic)
const { weekStartDay } = useValues(teamLogic)
const [open, setOpen] = useState(false)
@@ -98,7 +100,15 @@ export function InsightQuillDateFilter({ disabled }: InsightQuillDateFilterProps
const exclusionParts = dateFilterExclusionParts(exclusions)
return (
- <Popover open={open} onOpenChange={setOpen}>
+ <Popover
+ open={open}
+ onOpenChange={(next) => {
+ if (next && !open) {
+ reportInsightDatePickerOpened(querySource?.kind)
+ }
+ setOpen(next)
+ }}
+ >
<PopoverTrigger
render={
<Button