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.

fix(web-analytics): keep an interval that equals the range default (#97845)

posthog[bot]95b8e20c4f5e
diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
index 8546ee77f722..e459e452d1b9 100644
--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
@@ -429,6 +429,28 @@ describe('webAnalyticsLogic URL restoration', () => {
expect(logic.values.dateFilter).toMatchObject({ dateFrom: '-30d', dateTo: '-1d', interval: 'week' })
})
+ it('keeps a date range and interval that equal the defaults when another filter changes', async () => {
+ // Arrive off the defaults, so the URL carries all three date params.
+ router.actions.push('/web', { date_from: '-30d', date_to: '-1d', interval: 'hour' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ // Back onto the defaults: '-7d' with no end date, grouped by day. Every date param must drop
+ // out of the URL instead of keeping its previous value.
+ logic.actions.setDates('-7d', null)
+ logic.actions.setDateInterval('day')
+ await expectLogic(logic).toFinishAllListeners()
+ expect(router.values.searchParams.date_from).toBeUndefined()
+ expect(router.values.searchParams.date_to).toBeUndefined()
+ expect(router.values.searchParams.interval).toBeUndefined()
+
+ // Any later URL write runs urlToAction again. A param left behind is restored here and
+ // silently undoes what the user picked.
+ logic.actions.setCompareFilter({ compare: false })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.dateFilter).toMatchObject({ dateFrom: '-7d', dateTo: null, interval: 'day' })
+ })
+
it.each<[string, Record<string, string>]>([
['tab params', { device_tab: 'BROWSER', source_tab: 'REFERRING_DOMAIN', path_tab: 'INITIAL_PATH' }],
['cross-logic filter params', { domain: 'example.com', device_type: 'Desktop', percentile: 'p99' }],
diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
index e7a5dc68b1e4..8cef36bb0822 100644
--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
@@ -3219,6 +3219,13 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
urlParams.set('date_from', dateFrom ?? '')
urlParams.set('date_to', dateTo ?? '')
urlParams.set('interval', interval ?? '')
+ } else {
+ // Delete these params when the state is at its defaults. `urlParams` starts from the
+ // live URL, so a param left behind keeps an earlier value, which `urlToAction` reads
+ // back and applies over the user's current selection.
+ urlParams.delete('date_from')
+ urlParams.delete('date_to')
+ urlParams.delete('interval')
}
if (_deviceTab) {
urlParams.set('device_tab', _deviceTab)