diff --git a/.agents/skills/telemetry-standards/SKILL.md b/.agents/skills/telemetry-standards/SKILL.md index 907787d7a3e..db883a13fd9 100644 --- a/.agents/skills/telemetry-standards/SKILL.md +++ b/.agents/skills/telemetry-standards/SKILL.md @@ -134,6 +134,8 @@ Telemetry only runs for visitors who accepted analytics. Consent does not make i ## Required Pattern +**Never use `data-attr` (or any other `data-*` attribute) to send PostHog events.** Track every event with an explicit `track()` call from `useTrack`, defined in `packages/common/telemetry-constants.ts`. PostHog autocapture is off (`autocapture: false` in `packages/common/posthog-client.ts`), so a `data-attr` sends nothing, and it bypasses event typing and the review rules in this skill. A click you want measured gets a `track()` call. Don't add new `data-attr` attributes, and replace existing ones with `track()` when touching that code. Any that remain must keep a static string value, never built from user-defined names, in case autocapture is enabled later. + Import `useTrack` from `@/lib/telemetry/track` (within `apps/studio/`). ```typescript @@ -156,7 +158,6 @@ const MyComponent = () => { Where the `track()` call goes: -- **`data-attr` is not tracking.** PostHog autocapture is off (`autocapture: false` in `packages/common/posthog-client.ts`), so the attribute sends nothing. A click you want measured gets a `track()` call. Keep any `data-attr` value a static string, never built from user-defined names, in case autocapture is enabled later. - **Mutation outcomes.** Don't track in the callbacks passed as the second argument to `mutate()` (`onSuccess`, `onError`): they are skipped if the component unmounts first. Track around `await mutateAsync()` (after it for success, in a `catch` for failure), or in the callbacks passed to the mutation hook itself (`useXMutation({ onSuccess, onError })`) when the hook always calls them: some return early, on a 202 for example. The selected project can change before the response arrives, so attribute the event to the mutation's own project or org (from its variables, or from the response for a create) with the third `track()` argument, for example `{ project: variables.projectRef }`. - **One meaning per event.** When one event name fires from several places, every call site fires on the same kind of user action, so the counts are comparable. Don't mix a `copy` event handler on a DOM element, which also fires on keyboard and partial-selection copies, with a Copy button's click callback under one event name: track the same action in both, or add a property that tells them apart. - **Submitted values.** Capture what the user submitted at submit time, not in the success callback. A form can stay editable while the request is in flight, so reading it on success can report a value that was not the one sent. @@ -230,7 +231,7 @@ When reviewing a PR, flag a break of any of these as a **required change**, even 5. **Feature flags and experiment exposure**: [Feature Flag Measurement](#feature-flag-measurement) 6. **User-defined names or identifiers in properties**: [Privacy: User-Defined Names and Identifiers](#privacy-user-defined-names-and-identifiers) 7. **Secrets, project content, URL state or consent**: [Privacy: Secrets, Project Content and URL State](#privacy-secrets-project-content-and-url-state) and [Consent and Transport](#consent-and-transport) -8. **Tracking placement**: the placement rules under [Required Pattern](#required-pattern) +8. **Tracking placement**: the placement rules under [Required Pattern](#required-pattern), including no new `data-attr` or other `data-*` attribute used for tracking 9. **Org-level events**: a project-scoped event reused on an organization-level page ([Event Definitions](#event-definitions)) When a PR adds user-facing interactions (buttons, forms, toggles, modals) **without** tracking, suggest: diff --git a/apps/studio/components/interfaces/Project/ResumeProjectButton.tsx b/apps/studio/components/interfaces/Project/ResumeProjectButton.tsx index ea8500627cd..e61c3f44fed 100644 --- a/apps/studio/components/interfaces/Project/ResumeProjectButton.tsx +++ b/apps/studio/components/interfaces/Project/ResumeProjectButton.tsx @@ -36,6 +36,7 @@ import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useChe import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { PROJECT_STATUS } from '@/lib/constants' +import { useTrack } from '@/lib/telemetry/track' const FormSchema = z.object({ postgresVersionSelection: z.string(), @@ -46,6 +47,8 @@ type ResumeProjectButtonProps = Pick< 'className' | 'size' | 'variant' > & { label?: string + /** Where the button is rendered, sent with the resume telemetry event */ + source: 'settings_general' | 'project_layout_paused' } export const ResumeProjectButton = ({ @@ -53,8 +56,10 @@ export const ResumeProjectButton = ({ label = 'Resume project', size, variant = 'default', + source, }: ResumeProjectButtonProps) => { const router = useRouter() + const track = useTrack() const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const { data: selectedOrganization } = useSelectedOrganizationQuery() @@ -140,6 +145,8 @@ export const ResumeProjectButton = ({ return toast.error('Unable to restore: project is required') } + track('project_lifecycle_action_submitted', { action: 'resume', source }) + if (!newProjectInternalOnlyConfiguration) { return restoreProject({ ref: project.ref }) } diff --git a/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx b/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx index e43225b0e30..5d1882954f4 100644 --- a/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx +++ b/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx @@ -19,9 +19,11 @@ import { useComplianceConfigUpdateMutation } from '@/data/config/project-complia import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { DOCS_URL } from '@/lib/constants' +import { useTrack } from '@/lib/telemetry/track' export const ComplianceConfig = () => { const { ref } = useParams() + const track = useTrack() const isIssuesInboxEnabled = useFlag('issuesInbox') const [isSensitive, setIsSensitive] = useState(false) @@ -40,7 +42,8 @@ export const ComplianceConfig = () => { const { mutate: updateComplianceConfig, isPending: isSubmitting } = useComplianceConfigUpdateMutation({ - onSuccess: () => { + onSuccess: (_data, vars) => { + track('project_compliance_mode_updated', { isSensitive: vars.isSensitive }) toast.success('Successfully updated project compliance configuration') }, onError: (error) => { diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx index b745c25160c..f5922d58783 100644 --- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx +++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx @@ -12,6 +12,7 @@ import { useCustomDomainActivateMutation } from '@/data/custom-domains/custom-do import { useCustomDomainDeleteMutation } from '@/data/custom-domains/custom-domains-delete-mutation' import type { CustomDomainResponse } from '@/data/custom-domains/custom-domains-query' import { DOCS_URL } from '@/lib/constants' +import { useTrack } from '@/lib/telemetry/track' export type CustomDomainActivateProps = { projectRef?: string @@ -19,6 +20,7 @@ export type CustomDomainActivateProps = { } export const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivateProps) => { + const track = useTrack() const [isActivateConfirmModalVisible, setIsActivateConfirmModalVisible] = useState(false) const { data: settings } = useProjectSettingsV2Query({ projectRef }) @@ -43,6 +45,7 @@ export const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainA const onActivateCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') + track('custom_domain_step_submitted', { step: 'activate' }) checkCNAMERecord( { domain: customDomain.hostname }, { onSuccess: () => activateCustomDomain({ projectRef }) } diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx index 8e6b2cffab2..bcc9170276a 100644 --- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx +++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx @@ -10,6 +10,7 @@ import Panel from '@/components/ui/Panel' import { useCustomDomainDeleteMutation } from '@/data/custom-domains/custom-domains-delete-mutation' import type { CustomDomainResponse } from '@/data/custom-domains/custom-domains-query' import { DOCS_URL } from '@/lib/constants' +import { useTrack } from '@/lib/telemetry/track' export type CustomDomainDeleteProps = { projectRef?: string @@ -17,6 +18,7 @@ export type CustomDomainDeleteProps = { } export const CustomDomainDelete = ({ projectRef, customDomain }: CustomDomainDeleteProps) => { + const track = useTrack() const [removeCustomDomain, setRemoveCustomDomain] = useState(false) const [isDeleteConfirmModalVisible, setIsDeleteConfirmModalVisible] = useState(false) @@ -32,6 +34,7 @@ export const CustomDomainDelete = ({ projectRef, customDomain }: CustomDomainDel const onDeleteCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') + track('custom_domain_step_submitted', { step: 'remove' }) deleteCustomDomain({ projectRef, removeAddon: removeCustomDomain }) } diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx index 5ce18c3761b..4db35cb6e3a 100644 --- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx +++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx @@ -15,9 +15,11 @@ import { useCustomDomainDeleteMutation } from '@/data/custom-domains/custom-doma 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 }) @@ -64,6 +66,7 @@ export const CustomDomainVerify = () => { const onReverifyCustomDomain = () => { if (!projectRef) return console.error('Project ref is required') + track('custom_domain_step_submitted', { step: 'verify' }) refetchReverify() } diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx index 761b7bf8652..2342a6a2e36 100644 --- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx +++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx @@ -23,6 +23,7 @@ import { useCheckCNAMERecordMutation } from '@/data/custom-domains/check-cname-m 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'), @@ -30,6 +31,7 @@ const schema = z.object({ export const CustomDomainsConfigureHostname = () => { const { ref } = useParams() + const track = useTrack() const { mutate: checkCNAMERecord, isPending: isCheckingRecord } = useCheckCNAMERecordMutation() const { mutate: createCustomDomain, isPending: isCreating } = useCustomDomainCreateMutation() @@ -52,6 +54,7 @@ export const CustomDomainsConfigureHostname = () => { const onCreateCustomDomain = async (values: z.infer) => { if (!ref) return console.error('Project ref is required') + track('custom_domain_step_submitted', { step: 'configure' }) checkCNAMERecord( { domain: values.domain.trim() }, { diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/DNSRecord.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/DNSRecord.tsx index 15eddc03696..ca68fbf8346 100644 --- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/DNSRecord.tsx +++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/DNSRecord.tsx @@ -1,20 +1,40 @@ import { Input } from 'ui-patterns/DataInputs/Input' +import { useTrack } from '@/lib/telemetry/track' + export type DNSRecordProps = { - type: string + type: 'CNAME' | 'TXT' name: string value: string } export const DNSRecord = ({ type, name, value }: DNSRecordProps) => { + const track = useTrack() + return (

