Files
supabase/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.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

198 lines
7.4 KiB
TypeScript

import { useParams } from 'common'
import { AlertCircleIcon, RefreshCwIcon } from 'lucide-react'
import { useEffect } from 'react'
import { toast } from 'sonner'
import { Alert, AlertDescription, AlertTitle, Button, WarningIcon } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { DNSRecord } from './DNSRecord'
import { DNSTableHeaders } from './DNSTableHeaders'
import { DocsButton } from '@/components/ui/DocsButton'
import { InlineLink } from '@/components/ui/InlineLink'
import Panel from '@/components/ui/Panel'
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
import { useCustomDomainDeleteMutation } from '@/data/custom-domains/custom-domains-delete-mutation'
import { useCustomDomainsQuery } from '@/data/custom-domains/custom-domains-query'
import { useCustomDomainReverifyQuery } from '@/data/custom-domains/custom-domains-reverify-query'
import { DOCS_URL } from '@/lib/constants'
import { useTrack } from '@/lib/telemetry/track'
export const CustomDomainVerify = () => {
const { ref: projectRef } = useParams()
const track = useTrack()
const { data: settings } = useProjectSettingsV2Query({ projectRef })
const { data: customDomainData } = useCustomDomainsQuery({ projectRef })
const customDomain = customDomainData?.customDomain
const isSSLCertificateDeploying =
customDomain?.ssl.status !== undefined && customDomain.ssl.txt_name === undefined
const { mutate: deleteCustomDomain, isPending: isDeleting } = useCustomDomainDeleteMutation({
onSuccess: () => {
toast.success(
'Custom domain setup cancelled successfully. It may take a few seconds before your custom domain is fully removed, so you may need to refresh your browser.'
)
},
})
const {
data: reverifyData,
refetch: refetchReverify,
isFetching: isReverifyLoading,
isError: isReverifyError,
error: reverifyError,
} = useCustomDomainReverifyQuery(
{ projectRef },
{
// Poll every 10 seconds if the SSL certificate is being deployed
refetchInterval: isSSLCertificateDeploying && !isDeleting ? 10000 : false,
}
)
useEffect(() => {
if (isReverifyError) {
toast.error(reverifyError?.message)
}
}, [isReverifyError, reverifyError])
const isNotVerifiedYet = reverifyData?.status === '2_initiated'
const hasCAAErrors = customDomain?.ssl.validation_errors?.reduce(
(acc, error) => acc || error.message.includes('caa_error'),
false
)
const isValidating = (customDomain?.ssl.txt_name ?? '') === ''
const onReverifyCustomDomain = () => {
if (!projectRef) return console.error('Project ref is required')
track('custom_domain_step_submitted', { step: 'verify' })
refetchReverify()
}
const onCancelCustomDomain = async () => {
if (!projectRef) return console.error('Project ref is required')
deleteCustomDomain({ projectRef })
}
return (
<>
<Panel.Content className="space-y-6">
<div>
<h4 className="text-foreground mb-2">
Configure TXT verification for your custom domain <code>{customDomain?.hostname}</code>
</h4>
<p className="text-sm text-foreground-light">
Set the following TXT record(s) in your DNS provider, then click verify to confirm your
control over the domain. Records which have been successfully verified will be removed
from this list below.
</p>
{!isValidating && (
<div className="mt-4 mb-2">
<Admonition
type="note"
title={
isNotVerifiedYet
? 'Unable to verify records from DNS provider yet.'
: 'Please note that it may take up to 24 hours for the DNS records to propagate.'
}
>
<p>
You may also visit{' '}
<InlineLink href={`https://whatsmydns.net/#TXT/${customDomain?.ssl.txt_name}`}>
here
</InlineLink>{' '}
to check if your DNS has been propagated successfully before clicking verify.
</p>
{isNotVerifiedYet && (
<p className="mt-1">
Some registrars will require you to remove the domain name when creating DNS
records. As an example, to create a record for <code>foo.app.example.com</code>,
you would need to create an entry for <code>foo.app</code>.
</p>
)}
</Admonition>
</div>
)}
</div>
{hasCAAErrors && (
<Alert>
<WarningIcon />
<AlertTitle>Certificate Authority Authentication (CAA) error</AlertTitle>
<AlertDescription>
Please add a CAA record allowing "digicert.com" to issue certificates for{' '}
<code>{customDomain?.hostname}</code>. For example:{' '}
<code>0 issue "digicert.com"</code>
</AlertDescription>
</Alert>
)}
{customDomain?.ssl.status === 'validation_timed_out' ? (
<Alert>
<WarningIcon />
<AlertTitle>Validation timed out</AlertTitle>
<AlertDescription>
Please click "Verify" again to retry the validation of the records
</AlertDescription>
</Alert>
) : (
<div className="space-y-2">
<DNSTableHeaders display={customDomain?.ssl.txt_name ?? ''} />
{customDomain?.verification_errors?.includes(
'custom hostname does not CNAME to this zone.'
) && (
<DNSRecord
type="CNAME"
name={customDomain?.hostname}
value={settings?.app_config?.endpoint ?? 'Loading...'}
/>
)}
{!isValidating && customDomain?.ssl.status === 'pending_validation' && (
<DNSRecord
type="TXT"
name={customDomain?.ssl.txt_name ?? 'Loading...'}
value={customDomain?.ssl.txt_value ?? 'Loading...'}
/>
)}
{customDomain?.ssl.status === 'pending_deployment' && (
<div className="flex items-center justify-center space-x-2 py-8">
<AlertCircleIcon size={16} strokeWidth={1.5} />
<p className="text-sm text-foreground-light">
SSL certificate is being deployed. Please wait a few minutes and try again.
</p>
</div>
)}
</div>
)}
</Panel.Content>
<div className="border-t border-muted" />
<Panel.Content>
<div className="flex items-center justify-between">
<DocsButton href={`${DOCS_URL}/guides/platform/custom-domains`} />
<div className="flex items-center space-x-2">
<Button onClick={onCancelCustomDomain} loading={isDeleting} className="self-end">
Cancel
</Button>
<Button
variant="primary"
icon={<RefreshCwIcon />}
onClick={onReverifyCustomDomain}
loading={!isValidating && isReverifyLoading}
disabled={isDeleting || isReverifyLoading || isValidating}
className="self-end"
>
Verify
</Button>
</div>
</div>
</Panel.Content>
</>
)
}