Files
supabase/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx
supabase-vercel-tedd[bot]andIvan Vasilov e3684c034c feat(studio): track usage on Project Settings: General (#54081)
## Problem

Project Settings → General has almost no usage tracking. We can't tell
how often users restart, pause, resume, or transfer projects from here.
We also can't tell how often they copy the project ID or region, use the
custom domain flow, or toggle high compliance mode.

## Solution

Adds six PostHog events to `packages/common/telemetry-constants.ts`:
`project_name_updated`, `project_settings_value_copied`,
`project_lifecycle_action_submitted`, `project_compliance_mode_updated`,
`custom_domain_step_submitted`, and `custom_domain_dns_record_copied`.
Each event fires from the user's submit, confirm, copy, or toggle
handler, never on render. Properties are only enums and booleans. No
project names, domains, DNS record contents, or other typed values are
sent.

`ResumeProjectButton` is shared between settings and the paused-project
home state, so it now takes a required `source` prop. The two call sites
pass `settings_general` and `project_home`. Restart fires from the
confirmation modal, with `restart_project` or `restart_database`
depending on the chosen restart type. `DNSRecord` now types its `type`
prop as `'CNAME' | 'TXT'`, so the copy event sends the record type as an
enum. No `data-attr` attributes are added, because PostHog autocapture
is off and they would not be collected.

## How to verify

1. On Project Settings → General, save a new project name. One
`project_name_updated` event fires.
2. Copy the project ID, then the region. Each copy fires one
`project_settings_value_copied` event, with `field` set to `projectRef`
and then `region`.
3. Open the restart modal, then cancel it. No event fires. Confirm a
restart (project or fast database reboot). One
`project_lifecycle_action_submitted` fires with `action:
restart_project` or `restart_database` and `source: settings_general`.
4. Confirm a pause, a resume, and a transfer. Each fires
`project_lifecycle_action_submitted` with the matching `action`. A
resume from settings sends `source: settings_general`; a resume from the
paused project home page sends `source: project_home`.
5. Toggle high compliance mode. One `project_compliance_mode_updated`
fires, with `isSensitive` set to the new value.
6. In the custom domain flow, Add, Verify, confirm Activate, and confirm
Delete each fire `custom_domain_step_submitted` with `step` set to
`configure`, `verify`, `activate`, and `remove`.
7. In the custom domain verification step, copy a DNS record's name,
then its value. Each copy fires one `custom_domain_dns_record_copied`
event, with `recordType` set to `CNAME` or `TXT` and `field` set to
`name` and then `value`.

## Checks

Ran `tsc --noEmit` in `apps/studio` and `packages/common`. Ran `eslint`
(default config and `eslint.type-checks.config.cjs`) on the changed
Studio files: no errors, only warnings that were already there. Ran
`oxfmt --check` on all changed files. Ran `vitest run` on
`General.test.tsx`, `Project.test.tsx`, `PauseProjectButton.test.tsx`,
and `RestartServerButton.test.tsx`: all pass.

## Checklist

- [x] I have read the [Contributing
Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] I have checked that the change works in the preview deployment

## Feedback for Tedd

To ask Tedd for a change to this PR, reply in Tedd's session on
[FE-5029](https://linear.app/supabase/issue/FE-5029/track-usage-on-project-settings-general).
Tedd doesn't read comments on this PR.

---------

Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-11-30 20:38:20 +01:00

170 lines
5.9 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useParams } from 'common'
import { useForm, useWatch } from 'react-hook-form'
import {
Button,
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
Form,
FormControl,
FormField,
Input,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { z } from 'zod'
import CopyButton from '@/components/ui/CopyButton'
import { DocsButton } from '@/components/ui/DocsButton'
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
import { useCheckCNAMERecordMutation } from '@/data/custom-domains/check-cname-mutation'
import { useCustomDomainCreateMutation } from '@/data/custom-domains/custom-domains-create-mutation'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
import { DOCS_URL } from '@/lib/constants'
import { useTrack } from '@/lib/telemetry/track'
const schema = z.object({
domain: z.string().trim().min(1, 'A value for your custom domain is required'),
})
export const CustomDomainsConfigureHostname = () => {
const { ref } = useParams()
const track = useTrack()
const { mutate: checkCNAMERecord, isPending: isCheckingRecord } = useCheckCNAMERecordMutation()
const { mutate: createCustomDomain, isPending: isCreating } = useCustomDomainCreateMutation()
const { data: settings } = useProjectSettingsV2Query({ projectRef: ref })
const endpoint = settings?.app_config?.endpoint
const { can: canConfigureCustomDomain } = useAsyncCheckPermissionsV2(
FGA_PERMISSIONS.PROJECT.CUSTOM_DOMAIN_WRITE
)
const form = useForm<z.infer<typeof schema>>({
resolver: zodResolver(schema),
defaultValues: {
domain: '',
},
mode: 'onSubmit',
reValidateMode: 'onBlur',
})
const onCreateCustomDomain = async (values: z.infer<typeof schema>) => {
if (!ref) return console.error('Project ref is required')
track('custom_domain_step_submitted', { step: 'configure' })
checkCNAMERecord(
{ domain: values.domain.trim() },
{
onSuccess: () => {
createCustomDomain({ projectRef: ref, customDomain: values.domain.trim() })
},
}
)
}
const domain = useWatch({ control: form.control, name: 'domain' })
const trimmedDomain = domain.trim()
const isSubmitting = isCheckingRecord || isCreating
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onCreateCustomDomain)}>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 gap-4">
<CardTitle>Add a custom domain</CardTitle>
<DocsButton href={`${DOCS_URL}/guides/platform/custom-domains`} />
</CardHeader>
<CardContent>
<div className="space-y-4">
<FormField
control={form.control}
name="domain"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label="Custom domain"
description="Enter the subdomain you want to use."
className="[&>div]:md:w-1/2"
>
<FormControl>
<Input
{...field}
placeholder="subdomain.example.com"
disabled={!canConfigureCustomDomain || isSubmitting}
autoComplete="off"
/>
</FormControl>
</FormItemLayout>
)}
/>
</div>
</CardContent>
<CardContent>
<h4 className="text-sm mb-1">Configure a CNAME record</h4>
<p className="text-sm text-foreground-light">
Set up a CNAME record for{' '}
{domain ? <code>{domain}</code> : <span>your custom domain</span>}{' '}
<span>resolving to</span>{' '}
{endpoint ? (
<span className="inline-flex items-center gap-x-1">
<code>{endpoint}</code>
<CopyButton
iconOnly
variant="text"
className="h-5 w-5 min-w-0 p-0 [&_svg]:h-3 [&_svg]:w-3"
text={endpoint}
/>
</span>
) : (
<span>your project's API URL</span>
)}{' '}
<span>
with as low a TTL as possible. If you're using Cloudflare as your DNS provider,
disable the proxy option.
</span>
<br />
{trimmedDomain.includes('.') ? (
<>
Some DNS providers expect only the subdomain label{' '}
<code>{trimmedDomain.split('.')[0]}</code>, while others accept the full hostname{' '}
<code className="whitespace-nowrap">{trimmedDomain}</code>.
</>
) : (
<span>
Some DNS providers expect only the subdomain label, while others accept the full
hostname.
</span>
)}
</p>
</CardContent>
<CardFooter className="justify-end space-x-2">
{form.formState.isDirty && (
<Button disabled={isSubmitting} onClick={() => form.reset({ domain: '' })}>
Cancel
</Button>
)}
<Button
variant="primary"
type="submit"
loading={isSubmitting}
disabled={!form.formState.isDirty || isSubmitting || !canConfigureCustomDomain}
>
Add
</Button>
</CardFooter>
</Card>
{!canConfigureCustomDomain && (
<p className="text-xs text-foreground-light">
You need additional permissions to update your project's custom domain settings.
</p>
)}
</form>
</Form>
)
}