From 70410267a48a1532963c683310cfacfefcce6533 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Tue, 3 Sep 2024 14:01:46 +0200 Subject: [PATCH] feat(sanity): add telemetry when creating a draft --- .../structure/panes/document/DocumentPaneProvider.tsx | 6 +++++- .../document/__telemetry__/documentPanes.telemetry.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx index c097d2c9408a..43271f54042e 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx @@ -48,7 +48,7 @@ import {usePaneRouter} from '../../components' import {structureLocaleNamespace} from '../../i18n' import {type PaneMenuItem} from '../../types' import {useStructureTool} from '../../useStructureTool' -import {DocumentURLCopied} from './__telemetry__' +import {CreatedDraft, DocumentURLCopied} from './__telemetry__' import { DEFAULT_MENU_ITEM_GROUPS, EMPTY_PARAMS, @@ -294,6 +294,10 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { }) patchRef.current = (event: PatchEvent) => { + // when creating a new draft + if (!editState.draft && !editState.version && !editState.published) { + telemetry.log(CreatedDraft) + } patch.execute(toMutationPatches(event.patches), initialValue.value) } diff --git a/packages/sanity/src/structure/panes/document/__telemetry__/documentPanes.telemetry.ts b/packages/sanity/src/structure/panes/document/__telemetry__/documentPanes.telemetry.ts index b2b83cc66c1d..5718de4f4041 100644 --- a/packages/sanity/src/structure/panes/document/__telemetry__/documentPanes.telemetry.ts +++ b/packages/sanity/src/structure/panes/document/__telemetry__/documentPanes.telemetry.ts @@ -8,3 +8,13 @@ export const DocumentURLCopied = defineEvent({ version: 1, description: 'User copied document URL to clipboard', }) + +/** + * When a draft is successfully created + * @internal + */ +export const CreatedDraft = defineEvent({ + name: 'Create a new draft', + version: 1, + description: 'User created a new draft', +})