{type.toUpperCase()}

- - + track('custom_domain_dns_record_copied', { recordType: type, field: 'name' })} + /> + + track('custom_domain_dns_record_copied', { recordType: type, field: 'value' }) + } + />
) } diff --git a/apps/studio/components/interfaces/Settings/General/General.tsx b/apps/studio/components/interfaces/Settings/General/General.tsx index e57fe105ff3..0d0438bd365 100644 --- a/apps/studio/components/interfaces/Settings/General/General.tsx +++ b/apps/studio/components/interfaces/Settings/General/General.tsx @@ -28,9 +28,11 @@ import { useDeploymentMode } from '@/hooks/misc/useDeploymentMode' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { DOCS_URL } from '@/lib/constants' import { useGrant } from '@/lib/grants' +import { useTrack } from '@/lib/telemetry/track' export const General = () => { const { ref } = useParams() + const track = useTrack() const { data: project } = useSelectedProjectQuery() const isBranch = Boolean(project?.parent_project_ref) const entityLabel = isBranch ? 'Branch' : 'Project' @@ -77,12 +79,14 @@ export const General = () => { const onSubmit = async (values: z.infer) => { if (!project?.ref) return console.error('Ref is required') + if (values.name.trim() === projectName) return updateProject( { ref: project.ref, name: values.name.trim() }, { onSuccess: ({ name }) => { form.reset({ name }) + track('project_name_updated') toast.success('Successfully saved settings') }, } @@ -227,7 +231,15 @@ export const General = () => { className="[&>div]:md:w-1/2 [&>div>div]:md:w-full" > - + + track('project_settings_value_copied', { field: 'projectRef' }) + } + /> @@ -240,7 +252,13 @@ export const General = () => { className="[&>div]:md:w-1/2 [&>div>div]:md:w-full" > - + track('project_settings_value_copied', { field: 'region' })} + /> diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx index 7960413efce..72bf042db97 100644 --- a/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx +++ b/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx @@ -25,9 +25,11 @@ import { useSelectedProjectQuery, } from '@/hooks/misc/useSelectedProject' import { PROJECT_STATUS } from '@/lib/constants' +import { useTrack } from '@/lib/telemetry/track' export const PauseProjectButton = () => { const router = useRouter() + const track = useTrack() const { data: project } = useSelectedProjectQuery() const { data: organization } = useSelectedOrganizationQuery() const { setProjectStatus } = useSetProjectStatus() @@ -61,6 +63,7 @@ export const PauseProjectButton = () => { if (!canPauseProject) { return toast.error(`You do not have the required permissions to pause this ${entityLabel}`) } + track('project_lifecycle_action_submitted', { action: 'pause', source: 'settings_general' }) pauseProject({ ref: projectRef }) } diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx index 5556afb87db..8d0f4b842c8 100644 --- a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx +++ b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx @@ -22,9 +22,11 @@ import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { useIsProjectActive, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { PROJECT_STATUS } from '@/lib/constants' import type { StudioError } from '@/lib/errors/studio-errors' +import { useTrack } from '@/lib/telemetry/track' export const RestartServerButton = () => { const router = useRouter() + const track = useTrack() const { data: project } = useSelectedProjectQuery() const isProjectActive = useIsProjectActive() @@ -73,6 +75,10 @@ export const RestartServerButton = () => { if (!canRestartProject) { return toast.error('You do not have the required permissions to restart this project') } + track('project_lifecycle_action_submitted', { + action: 'restart_project', + source: 'settings_general', + }) restartProject({ ref: projectRef }) } @@ -80,6 +86,10 @@ export const RestartServerButton = () => { if (!canRestartProject) { return toast.error('You do not have the required permissions to restart this project') } + track('project_lifecycle_action_submitted', { + action: 'restart_database', + source: 'settings_general', + }) restartProjectServices({ ref: projectRef, region: projectRegion, services: ['postgresql'] }) } diff --git a/apps/studio/components/interfaces/Settings/General/Project.tsx b/apps/studio/components/interfaces/Settings/General/Project.tsx index 5130ba399ab..eaf95dac719 100644 --- a/apps/studio/components/interfaces/Settings/General/Project.tsx +++ b/apps/studio/components/interfaces/Settings/General/Project.tsx @@ -81,7 +81,7 @@ export const Project = () => { View project dashboard ) : ( - + ) ) : ( diff --git a/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx b/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx index 7f4a34604db..2c3e69b5c75 100644 --- a/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx +++ b/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx @@ -107,6 +107,7 @@ export const TransferProjectButton = () => { async function handleTransferProject() { if (project === undefined) return if (selectedOrg === undefined) return + track('project_lifecycle_action_submitted', { action: 'transfer', source: 'settings_general' }) transferProject({ projectRef, targetOrganizationSlug: selectedOrg }) } diff --git a/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx b/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx index 141cb54358f..4445bb79144 100644 --- a/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx +++ b/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx @@ -142,7 +142,7 @@ export const ProjectPausedState = ({ product }: ProjectPausedStateProps) => { {isPauseStatusSuccess && !isRestoreDisabled && ( <> - + {isFreePlan ? ( diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts index 32f3ceeeb10..960b0ac0165 100644 --- a/packages/common/telemetry-constants.ts +++ b/packages/common/telemetry-constants.ts @@ -2867,6 +2867,119 @@ export interface BranchDeleteButtonClickedEvent { groups: TelemetryGroups } +/** + * Triggered when a user saves a new project name in project settings. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general + */ +export interface ProjectNameUpdatedEvent { + action: 'project_name_updated' + groups: TelemetryGroups +} + +/** + * Triggered when a user copies the project ID or region from project settings. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general + */ +export interface ProjectSettingsValueCopiedEvent { + action: 'project_settings_value_copied' + properties: { + /** + * The field that was copied + */ + field: 'projectRef' | 'region' + } + groups: TelemetryGroups +} + +/** + * Triggered when a user confirms a project lifecycle action: a full project restart, a fast + * database reboot, a pause, a resume, or a transfer to another organization. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general or /dashboard/project/{ref} (resume from the paused project state) + */ +export interface ProjectLifecycleActionSubmittedEvent { + action: 'project_lifecycle_action_submitted' + properties: { + /** + * The lifecycle action the user confirmed + */ + action: 'restart_project' | 'restart_database' | 'pause' | 'resume' | 'transfer' + /** + * Where the action was confirmed from + */ + source: 'settings_general' | 'project_layout_paused' + } + groups: TelemetryGroups +} + +/** + * Triggered when a user toggles the high compliance (sensitive data) mode of a project. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general + */ +export interface ProjectComplianceModeUpdatedEvent { + action: 'project_compliance_mode_updated' + properties: { + /** + * Whether the project is marked as storing sensitive data after the toggle + */ + isSensitive: boolean + } + groups: TelemetryGroups +} + +/** + * Triggered when a user submits a step of the custom domain flow: adding the hostname, + * verifying its DNS records, activating it, or deleting the active custom domain. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general + */ +export interface CustomDomainStepSubmittedEvent { + action: 'custom_domain_step_submitted' + properties: { + /** + * The step of the custom domain flow that was submitted + */ + step: 'configure' | 'verify' | 'activate' | 'remove' + } + groups: TelemetryGroups +} + +/** + * Triggered when a user copies the name or value of a DNS record shown in the custom domain + * verification step. + * + * @group Events + * @source studio + * @page /dashboard/project/{ref}/settings/general + */ +export interface CustomDomainDnsRecordCopiedEvent { + action: 'custom_domain_dns_record_copied' + properties: { + /** + * The type of DNS record that was copied + */ + recordType: 'CNAME' | 'TXT' + /** + * Whether the record name or the record value was copied + */ + field: 'name' | 'value' + } + groups: TelemetryGroups +} + /** * Triggered when a create merge request is clicked for a branch. * @@ -5342,6 +5455,12 @@ export type TelemetryEvent = | StorageBucketLifecycleRuleRemovedEvent | BranchCreateButtonClickedEvent | BranchDeleteButtonClickedEvent + | ProjectNameUpdatedEvent + | ProjectSettingsValueCopiedEvent + | ProjectLifecycleActionSubmittedEvent + | ProjectComplianceModeUpdatedEvent + | CustomDomainStepSubmittedEvent + | CustomDomainDnsRecordCopiedEvent | BranchCreateMergeRequestButtonClickedEvent | BranchCloseMergeRequestButtonClickedEvent | BranchMergeSubmittedEvent