The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Simplify realtime experiment to rely on PostHog targeting (#41210)
Sean Oliver30adf96a0ee9
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsxindex 0c91f6e92a0..edb42974657 100644--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx@@ -113,7 +113,6 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsPropconst isRealtimeEnabled = realtimeEnabledTables.some((t) => t.id === table?.id)const { activeVariant: activeRealtimeVariant } = useRealtimeExperiment({- projectInsertedAt: project?.inserted_at,isTable,isRealtimeEnabled,})diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsxindex 9b71ffaeba8..ab128d6c7a4 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx@@ -130,7 +130,6 @@ export const TableEditor = ({: realtimeEnabledTables.some((t) => t.id === table?.id)const { activeVariant: activeRealtimeVariant } = useRealtimeExperiment({- projectInsertedAt: project?.inserted_at,isTable: !isNewRecord,isRealtimeEnabled,})diff --git a/apps/studio/hooks/misc/useRealtimeExperiment.ts b/apps/studio/hooks/misc/useRealtimeExperiment.tsindex aca021b312f..bf7740989d7 100644--- a/apps/studio/hooks/misc/useRealtimeExperiment.ts+++ b/apps/studio/hooks/misc/useRealtimeExperiment.ts@@ -1,18 +1,9 @@-import dayjs from 'dayjs'-import utc from 'dayjs/plugin/utc'import { useEffect, useMemo, useRef } from 'react'import { usePHFlag } from 'hooks/ui/useFlag'import { IS_PLATFORM } from 'lib/constants'import { useTrack } from 'lib/telemetry/track'-dayjs.extend(utc)--/**- * Days after project creation to be considered "new" for experiment targeting- */-export const NEW_PROJECT_THRESHOLD_DAYS = 7-export enum RealtimeButtonVariant {CONTROL = 'control',HIDE_BUTTON = 'hide-button',@@ -20,40 +11,22 @@ export enum RealtimeButtonVariant {}interface UseRealtimeExperimentOptions {- /**- * Project creation timestamp- */- projectInsertedAt?: string- /**- * Whether the current context is a table (not a view/foreign table)- */+ /** Whether the current context is a table (not a view/foreign table) */isTable?: boolean- /**- * Whether realtime is currently enabled for the table- */+ /** Whether realtime is currently enabled for the table */isRealtimeEnabled?: boolean}interface UseRealtimeExperimentResult {- /**- * The active variant for this user/project, or null if not in experiment- */+ /** The active variant for this user, or null if not in experiment */activeVariant: RealtimeButtonVariant | null- /**- * Whether this project is considered "new" for experiment targeting- */- isNewProject: boolean}/**- * Hook to manage the realtime button A/B experiment logic.- * Handles variant determination, exposure tracking, and date validation.- *- * @param options Configuration for experiment targeting- * @returns Experiment state including active variant and project age+ * Hook to manage the realtime button A/B experiment.+ * User targeting is handled via PostHog experiment configuration.*/export function useRealtimeExperiment({- projectInsertedAt,isTable = false,isRealtimeEnabled = false,}: UseRealtimeExperimentOptions): UseRealtimeExperimentResult {@@ -61,52 +34,35 @@ export function useRealtimeExperiment({const realtimeButtonVariant = usePHFlag<RealtimeButtonVariant>('realtimeButtonVariant')const hasTrackedExposure = useRef(false)- const isNewProject = useMemo(() => {- if (!projectInsertedAt) return false-- const insertedDate = dayjs.utc(projectInsertedAt)- if (!insertedDate.isValid()) {- return false- }-- return dayjs.utc().diff(insertedDate, 'day') < NEW_PROJECT_THRESHOLD_DAYS- }, [projectInsertedAt])-const activeVariant = useMemo(() => {if (!IS_PLATFORM) return null- if (!isTable || !isNewProject) return null- if (!realtimeButtonVariant || realtimeButtonVariant === RealtimeButtonVariant.CONTROL) {- return null- }+ if (!isTable) return null+ if (!realtimeButtonVariant) return null+ if (realtimeButtonVariant === RealtimeButtonVariant.CONTROL) return nullreturn realtimeButtonVariant- }, [isTable, isNewProject, realtimeButtonVariant])+ }, [isTable, realtimeButtonVariant])useEffect(() => {if (!IS_PLATFORM) returnif (hasTrackedExposure.current) return- if (!isTable || !isNewProject || !projectInsertedAt) return- if (!realtimeButtonVariant) return+ if (!isTable || !realtimeButtonVariant) returnhasTrackedExposure.current = truetry {- const insertedDate = dayjs.utc(projectInsertedAt)- if (!insertedDate.isValid()) return-- const daysSinceCreation = dayjs.utc().diff(insertedDate, 'day')-track('realtime_experiment_exposed', {+ experiment_id: 'realtimeButtonVariant',variant: realtimeButtonVariant,table_has_realtime_enabled: isRealtimeEnabled,- days_since_project_creation: daysSinceCreation,})- } catch {+ } catch (error) {+ // Reset tracking flag on error to allow retryhasTrackedExposure.current = false+ console.error('Failed to track realtime experiment exposure:', error)}- }, [isTable, isNewProject, realtimeButtonVariant, projectInsertedAt, isRealtimeEnabled, track])+ }, [isTable, realtimeButtonVariant, isRealtimeEnabled, track])return {activeVariant,- isNewProject,}}diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.tsindex b0b87eb1329..443027b85d8 100644--- a/packages/common/telemetry-constants.ts+++ b/packages/common/telemetry-constants.ts@@ -1716,18 +1716,12 @@ export interface HomeActivityStatClickedEvent {export interface RealtimeExperimentExposedEvent {action: 'realtime_experiment_exposed'properties: {- /**- * The experiment variant shown to the user- */+ /** The PostHog experiment/feature flag name */+ experiment_id: 'realtimeButtonVariant'+ /** The experiment variant shown to the user */variant: 'control' | 'hide-button' | 'triggers'- /**- * Whether the table already has realtime enabled- */+ /** Whether the table already has realtime enabled */table_has_realtime_enabled: boolean- /**- * Days since project creation (to segment by new user cohorts)- */- days_since_project_creation: number}groups: TelemetryGroups}