Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Check region selection for project creation (#51012)

Joshen Lim93a262d185fc
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<string | undefined>(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
}