From e2d3a71d62021f86adbe486ac65bd048cff422b5 Mon Sep 17 00:00:00 2001 From: Snorre Eskeland Brekke Date: Sun, 20 Oct 2024 15:01:22 +0200 Subject: [PATCH] chore: adds sanity create telemetry --- .../create/__telemetry__/create.telemetry.ts | 32 +++++++++++++ .../create/components/CreateLinkedActions.tsx | 12 ++++- .../components/CreateUnlinkConfirmDialog.tsx | 5 +- .../start-in-create/StartInCreateAction.tsx | 15 ++++-- .../start-in-create/StartInCreateDialog.tsx | 6 ++- .../core/create/useSanityCreateTelemetry.ts | 46 +++++++++++++++++++ 6 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 packages/sanity/src/core/create/__telemetry__/create.telemetry.ts create mode 100644 packages/sanity/src/core/create/useSanityCreateTelemetry.ts 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} />