diff --git a/packages/sanity/src/core/create/__telemetry__/create.telemetry.ts b/packages/sanity/src/core/create/__telemetry__/create.telemetry.ts new file mode 100644 index 000000000000..8d2473db31e4 --- /dev/null +++ b/packages/sanity/src/core/create/__telemetry__/create.telemetry.ts @@ -0,0 +1,32 @@ +import {defineEvent} from '@sanity/telemetry' + +export const StartInCreateClicked = defineEvent({ + name: 'Start in Create clicked', + version: 1, + description: 'The "Start in Sanity Create" button is clicked.', +}) + +export const StartInCreateAccepted = defineEvent({ + name: 'Start in Create accepted', + version: 1, + description: + 'Continue in the "Start in Sanity Create" dialog was pressed, or auto-confirm was enabled.', +}) + +export const CreateUnlinkClicked = defineEvent({ + name: 'Create Unlink clicked', + version: 1, + description: 'The Unlink action was clicked', +}) + +export const CreateUnlinkAccepted = defineEvent({ + name: 'Create Unlink accepted', + version: 1, + description: 'User confirmed that they want the Studio document unlinked', +}) + +export const EditInCreateClicked = defineEvent({ + name: 'Edit in Create clicked', + version: 1, + description: 'User clicked "Edit in Create"', +}) diff --git a/packages/sanity/src/core/create/components/CreateLinkedActions.tsx b/packages/sanity/src/core/create/components/CreateLinkedActions.tsx index 4f8b5836b6a9..323058dc7c2e 100644 --- a/packages/sanity/src/core/create/components/CreateLinkedActions.tsx +++ b/packages/sanity/src/core/create/components/CreateLinkedActions.tsx @@ -7,6 +7,7 @@ import {useTranslation} from '../../i18n' import {createLocaleNamespace} from '../i18n' import {type CreateLinkedActionsProps} from '../types' import {useCreateDocumentUrl} from '../useCreateDocumentUrl' +import {useSanityCreateTelemetry} from '../useSanityCreateTelemetry' import {CreateUnlinkConfirmDialog} from './CreateUnlinkConfirmDialog' export function CreateLinkedActions(props: CreateLinkedActionsProps) { @@ -14,9 +15,17 @@ export function CreateLinkedActions(props: CreateLinkedActionsProps) { const {t} = useTranslation(createLocaleNamespace) const href = useCreateDocumentUrl(metadata) + const telemetry = useSanityCreateTelemetry() + + const onEditInCreateClicked = useCallback(() => telemetry.editInCreateClicked(), [telemetry]) + const [unlinkConfirm, setUnlinkConfirm] = useState(false) - const confirmUnlink = useCallback(() => setUnlinkConfirm(true), []) + const confirmUnlink = useCallback(() => { + setUnlinkConfirm(true) + telemetry.unlinkClicked() + }, [telemetry]) + const cancelUnlink = useCallback(() => setUnlinkConfirm(false), []) return ( @@ -27,6 +36,7 @@ export function CreateLinkedActions(props: CreateLinkedActionsProps) { mode="ghost" paddingY={3} href={href} + onClick={onEditInCreateClicked} />