Skip to content

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

chore(studio): add telemetry for data API access toggle rollout (#43913)

Sean Oliverce00372b402a
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx
index b163ab1d651..183773915e7 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx
@@ -21,6 +21,7 @@ import { Admonition } from 'ui-patterns'
import { Input } from 'ui-patterns/DataInputs/Input'
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
+import { useTrack } from 'lib/telemetry/track'
import { defaultPrivilegesQueryOptions } from '@/data/privileges/default-privileges-query'
import { useTableApiAccessQuery } from '@/data/privileges/table-api-access-query'
import { useStaticEffectEvent } from '@/hooks/useStaticEffectEvent'
@@ -282,6 +283,7 @@ export const ApiAccessToggle = ({
isNewRecord,
handler,
}: ApiAccessToggleComponentProps): ReactNode => {
+ const track = useTrack()
const isPending = handler.isPending
const isError = handler.isError
const isSchemaExposed = handler.data?.schemaExposed
@@ -295,6 +297,13 @@ export const ApiAccessToggle = ({
if (!handler.isSuccess) return
if (!isSchemaExposed) return
+ if (isNewRecord) {
+ track('table_api_access_toggle_clicked', {
+ newState: checked ? 'enabled' : 'disabled',
+ schemaName: schemaName ?? 'unknown',
+ })
+ }
+
if (checked) {
handler.data?.restorePreviousPrivileges()
} else {
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index e6d8b3192ab..cefe4ac1267 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -46,6 +46,7 @@ import { useCustomContent } from 'hooks/custom-content/useCustomContent'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useDataApiGrantTogglesEnabled } from 'hooks/misc/useDataApiGrantTogglesEnabled'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
+import { usePHFlag } from 'hooks/ui/useFlag'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { withAuth } from 'hooks/misc/withAuth'
@@ -96,6 +97,10 @@ const Wizard: NextPageWithLayout = () => {
const showPostgresVersionSelector = useFlag('showPostgresVersionSelector')
const cloudProviderEnabled = useFlag('enableFlyCloudProvider')
const isDataApiGrantTogglesEnabled = useDataApiGrantTogglesEnabled()
+ // Read the raw flag for telemetry — useDataApiGrantTogglesEnabled coerces undefined→false,
+ // which would record false for users whose flags haven't loaded yet. The raw value preserves
+ // undefined (omitted from PostHog) so we only record true/false when the flag is resolved.
+ const tableEditorApiAccessToggleFlag = usePHFlag<boolean>('tableEditorApiAccessToggle')
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
const isNotOnHigherPlan = !['team', 'enterprise', 'platform'].includes(currentOrg?.plan.id ?? '')
@@ -259,6 +264,9 @@ const Wizard: NextPageWithLayout = () => {
enableRlsEventTrigger: form.getValues('enableRlsEventTrigger'),
dataApiEnabled: form.getValues('dataApi'),
useOrioleDb: form.getValues('useOrioleDb'),
+ ...(tableEditorApiAccessToggleFlag !== undefined && {
+ tableEditorApiAccessToggleEnabled: tableEditorApiAccessToggleFlag,
+ }),
},
{
project: res.ref,
diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts
index 06cd6463049..20473e5c35d 100644
--- a/packages/common/telemetry-constants.ts
+++ b/packages/common/telemetry-constants.ts
@@ -291,10 +291,10 @@ export interface ProjectCreationRlsOptionExperimentExposedEvent {
*/
export interface ProjectCreationSimpleVersionSubmittedEvent {
action: 'project_creation_simple_version_submitted'
- /**
- * the instance size selected in the project creation form
- */
properties: {
+ /**
+ * The instance size selected in the project creation form.
+ */
instanceSize?: string
/**
* Whether the automatic RLS event trigger option was enabled
@@ -322,6 +322,14 @@ export interface ProjectCreationSimpleVersionSubmittedEvent {
* false = "Postgres" (default)
*/
useOrioleDb?: boolean
+ /**
+ * Whether the tableEditorApiAccessToggle PostHog flag was enabled for this user,
+ * meaning the project was created with default public schema grants revoked.
+ * true = user is in the staged rollout cohort (revoke SQL ran at creation)
+ * false = user is outside the rollout (default grants left intact)
+ * omitted = PostHog flags had not loaded at the time of project creation
+ */
+ tableEditorApiAccessToggleEnabled?: boolean
}
groups: TelemetryGroups
}
@@ -344,6 +352,29 @@ export interface ProjectCreationSimpleVersionConfirmModalOpenedEvent {
groups: Omit<TelemetryGroups, 'project'>
}
+/**
+ * User toggled Data API access on a table via the switch in the table editor side panel.
+ * Only fires for new tables — editing existing tables links out to the settings page instead.
+ *
+ * @group Events
+ * @source studio
+ * @page /dashboard/project/{ref}/editor
+ */
+export interface TableApiAccessToggleClickedEvent {
+ action: 'table_api_access_toggle_clicked'
+ properties: {
+ /**
+ * The resulting state of the toggle after the click.
+ */
+ newState: 'enabled' | 'disabled'
+ /**
+ * The schema containing the table being created.
+ */
+ schemaName: string
+ }
+ groups: TelemetryGroups
+}
+
/**
* On the InitialStep.tsx screen, where user can chose to prompt, start blank or migrate, at least 5 characters were typed
* in the prompt textarea indicating an intention to use the prompt.
@@ -3034,6 +3065,7 @@ export type TelemetryEvent =
| ProjectCreationRlsOptionExperimentExposedEvent
| ProjectCreationSimpleVersionSubmittedEvent
| ProjectCreationSimpleVersionConfirmModalOpenedEvent
+ | TableApiAccessToggleClickedEvent
| ProjectCreationInitialStepPromptIntendedEvent
| ProjectCreationInitialStepSubmittedEvent
| ProjectCreationSecondStepPromptIntendedEvent