The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): additional events for scoped pat telemetry (#49965)
kemal.earth865499184740
diff --git a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenSuccess.tsx b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenSuccess.tsxindex 5023f82b78b..5032a4b622e 100644--- a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenSuccess.tsx+++ b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenSuccess.tsx@@ -4,14 +4,40 @@ import { Button, Checkbox, ScrollArea, SheetFooter } from 'ui'import { Admonition } from 'ui-patterns/Admonition'import { Input } from 'ui-patterns/DataInputs/Input'+import { useTrack } from '@/lib/telemetry/track'+interface TokenSuccessProps {tokenName: stringtokenValue: string+ tokenType: 'classic' | 'scoped'onClose: () => void}-export const NewScopedTokenSuccess = ({ tokenName, tokenValue, onClose }: TokenSuccessProps) => {+export const NewScopedTokenSuccess = ({+ tokenName,+ tokenValue,+ tokenType,+ onClose,+}: TokenSuccessProps) => {+ const track = useTrack()const [keyCopied, setKeyCopied] = useState(false)+ const [hasCopiedToken, setHasCopiedToken] = useState(false)++ const handleCopy = () => {+ setHasCopiedToken(true)+ track('access_token_copied', { tokenType })+ toast.success('Token copied to clipboard')+ }++ const handleAcknowledge = (isChecked: boolean) => {+ setKeyCopied(isChecked)+ track('access_token_stored_checkbox_clicked', { tokenType, isChecked })+ }++ const handleDone = () => {+ track('access_token_done_button_clicked', { tokenType, hasCopiedToken })+ onClose()+ }return (<>@@ -33,7 +59,7 @@ export const NewScopedTokenSuccess = ({ tokenName, tokenValue, onClose }: TokenSvalue={tokenValue}onChange={() => {}}aria-label={`${tokenName} token`}- onCopy={() => toast.success('Token copied to clipboard')}+ onCopy={handleCopy}/><Admonition@@ -46,7 +72,7 @@ export const NewScopedTokenSuccess = ({ tokenName, tokenValue, onClose }: TokenS<Checkboxid="key-copied"checked={keyCopied}- onCheckedChange={(v) => setKeyCopied(Boolean(v))}+ onCheckedChange={(v) => handleAcknowledge(Boolean(v))}/><span className="text-sm text-warning cursor-pointer select-none">I have copied the key and stored it securely@@ -56,7 +82,7 @@ export const NewScopedTokenSuccess = ({ tokenName, tokenValue, onClose }: TokenS</div></ScrollArea><SheetFooter className="mt-auto flex w-full items-center justify-between! border-t py-4">- <Button className="ml-auto" disabled={!keyCopied} onClick={onClose}>+ <Button className="ml-auto" disabled={!keyCopied} onClick={handleDone}>Done</Button></SheetFooter>diff --git a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsxindex 7f4480086bf..4699369cdad 100644--- a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx+++ b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx@@ -235,8 +235,17 @@ describe('NewScopedTokenSheet', () => {await waitFor(async () =>expect(await window.navigator.clipboard.readText()).toEqual('a_token_value'))+ expect(mockTrack).toHaveBeenCalledWith('access_token_copied', { tokenType: 'scoped' })fireEvent.click(await screen.findByLabelText('I have copied the key and stored it securely'))+ expect(mockTrack).toHaveBeenCalledWith('access_token_stored_checkbox_clicked', {+ tokenType: 'scoped',+ isChecked: true,+ })fireEvent.click(await screen.findByRole('button', { name: 'Done' }))+ expect(mockTrack).toHaveBeenCalledWith('access_token_done_button_clicked', {+ tokenType: 'scoped',+ hasCopiedToken: true,+ })// Dialog has been closedawait waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())}, 10_000)@@ -451,8 +460,13 @@ describe('NewScopedTokenSheet', () => {expiryPreset: '7d',resourceAccess: 'account',})+ expect(mockTrack).toHaveBeenCalledWith('access_token_copied', { tokenType: 'classic' })fireEvent.click(await screen.findByLabelText('I have copied the key and stored it securely'))fireEvent.click(await screen.findByRole('button', { name: 'Done' }))+ expect(mockTrack).toHaveBeenCalledWith('access_token_done_button_clicked', {+ tokenType: 'classic',+ hasCopiedToken: true,+ })// Dialog has been closedawait waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())})diff --git a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.tsx b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.tsxindex b7875967542..77eca42f91f 100644--- a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.tsx+++ b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.tsx@@ -42,12 +42,15 @@ export const NewScopedTokenSheet = ({ onCreateExperimentalToken }: NewScopedTokeconst [step, setStep] = useState<'form' | 'success'>('form')const [createdToken, setCreatedToken] = useState<- NewScopedAccessToken | NewAccessToken | undefined+ { token: NewScopedAccessToken | NewAccessToken; tokenType: 'classic' | 'scoped' } | undefined>()- const showCreatedToken = (data: NewScopedAccessToken | NewAccessToken) => {+ const showCreatedToken = (+ data: NewScopedAccessToken | NewAccessToken,+ tokenType: 'classic' | 'scoped'+ ) => {toast.success('Access token created successfully')- setCreatedToken(data)+ setCreatedToken({ token: data, tokenType })setStep('success')}@@ -66,7 +69,7 @@ export const NewScopedTokenSheet = ({ onCreateExperimentalToken }: NewScopedTokeexpiryPreset: values.expiresAt,resourceAccess: 'account',})- showCreatedToken(data)+ showCreatedToken(data, 'classic')},})@@ -94,7 +97,7 @@ export const NewScopedTokenSheet = ({ onCreateExperimentalToken }: NewScopedTokeresourceAccess: values.resourceAccess,permissionCount: permissions.length,})- showCreatedToken(data)+ showCreatedToken(data, 'scoped')},})}@@ -103,6 +106,13 @@ export const NewScopedTokenSheet = ({ onCreateExperimentalToken }: NewScopedToke// as we need to make sure they copied the new token firstconst handleOpenChange = (open: boolean, isSafe = false) => {if (open === false && step === 'success' && !isSafe) return+ if (open === false) {+ track('access_token_creation_sheet_dismissed', {+ // Can be non when users closes the sheet without completing the token creation+ tokenType: createdToken?.tokenType ?? 'none',+ step,+ })+ }setStep('form')setIsOpen(open)}@@ -134,8 +144,9 @@ export const NewScopedTokenSheet = ({ onCreateExperimentalToken }: NewScopedToke</SheetHeader>{step === 'success' && createdToken ? (<NewScopedTokenSuccess- tokenName={createdToken.name}- tokenValue={createdToken.token}+ tokenName={createdToken.token.name}+ tokenValue={createdToken.token.token}+ tokenType={createdToken.tokenType}onClose={() => handleOpenChange(false, true)}/>) : (diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.tsindex dbe916ee052..e01b9126af4 100644--- a/packages/common/telemetry-constants.ts+++ b/packages/common/telemetry-constants.ts@@ -3533,6 +3533,22 @@ export interface AccessTokenCreatedEvent {groups: Omit<TelemetryGroups, 'project'>}+/**+ * Triggered when an access token creation sheet is closed.+ *+ * @group Events+ * @source studio+ * @page /account/tokens+ */+export interface AccessTokenCreationSheetDismissedEvent {+ action: 'access_token_creation_sheet_dismissed'+ properties: {+ tokenType: 'classic' | 'scoped' | 'none'+ step: 'form' | 'success'+ }+ groups: Omit<TelemetryGroups, 'project'>+}+/*** Triggered when an access token is successfully deleted.*@@ -3548,6 +3564,57 @@ export interface AccessTokenRemovedEvent {groups: Omit<TelemetryGroups, 'project'>}+/**+ * Triggered when the copy button is used on the token value shown after creation. The value is+ * only ever displayed once, so this measures how many users leave with a usable token.+ *+ * @group Events+ * @source studio+ * @page /account/tokens (token created step of the generate token sheet)+ */+export interface AccessTokenCopiedEvent {+ action: 'access_token_copied'+ properties: {+ tokenType: 'classic' | 'scoped'+ }+ groups: Omit<TelemetryGroups, 'project'>+}++/**+ * Triggered when the "I have copied the key and stored it securely" checkbox is toggled on the+ * token created step. `isChecked` is the resulting state, so unticking is tracked too.+ *+ * @group Events+ * @source studio+ * @page /account/tokens (token created step of the generate token sheet)+ */+export interface AccessTokenStoredCheckboxClickedEvent {+ action: 'access_token_stored_checkbox_clicked'+ properties: {+ tokenType: 'classic' | 'scoped'+ /** The state the checkbox was toggled into */+ isChecked: boolean+ }+ groups: Omit<TelemetryGroups, 'project'>+}++/**+ * Triggered when the "Done" button dismisses the token created step, completing the creation flow.+ *+ * @group Events+ * @source studio+ * @page /account/tokens (token created step of the generate token sheet)+ */+export interface AccessTokenDoneButtonClickedEvent {+ action: 'access_token_done_button_clicked'+ properties: {+ tokenType: 'classic' | 'scoped'+ /** Whether the copy button was used before finishing, as opposed to copying the value manually */+ hasCopiedToken: boolean+ }+ groups: Omit<TelemetryGroups, 'project'>+}+/*** User clicked the "Upgrade to Pro" CTA. Fired from each CTA placement surface, with* `placement` identifying which one (the user dropdown or the org project-list usage card).@@ -4008,7 +4075,11 @@ export type TelemetryEvent =| UpgradeCtaClickedEvent| PricingPanelPlanPresentationExperimentExposedEvent| AccessTokenCreatedEvent+ | AccessTokenCreationSheetDismissedEvent| AccessTokenRemovedEvent+ | AccessTokenCopiedEvent+ | AccessTokenStoredCheckboxClickedEvent+ | AccessTokenDoneButtonClickedEvent| ResourceExhaustionBannerUpgradeClickedEvent| ResourceExhaustionBannerAiAssistantClickedEvent| UnifiedLogsRowClickedEvent