From 4fda38573af7c4b2a210f3b100bd80e063825a24 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 10:17:07 +0200 Subject: [PATCH 01/14] fix(sanity): issue where the createVersionSuccess was never resolving --- .../sanity/src/core/bundles/components/panes/BundleActions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx index 871eab3056f..6fe60f8f3db 100644 --- a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx +++ b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx @@ -67,7 +67,7 @@ export function BundleActions(props: BundleActionsProps): ReactNode { // set up the listener before executing const createVersionSuccess = firstValueFrom( documentStore.pair - .operationEvents(versionId, documentType) + .operationEvents(getPublishedId(bundleId), documentType) .pipe(filter((e) => e.op === 'newVersion' && e.type === 'success')), ) From 6c67887fa05e5e26ce0ffa666a67657bd1669e3a Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 10:18:54 +0200 Subject: [PATCH 02/14] feat(sanity): add telemetry when adding version --- .../__telemetry__/bundles.telemetry.ts | 23 +++++++++++++++++++ .../components/panes/BundleActions.tsx | 23 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts diff --git a/packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts new file mode 100644 index 00000000000..8305203dfcb --- /dev/null +++ b/packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts @@ -0,0 +1,23 @@ +import {defineEvent} from '@sanity/telemetry' + +interface VersionInfo { + /** + * document type that was added + */ + schemaType: string + + /** + * the origin of the version created (from a draft or from a version) + */ + documentOrigin: 'draft' | 'version' +} + +/** + * When a document (version) is successfully added to a release + * @internal + */ +export const AddedVersion = defineEvent({ + name: 'Add version of document to release', + version: 1, + description: 'User added a document to a release', +}) diff --git a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx index 6fe60f8f3db..e2d1d6a6b08 100644 --- a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx +++ b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx @@ -1,4 +1,5 @@ import {AddIcon, CheckmarkIcon} from '@sanity/icons' +import {useTelemetry} from '@sanity/telemetry/react' import {useToast} from '@sanity/ui' import {type ReactNode, useCallback, useState} from 'react' import {filter, firstValueFrom} from 'rxjs' @@ -6,6 +7,7 @@ import { getPublishedId, getVersionFromId, getVersionId, + isVersionId, useDocumentOperation, useDocumentStore, useTranslation, @@ -13,6 +15,7 @@ import { import {Button} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' +import {AddedVersion} from '../../__telemetry__/bundles.telemetry' interface BundleActionsProps { currentGlobalBundle: BundleDocument @@ -42,6 +45,7 @@ export function BundleActions(props: BundleActionsProps): ReactNode { const toast = useToast() const {newVersion} = useDocumentOperation(publishedId, documentType, bundleId) const {t} = useTranslation() + const telemetry = useTelemetry() const handleAddVersion = useCallback(async () => { if (!documentId) { @@ -67,7 +71,7 @@ export function BundleActions(props: BundleActionsProps): ReactNode { // set up the listener before executing const createVersionSuccess = firstValueFrom( documentStore.pair - .operationEvents(getPublishedId(bundleId), documentType) + .operationEvents(getPublishedId(documentId), documentType) .pipe(filter((e) => e.op === 'newVersion' && e.type === 'success')), ) @@ -76,7 +80,22 @@ export function BundleActions(props: BundleActionsProps): ReactNode { // only change if the version was created successfully await createVersionSuccess setIsInVersion(true) - }, [documentId, globalBundleId, documentStore.pair, documentType, newVersion, toast, title]) + + telemetry.log(AddedVersion, { + schemaType: documentType, + documentOrigin: isVersionId(documentId) ? 'version' : 'draft', + }) + }, [ + documentId, + globalBundleId, + documentStore.pair, + bundleId, + documentType, + newVersion, + telemetry, + toast, + title, + ]) /** TODO what should happen when you add a version if we don't have the ready button */ From 4fe49b4ba7021aba42d7970e35b63d8119292005 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 10:30:52 +0200 Subject: [PATCH 03/14] refactor(sanity): rename bundles to releases telemetry --- .../{bundles.telemetry.ts => releases.telemetry.ts} | 0 .../sanity/src/core/bundles/components/panes/BundleActions.tsx | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/sanity/src/core/bundles/__telemetry__/{bundles.telemetry.ts => releases.telemetry.ts} (100%) diff --git a/packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts similarity index 100% rename from packages/sanity/src/core/bundles/__telemetry__/bundles.telemetry.ts rename to packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts diff --git a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx index e2d1d6a6b08..33c304476a9 100644 --- a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx +++ b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx @@ -15,7 +15,7 @@ import { import {Button} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' -import {AddedVersion} from '../../__telemetry__/bundles.telemetry' +import {AddedVersion} from '../../__telemetry__/releases.telemetry' interface BundleActionsProps { currentGlobalBundle: BundleDocument From 40d5be617bab7486bbdeee2e90a256ea4a56ed0a Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 11:18:44 +0200 Subject: [PATCH 04/14] feat(sanity): add telemetry when creating release --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 9 +++++++++ .../bundles/components/dialog/BundleDetailsDialog.tsx | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index 8305203dfcb..27e72245f1d 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -21,3 +21,12 @@ export const AddedVersion = defineEvent({ version: 1, description: 'User added a document to a release', }) + +/** When a release is successfully created + * @internal + */ +export const CreatedRelease = defineEvent({ + name: 'Create release', + version: 1, + description: 'User created a release', +}) diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx index 8a350dca91f..3936c9ecc75 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx @@ -1,4 +1,5 @@ import {ArrowRightIcon} from '@sanity/icons' +import {useTelemetry} from '@sanity/telemetry/react' import {Box, Flex, useToast} from '@sanity/ui' import {type FormEvent, useCallback, useState} from 'react' import {type FormBundleDocument, useTranslation} from 'sanity' @@ -6,6 +7,7 @@ import {type FormBundleDocument, useTranslation} from 'sanity' import {Button, Dialog} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' import {useBundleOperations} from '../../../store/bundles/useBundleOperations' +import {CreatedRelease} from '../../__telemetry__/releases.telemetry' import {usePerspective} from '../../hooks/usePerspective' import {createReleaseId} from '../../util/createReleaseId' import {BundleForm} from './BundleForm' @@ -22,6 +24,7 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen const {createBundle, updateBundle} = useBundleOperations() const formAction = bundle ? 'edit' : 'create' const {t} = useTranslation() + const telemetry = useTelemetry() const [value, setValue] = useState((): FormBundleDocument => { return { @@ -56,6 +59,7 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen await submit(submitValue) if (formAction === 'create') { setPerspective(value._id) + telemetry.log(CreatedRelease) } } catch (err) { console.error(err) @@ -69,7 +73,7 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen onSubmit() } }, - [value, submit, formAction, setPerspective, toast, onSubmit], + [value, submit, formAction, setPerspective, telemetry, toast, onSubmit], ) const handleOnChange = useCallback((changedValue: FormBundleDocument) => { From e93f38dbabfd9176fa3505b99eef5a517159777e Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 11:22:50 +0200 Subject: [PATCH 05/14] feat(sanity): add telemetry when updating release --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 9 +++++++++ .../bundles/components/dialog/BundleDetailsDialog.tsx | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index 27e72245f1d..a1a1bf340fa 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -30,3 +30,12 @@ export const CreatedRelease = defineEvent({ version: 1, description: 'User created a release', }) + +/** When a release is successfully updated + * @internal + */ +export const UpdatedRelease = defineEvent({ + name: 'Update release', + version: 1, + description: 'User updated a release', +}) diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx index 3936c9ecc75..3d63b09aef8 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx @@ -7,7 +7,7 @@ import {type FormBundleDocument, useTranslation} from 'sanity' import {Button, Dialog} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' import {useBundleOperations} from '../../../store/bundles/useBundleOperations' -import {CreatedRelease} from '../../__telemetry__/releases.telemetry' +import {CreatedRelease, UpdatedRelease} from '../../__telemetry__/releases.telemetry' import {usePerspective} from '../../hooks/usePerspective' import {createReleaseId} from '../../util/createReleaseId' import {BundleForm} from './BundleForm' @@ -60,6 +60,8 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen if (formAction === 'create') { setPerspective(value._id) telemetry.log(CreatedRelease) + } else { + telemetry.log(UpdatedRelease) } } catch (err) { console.error(err) From 4484c1bf9e6b6236e423d47deca62f8aab6d11d9 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 11:28:08 +0200 Subject: [PATCH 06/14] feat(sanity): add telemetry when deleting release --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 9 +++++++++ .../components/BundleMenuButton/BundleMenuButton.tsx | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index a1a1bf340fa..b90105c5b21 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -39,3 +39,12 @@ export const UpdatedRelease = defineEvent({ version: 1, description: 'User updated a release', }) + +/** When a release is successfully deleted + * @internal + */ +export const DeletedRelease = defineEvent({ + name: 'Delete release', + version: 1, + description: 'User deleted a release', +}) diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx index 686c9af5912..81c453fab9b 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx @@ -5,11 +5,13 @@ import { TrashIcon, UnarchiveIcon, } from '@sanity/icons' +import {useTelemetry} from '@sanity/telemetry/react' import {Menu, Spinner, Text, useToast} from '@sanity/ui' import {useState} from 'react' import {useRouter} from 'sanity/router' import {Button, Dialog, MenuButton, MenuItem} from '../../../../ui-components' +import {DeletedRelease} from '../../../bundles/__telemetry__/releases.telemetry' import {BundleDetailsDialog} from '../../../bundles/components/dialog/BundleDetailsDialog' import {Translate, useTranslation} from '../../../i18n' import {type BundleDocument} from '../../../store/bundles/types' @@ -33,6 +35,7 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu const bundleMenuDisabled = !bundle || disabled const toast = useToast() const {t} = useTranslation(releasesLocaleNamespace) + const telemetry = useTelemetry() const resetSelectedAction = () => setSelectedAction(undefined) @@ -41,6 +44,7 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu try { setDiscardStatus('discarding') await deleteBundle(bundle) + telemetry.log(DeletedRelease) toast.push({ closable: true, status: 'success', From 7994a5abc2d08965d21b638ebf8fa5b77b8fe211 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 12:46:44 +0200 Subject: [PATCH 07/14] feat(sanity): add telemetry when publishing release --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 9 +++++++++ .../ReleasePublishAllButton/ReleasePublishAllButton.tsx | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index b90105c5b21..0dee4f44ea7 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -48,3 +48,12 @@ export const DeletedRelease = defineEvent({ version: 1, description: 'User deleted a release', }) + +/** When a release is successfully published + * @internal + */ +export const PublishedRelease = defineEvent({ + name: 'Publish release', + version: 1, + description: 'User published a release', +}) diff --git a/packages/sanity/src/core/releases/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx b/packages/sanity/src/core/releases/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx index 2f37aebf6bb..b9f65f16c2f 100644 --- a/packages/sanity/src/core/releases/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx +++ b/packages/sanity/src/core/releases/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx @@ -1,9 +1,11 @@ import {ErrorOutlineIcon, PublishIcon} from '@sanity/icons' +import {useTelemetry} from '@sanity/telemetry/react' import {Flex, Text, useToast} from '@sanity/ui' import {useCallback, useMemo, useState} from 'react' import {type BundleDocument} from 'sanity' import {Button, Dialog} from '../../../../ui-components' +import {PublishedRelease} from '../../../bundles/__telemetry__/releases.telemetry' import {Translate, useTranslation} from '../../../i18n' import {useBundleOperations} from '../../../store/bundles/useBundleOperations' import {releasesLocaleNamespace} from '../../i18n' @@ -24,6 +26,7 @@ export const ReleasePublishAllButton = ({ const toast = useToast() const {publishBundle} = useBundleOperations() const {t} = useTranslation(releasesLocaleNamespace) + const telemetry = useTelemetry() const [publishBundleStatus, setPublishBundleStatus] = useState<'idle' | 'confirm' | 'publishing'>( 'idle', ) @@ -47,6 +50,7 @@ export const ReleasePublishAllButton = ({ bundleDocuments.map(({document}) => document), publishedDocumentsRevisions, ) + telemetry.log(PublishedRelease) toast.push({ closable: true, status: 'success', @@ -69,7 +73,7 @@ export const ReleasePublishAllButton = ({ } finally { setPublishBundleStatus('idle') } - }, [bundle, bundleDocuments, publishBundle, publishedDocumentsRevisions, t, toast]) + }, [bundle, bundleDocuments, publishBundle, publishedDocumentsRevisions, t, telemetry, toast]) const confirmPublishDialog = useMemo(() => { if (publishBundleStatus === 'idle') return null From 76e9db98134d718e74c9a81166a1d5247bdb2700 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 29 Aug 2024 12:47:05 +0200 Subject: [PATCH 08/14] feat(sanity): add telemetry when archive and unarchive release --- .../__telemetry__/releases.telemetry.ts | 18 ++++++++++++++++++ .../BundleMenuButton/BundleMenuButton.tsx | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index 0dee4f44ea7..acdce6062b8 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -57,3 +57,21 @@ export const PublishedRelease = defineEvent({ version: 1, description: 'User published a release', }) + +/** When a release is successfully archived + * @internal + */ +export const ArchivedRelease = defineEvent({ + name: 'Archive release', + version: 1, + description: 'User archived a release', +}) + +/** When a release is successfully unarchived + * @internal + */ +export const UnarchivedRelease = defineEvent({ + name: 'Unarchive release', + version: 1, + description: 'User unarchived a release', +}) diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx index 81c453fab9b..67301f5776b 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx @@ -11,7 +11,11 @@ import {useState} from 'react' import {useRouter} from 'sanity/router' import {Button, Dialog, MenuButton, MenuItem} from '../../../../ui-components' -import {DeletedRelease} from '../../../bundles/__telemetry__/releases.telemetry' +import { + ArchivedRelease, + DeletedRelease, + UnarchivedRelease, +} from '../../../bundles/__telemetry__/releases.telemetry' import {BundleDetailsDialog} from '../../../bundles/components/dialog/BundleDetailsDialog' import {Translate, useTranslation} from '../../../i18n' import {type BundleDocument} from '../../../store/bundles/types' @@ -78,6 +82,12 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu ...bundle, archivedAt: isBundleArchived ? undefined : new Date().toISOString(), }) + + if (isBundleArchived) { + telemetry.log(UnarchivedRelease) + } else { + telemetry.log(ArchivedRelease) + } setIsPerformingOperation(false) } From 96403771a5229aee2fd071d62dd063fe55445beb Mon Sep 17 00:00:00 2001 From: RitaDias Date: Fri, 30 Aug 2024 11:22:19 +0200 Subject: [PATCH 09/14] chore(sanity): fix dependencies --- .../sanity/src/core/bundles/components/panes/BundleActions.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx index 33c304476a9..280d77feb29 100644 --- a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx +++ b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx @@ -89,7 +89,6 @@ export function BundleActions(props: BundleActionsProps): ReactNode { documentId, globalBundleId, documentStore.pair, - bundleId, documentType, newVersion, telemetry, From a4374e72594121a61331bac7c714976c0db95dda Mon Sep 17 00:00:00 2001 From: RitaDias Date: Tue, 3 Sep 2024 14:01:46 +0200 Subject: [PATCH 10/14] 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 d802c201923..610b72476a0 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx @@ -50,7 +50,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, @@ -328,6 +328,10 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { }) patchRef.current = (event: PatchEvent) => { + // when creating a new draft + if (!editState.draft && !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 b2b83cc66c1..5718de4f404 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', +}) From f1bd4b6aef90b02505491f202e4cffd386761a76 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Tue, 3 Sep 2024 16:14:12 +0200 Subject: [PATCH 11/14] refactor(sanity): add telemetry for tracking drafts and include version --- .../src/structure/panes/document/DocumentPaneProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx index 610b72476a0..c00dde3adfb 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx @@ -329,7 +329,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { patchRef.current = (event: PatchEvent) => { // when creating a new draft - if (!editState.draft && !editState.published) { + if (!editState.draft && !editState.published && !editState.version) { telemetry.log(CreatedDraft) } patch.execute(toMutationPatches(event.patches), initialValue.value) From 64bf480de2bd829ba86b9e3f2b5b0f8cf6fd402e Mon Sep 17 00:00:00 2001 From: RitaDias Date: Wed, 4 Sep 2024 09:31:29 +0200 Subject: [PATCH 12/14] refactor(sanity): update telemetry request for creating release --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 9 ++++++++- .../bundles/components/dialog/BundleDetailsDialog.tsx | 7 ++++--- .../src/core/releases/tool/overview/ReleasesOverview.tsx | 1 + .../navbar/perspective/GlobalPerspectiveMenu.tsx | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index acdce6062b8..06c5ada6ca7 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -12,6 +12,13 @@ interface VersionInfo { documentOrigin: 'draft' | 'version' } +interface OriginInfo { + /** + * determines where the release was created, either from the structure view or the release plugin + */ + origin: 'structure' | 'release-plugin' +} + /** * When a document (version) is successfully added to a release * @internal @@ -25,7 +32,7 @@ export const AddedVersion = defineEvent({ /** When a release is successfully created * @internal */ -export const CreatedRelease = defineEvent({ +export const CreatedRelease = defineEvent({ name: 'Create release', version: 1, description: 'User created a release', diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx index 3d63b09aef8..2e5d2f27e8a 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx @@ -16,10 +16,11 @@ interface BundleDetailsDialogProps { onCancel: () => void onSubmit: () => void bundle?: BundleDocument + origin?: 'structure' | 'release-plugin' } export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Element { - const {onCancel, onSubmit, bundle} = props + const {onCancel, onSubmit, bundle, origin} = props const toast = useToast() const {createBundle, updateBundle} = useBundleOperations() const formAction = bundle ? 'edit' : 'create' @@ -59,7 +60,7 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen await submit(submitValue) if (formAction === 'create') { setPerspective(value._id) - telemetry.log(CreatedRelease) + telemetry.log(CreatedRelease, {origin}) } else { telemetry.log(UpdatedRelease) } @@ -75,7 +76,7 @@ export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Elemen onSubmit() } }, - [value, submit, formAction, setPerspective, telemetry, toast, onSubmit], + [value, submit, formAction, setPerspective, telemetry, origin, toast, onSubmit], ) const handleOnChange = useCallback((changedValue: FormBundleDocument) => { diff --git a/packages/sanity/src/core/releases/tool/overview/ReleasesOverview.tsx b/packages/sanity/src/core/releases/tool/overview/ReleasesOverview.tsx index 05a91d52344..670a7270190 100644 --- a/packages/sanity/src/core/releases/tool/overview/ReleasesOverview.tsx +++ b/packages/sanity/src/core/releases/tool/overview/ReleasesOverview.tsx @@ -147,6 +147,7 @@ export function ReleasesOverview() { setIsCreateBundleDialogOpen(false)} onSubmit={() => setIsCreateBundleDialogOpen(false)} + origin="release-plugin" /> ) } diff --git a/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx b/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx index 8ee36b4335b..04b1b88e138 100644 --- a/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx +++ b/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx @@ -60,7 +60,7 @@ export function GlobalPerspectiveMenu(): JSX.Element { /> {createBundleDialogOpen && ( - + )} ) From 98f2e7d7b59627cd7bf03ec0d9ed3092e24615d0 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Wed, 4 Sep 2024 13:01:18 +0200 Subject: [PATCH 13/14] refactor(sanity): reuse interface for OriginInfo --- .../src/core/bundles/__telemetry__/releases.telemetry.ts | 2 +- .../bundles/components/dialog/BundleDetailsDialog.tsx | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts index 06c5ada6ca7..35b678ed4de 100644 --- a/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts +++ b/packages/sanity/src/core/bundles/__telemetry__/releases.telemetry.ts @@ -12,7 +12,7 @@ interface VersionInfo { documentOrigin: 'draft' | 'version' } -interface OriginInfo { +export interface OriginInfo { /** * determines where the release was created, either from the structure view or the release plugin */ diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx index 2e5d2f27e8a..b80964451a5 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleDetailsDialog.tsx @@ -7,7 +7,11 @@ import {type FormBundleDocument, useTranslation} from 'sanity' import {Button, Dialog} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' import {useBundleOperations} from '../../../store/bundles/useBundleOperations' -import {CreatedRelease, UpdatedRelease} from '../../__telemetry__/releases.telemetry' +import { + CreatedRelease, + type OriginInfo, + UpdatedRelease, +} from '../../__telemetry__/releases.telemetry' import {usePerspective} from '../../hooks/usePerspective' import {createReleaseId} from '../../util/createReleaseId' import {BundleForm} from './BundleForm' @@ -16,7 +20,7 @@ interface BundleDetailsDialogProps { onCancel: () => void onSubmit: () => void bundle?: BundleDocument - origin?: 'structure' | 'release-plugin' + origin?: OriginInfo['origin'] } export function BundleDetailsDialog(props: BundleDetailsDialogProps): JSX.Element { From b3b64cf3a4827171a049ce7bf5dddb6e853d17c9 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Wed, 4 Sep 2024 13:04:17 +0200 Subject: [PATCH 14/14] docs(sanity): clarify unarchive / archive telemetry track --- .../releases/components/BundleMenuButton/BundleMenuButton.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx index 67301f5776b..be7e62eab4b 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx @@ -84,8 +84,10 @@ export const BundleMenuButton = ({disabled, bundle, documentCount}: BundleMenuBu }) if (isBundleArchived) { + // it's in the process of becoming false, so the event we want to track is unarchive telemetry.log(UnarchivedRelease) } else { + // it's in the process of becoming true, so the event we want to track is archive telemetry.log(ArchivedRelease) } setIsPerformingOperation(false)