diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx index cd74359799316..8d764a1ecd6cd 100644 --- a/frontend/src/lib/constants.tsx +++ b/frontend/src/lib/constants.tsx @@ -210,6 +210,7 @@ export const FEATURE_FLAGS = { SETTINGS_BOUNCE_RATE_PAGE_VIEW_MODE: 'settings-bounce-rate-page-view-mode', // owner: @robbie-c SURVEYS_BRANCHING_LOGIC: 'surveys-branching-logic', // owner: @jurajmajerik #team-feature-success WEB_ANALYTICS_LIVE_USER_COUNT: 'web-analytics-live-user-count', // owner: @robbie-c + SETTINGS_SESSION_TABLE_VERSION: 'settings-session-table-version', // owner: @robbie-c } as const export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS] diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts index e798813d59c03..8150bfa869a96 100644 --- a/frontend/src/lib/utils/eventUsageLogic.ts +++ b/frontend/src/lib/utils/eventUsageLogic.ts @@ -395,6 +395,7 @@ export const eventUsageLogic = kea([ reportPoEModeUpdated: (mode: string) => ({ mode }), reportPersonsJoinModeUpdated: (mode: string) => ({ mode }), reportBounceRatePageViewModeUpdated: (mode: string) => ({ mode }), + reportSessionTableVersionUpdated: (version: string) => ({ version }), reportPropertySelectOpened: true, reportCreatedDashboardFromModal: true, reportSavedInsightToDashboard: true, @@ -810,6 +811,9 @@ export const eventUsageLogic = kea([ reportBounceRatePageViewModeUpdated: async ({ mode }) => { posthog.capture('bounce rate page view mode updated', { mode }) }, + reportSessionTableVersionUpdated: async ({ version }) => { + posthog.capture('session table version updated', { version }) + }, reportInsightFilterRemoved: async ({ index }) => { posthog.capture('local filter removed', { index }) }, diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx index ee7c6c3b363b5..41c9f83b878b8 100644 --- a/frontend/src/scenes/settings/SettingsMap.tsx +++ b/frontend/src/scenes/settings/SettingsMap.tsx @@ -1,6 +1,7 @@ import { BounceRatePageViewModeSetting } from 'scenes/settings/project/BounceRatePageViewMode' import { PersonsJoinMode } from 'scenes/settings/project/PersonsJoinMode' import { PersonsOnEvents } from 'scenes/settings/project/PersonsOnEvents' +import { SessionsTableVersion } from 'scenes/settings/project/SessionsTableVersion' import { Invites } from './organization/Invites' import { Members } from './organization/Members' @@ -167,6 +168,12 @@ export const SettingsMap: SettingSection[] = [ component: , flag: 'SETTINGS_BOUNCE_RATE_PAGE_VIEW_MODE', }, + { + id: 'session-table-version', + title: 'Sessions Table Version', + component: , + flag: 'SETTINGS_SESSION_TABLE_VERSION', + }, ], }, diff --git a/frontend/src/scenes/settings/project/SessionsTableVersion.tsx b/frontend/src/scenes/settings/project/SessionsTableVersion.tsx new file mode 100644 index 0000000000000..368e9d1ef71ea --- /dev/null +++ b/frontend/src/scenes/settings/project/SessionsTableVersion.tsx @@ -0,0 +1,75 @@ +import { useActions, useValues } from 'kea' +import { LemonButton } from 'lib/lemon-ui/LemonButton' +import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio' +import { eventUsageLogic } from 'lib/utils/eventUsageLogic' +import { useState } from 'react' +import { teamLogic } from 'scenes/teamLogic' + +import { HogQLQueryModifiers } from '~/queries/schema' + +type SessionTableVersion = NonNullable + +const bounceRatePageViewModeOptions: LemonRadioOption[] = [ + { + value: 'auto', + label: ( + <> +
Auto
+ + ), + }, + { + value: 'v1', + label: ( + <> +
Version 1
+ + ), + }, + { + value: 'v2', + label: ( + <> +
Version 2
+ + ), + }, +] + +export function SessionsTableVersion(): JSX.Element { + const { updateCurrentTeam } = useActions(teamLogic) + const { currentTeam } = useValues(teamLogic) + const { reportSessionTableVersionUpdated } = useActions(eventUsageLogic) + + const savedSessionTableVersion = + currentTeam?.modifiers?.sessionTableVersion ?? currentTeam?.default_modifiers?.sessionTableVersion ?? 'auto' + const [sessionTableVersion, setSessionTableVersion] = useState(savedSessionTableVersion) + + const handleChange = (version: SessionTableVersion): void => { + updateCurrentTeam({ modifiers: { ...currentTeam?.modifiers, sessionTableVersion: version } }) + reportSessionTableVersionUpdated(version) + } + + return ( + <> +

+ Choose which version of the session table to use. V2 is faster, but requires uuidv7 session ids. Use + auto unless you know what you're doing. +

+ +
+ handleChange(sessionTableVersion)} + disabledReason={sessionTableVersion === savedSessionTableVersion ? 'No changes to save' : undefined} + > + Save + +
+ + ) +} diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.ts index d63d797ef536a..35b01185e1986 100644 --- a/frontend/src/scenes/settings/types.ts +++ b/frontend/src/scenes/settings/types.ts @@ -82,6 +82,7 @@ export type SettingId = | 'hedgehog-mode' | 'persons-join-mode' | 'bounce-rate-page-view-mode' + | 'session-table-version' type FeatureFlagKey = keyof typeof FEATURE_FLAGS diff --git a/posthog/hogql/modifiers.py b/posthog/hogql/modifiers.py index 8deb1fffdae12..0fa3e390e1796 100644 --- a/posthog/hogql/modifiers.py +++ b/posthog/hogql/modifiers.py @@ -52,8 +52,8 @@ def set_default_modifier_values(modifiers: HogQLQueryModifiers, team: "Team"): if modifiers.bounceRatePageViewMode is None: modifiers.bounceRatePageViewMode = BounceRatePageViewMode.COUNT_PAGEVIEWS - if modifiers.sessionTableVersion is None or modifiers.sessionTableVersion == SessionTableVersion.AUTO: - modifiers.sessionTableVersion = SessionTableVersion.V1 + if modifiers.sessionTableVersion is None: + modifiers.sessionTableVersion = SessionTableVersion.AUTO def set_default_in_cohort_via(modifiers: HogQLQueryModifiers) -> HogQLQueryModifiers: diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py index 4db5cc85d39c0..c4fc6ecc34a0c 100644 --- a/posthog/hogql_queries/test/test_query_runner.py +++ b/posthog/hogql_queries/test/test_query_runner.py @@ -90,7 +90,7 @@ def test_cache_payload(self): "optimizeJoinedFilters": False, "personsOnEventsMode": "disabled", "bounceRatePageViewMode": "count_pageviews", - "sessionTableVersion": "v1", + "sessionTableVersion": "auto", }, "limit_context": "query", "query": {"kind": "TestQuery", "some_attr": "bla"}, @@ -109,7 +109,7 @@ def test_cache_key(self): runner = TestQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_19dbcf2dbe2bd72239f37007f2eb6224") + self.assertEqual(cache_key, "cache_c4e20e19f3cad552478257f71f80b52f") def test_cache_key_runner_subclass(self): TestQueryRunner = self.setup_test_query_runner_class() @@ -123,7 +123,7 @@ class TestSubclassQueryRunner(TestQueryRunner): runner = TestSubclassQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_325bbd17cd27dd556d765984ba993da0") + self.assertEqual(cache_key, "cache_db0fcd4797812983cbf9df57cd9f3032") def test_cache_key_different_timezone(self): TestQueryRunner = self.setup_test_query_runner_class() @@ -134,7 +134,7 @@ def test_cache_key_different_timezone(self): runner = TestQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_c1d666350117520920dbc3cc9286195c") + self.assertEqual(cache_key, "cache_8c92e69a656cc68522e5b48a7304b97d") @mock.patch("django.db.transaction.on_commit") def test_cache_response(self, mock_on_commit):