From 93a262d185fcba2d919692c32e88ce0f97a9ec98 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Tue, 29 Sep 2026 16:34:03 +0800 Subject: [PATCH] Check region selection for project creation (#51012) ## Context Previously added telemetry for `selectedRegionOption` and `selectedRegionOptionType` [here](https://github.com/supabase/supabase/issues/50851) if the best available region option is available for users Opting to extend this telemetry (still just for Free plan orgs) irregardless if best available region was selected and include `initialRecommendedRegion` Main thing to understand is what regions users are spinning projects up in outside of the recommended option ## To test - [ ] Verify the telemetry network request after creating projects - [ ] Non-free plan: Telemetry request doesn't have `initialRecommendedRegion` in the payload - [ ] Free plan: Telemetry request has `initialRecommendedRegion` in the payload - Sends correctly if best available region option is available (default behaviour for staging) - Sends correctly if best available region option is NOT available (override with dev tools the configcat flag) --- .../ProjectCreation/ProjectCreationForm.tsx | 19 ++++++++++++++++- packages/common/telemetry-constants.ts | 21 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx index 0ad0e897952..dca2cafbeb7 100644 --- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx +++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx @@ -152,6 +152,9 @@ export const ProjectCreationForm = ({ showBestAvailableRegionFeature && showBestAvailableRegionFlag && isFreePlan const [isBestAvailableSelected, setIsBestAvailableSelected] = useState(false) + const shouldTrackRegionRecommendation = isFreePlan && showBestAvailableRegionFeature + const initialRecommendedRegionRef = useRef(undefined) + // Read the raw flag for telemetry — coerce-undefined-to-false would record false for // users whose flags haven't loaded yet. The raw value preserves undefined (omitted from // PostHog) so we only record an actual value (boolean true/false, or a variant string @@ -302,6 +305,16 @@ export const ProjectCreationForm = ({ ? availableRegionsData?.recommendations.smartGroup.name : '' + if ( + initialRecommendedRegionRef.current === undefined && + flagsLoaded && + shouldTrackRegionRecommendation + ) { + initialRecommendedRegionRef.current = showBestAvailableRegionOption + ? 'best_available' + : recommendedSmartRegion || undefined + } + const fixedDefaultRegion = PROVIDERS[selectedCloudProvider].default_region.displayName const regionError = smartRegionEnabled ? availableRegionsError : defaultRegionError const defaultRegion = resolveDefaultDbRegion({ @@ -374,7 +387,11 @@ export const ProjectCreationForm = ({ ...(dataApiRevokeOnCreateDefaultFlag !== undefined && { dataApiRevokeOnCreateDefaultEnabled: dataApiRevokeOnCreateDefaultFlag, }), - ...(showBestAvailableRegionOption && { selectedRegionOption, selectedRegionOptionType }), + ...(shouldTrackRegionRecommendation && { + selectedRegionOption, + selectedRegionOptionType, + initialRecommendedRegion: initialRecommendedRegionRef.current, + }), }, { project: res.ref, diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts index dbddceff257..473b6b7169f 100644 --- a/packages/common/telemetry-constants.ts +++ b/packages/common/telemetry-constants.ts @@ -450,9 +450,12 @@ export interface ProjectCreationSimpleVersionSubmittedEvent { */ dataApiRevokeOnCreateDefaultEnabled?: boolean | string /** - * Which region option was submitted. Only present when the "Best available region" option - * was shown to the user (see `showBestAvailableRegionOption` in RegionSelector.tsx); omitted - * entirely for users who never saw that option. + * Which region option was submitted. Only present for the region-recommendation experiment's + * eligible cohort (free plan + `project_creation:show_best_available_region` feature enabled — + * see `shouldTrackRegionRecommendation` in ProjectCreationForm.tsx). This is cohort-level + * eligibility, not "the option was shown" — it's present for both the PostHog flag's control + * and test arms so the two can be compared; omitted entirely outside the cohort (e.g. paid + * plans, or providers like AWS_NIMBUS where the feature is disabled). * 'best_available' = the "Best available region" shortcut was used * otherwise = the name of the region that was directly selected (e.g. 'Americas', 'ap-southeast-1') */ @@ -464,6 +467,18 @@ export interface ProjectCreationSimpleVersionSubmittedEvent { * 'specific' = picked from the "Specific regions" list */ selectedRegionOptionType?: 'general' | 'specific' + /** + * The region that was recommended/defaulted to on initial render, before any user + * interaction. Present under the same cohort gate as `selectedRegionOption`. Frozen the + * first time it's known, so a later refetch (e.g. switching cloud provider or instance size) + * doesn't overwrite what was actually shown to the user initially. + * 'best_available' = the user was in the PostHog flag's test arm, so the form defaulted to + * the "Best available region" shortcut + * otherwise = the name of the smart-group region recommended by the `available-regions` + * endpoint (e.g. 'Americas'), for users in the flag's control arm + * undefined = no recommendation had loaded yet at submission time + */ + initialRecommendedRegion?: string } groups: TelemetryGroups }