From 7671dbba656026163f8415895eb2da2f2938711e Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Mon, 23 Sep 2024 17:32:42 +0200 Subject: [PATCH] chore(core): update studio announcements telemetry, add internal_name --- .../StudioAnnouncementsCard.tsx | 5 +- .../StudioAnnouncementsDialog.tsx | 4 +- .../StudioAnnouncementsMenuItem.tsx | 1 + .../StudioAnnouncementsProvider.tsx | 4 + .../studioAnnouncements.telemetry.ts | 1 + .../StudioAnnouncementsCard.test.tsx | 2 + .../StudioAnnouncementsDialog.test.tsx | 62 +++-- .../StudioAnnouncementsMenuItem.test.tsx | 25 +- .../StudioAnnouncementsProvider.test.tsx | 217 +++++++----------- .../core/studio/studioAnnouncements/types.ts | 1 + 10 files changed, 130 insertions(+), 192 deletions(-) diff --git a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsCard.tsx b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsCard.tsx index d2c11216b497..099f4a0dd231 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsCard.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsCard.tsx @@ -79,6 +79,7 @@ const ButtonRoot = styled.div` interface StudioAnnouncementCardProps { title: string id: string + name: string isOpen: boolean subtitle: string onCardClick: () => void @@ -93,6 +94,7 @@ export function StudioAnnouncementsCard({ title, id, isOpen, + name, subtitle, onCardClick, onCardDismiss, @@ -105,11 +107,12 @@ export function StudioAnnouncementsCard({ telemetry.log(ProductAnnouncementCardSeen, { announcement_id: id, announcement_title: title, + announcement_internal_name: name, source: 'studio', studio_version: SANITY_VERSION, }) } - }, [telemetry, id, title, isOpen]) + }, [telemetry, id, title, isOpen, name]) return ( { diff --git a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsMenuItem.tsx b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsMenuItem.tsx index 2c5b622e875a..7d8c88db581b 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsMenuItem.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsMenuItem.tsx @@ -17,6 +17,7 @@ export function StudioAnnouncementsMenuItem({text}: {text: string}) { source: 'studio', announcement_id: studioAnnouncements[0]?._id, announcement_title: studioAnnouncements[0]?.title, + announcement_internal_name: studioAnnouncements[0]?.name, studio_version: SANITY_VERSION, }) }, [onDialogOpen, studioAnnouncements, telemetry]) diff --git a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsProvider.tsx b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsProvider.tsx index 1f903ad93831..143c64640985 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsProvider.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsProvider.tsx @@ -92,6 +92,7 @@ export function StudioAnnouncementsProvider({children}: StudioAnnouncementsProvi telemetry.log(ProductAnnouncementCardDismissed, { announcement_id: unseenAnnouncements[0]?._id, announcement_title: unseenAnnouncements[0]?.title, + announcement_internal_name: unseenAnnouncements[0]?.name, source: 'studio', studio_version: SANITY_VERSION, }) @@ -102,6 +103,7 @@ export function StudioAnnouncementsProvider({children}: StudioAnnouncementsProvi telemetry.log(ProductAnnouncementCardClicked, { announcement_id: unseenAnnouncements[0]?._id, announcement_title: unseenAnnouncements[0]?.title, + announcement_internal_name: unseenAnnouncements[0]?.name, source: 'studio', studio_version: SANITY_VERSION, }) @@ -114,6 +116,7 @@ export function StudioAnnouncementsProvider({children}: StudioAnnouncementsProvi telemetry.log(ProductAnnouncementModalDismissed, { announcement_id: firstAnnouncement?._id, announcement_title: firstAnnouncement?.title, + announcement_internal_name: firstAnnouncement?.name, source: 'studio', studio_version: SANITY_VERSION, origin: dialogMode ?? 'card', @@ -139,6 +142,7 @@ export function StudioAnnouncementsProvider({children}: StudioAnnouncementsProvi { @@ -65,6 +66,7 @@ describe('StudioAnnouncementsCard', () => { expect(mockLog).toHaveBeenCalledWith(ProductAnnouncementCardSeen, { announcement_id: 'foo', announcement_title: 'New Features Available', + announcement_internal_name: 'new-features', source: 'studio', studio_version: '3.57.0', }) diff --git a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsDialog.test.tsx b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsDialog.test.tsx index 70ade9d9e4fe..b41c262b4e1c 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsDialog.test.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsDialog.test.tsx @@ -5,6 +5,10 @@ import {type ReactNode} from 'react' import {defineConfig} from 'sanity' import {createTestProvider} from '../../../../../test/testUtils/TestProvider' +import { + ProductAnnouncementLinkClicked, + ProductAnnouncementViewed, +} from '../__telemetry__/studioAnnouncements.telemetry' import {StudioAnnouncementsDialog} from '../StudioAnnouncementsDialog' import {type StudioAnnouncementDocument} from '../types' @@ -26,6 +30,8 @@ const MOCKED_ANNOUNCEMENTS: StudioAnnouncementDocument[] = [ _createdAt: '', _updatedAt: '', title: 'Announcement 1', + name: 'announcement-1', + subtitle: "What's new", body: [ { _type: 'block', @@ -65,6 +71,8 @@ const MOCKED_ANNOUNCEMENTS: StudioAnnouncementDocument[] = [ _createdAt: '', _updatedAt: '', title: 'Announcement 2', + name: 'announcement-2', + subtitle: "What's new", body: [ { _type: 'block', @@ -168,40 +176,24 @@ describe('StudioAnnouncementsCard', () => { const link = screen.getByText('Content with a link') fireEvent.click(link) expect(mockLog).toHaveBeenCalledTimes(2) - expect(mockLog).toHaveBeenCalledWith( - { - description: 'User viewed the product announcement', - name: 'Product Announcement Viewed', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-1', - announcement_title: 'Announcement 1', - origin: 'card', - scrolled_into_view: false, - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toHaveBeenCalledWith( - { - description: 'User clicked the link in the product announcement ', - name: 'Product Announcement Link Clicked', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-1', - announcement_title: 'Announcement 1', - link_title: 'Content with a link', - link_url: 'https://github.com/sanity-io/sanity/releases/tag/v3.56.0', - origin: 'card', - source: 'studio', - studio_version: '3.57.0', - }, - ) + expect(mockLog).toHaveBeenCalledWith(ProductAnnouncementViewed, { + announcement_id: 'studioAnnouncement-1', + announcement_title: 'Announcement 1', + announcement_internal_name: 'announcement-1', + origin: 'card', + scrolled_into_view: false, + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toHaveBeenCalledWith(ProductAnnouncementLinkClicked, { + announcement_id: 'studioAnnouncement-1', + announcement_title: 'Announcement 1', + announcement_internal_name: 'announcement-1', + link_title: 'Content with a link', + link_url: 'https://github.com/sanity-io/sanity/releases/tag/v3.56.0', + origin: 'card', + source: 'studio', + studio_version: '3.57.0', + }) }) }) diff --git a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsMenuItem.test.tsx b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsMenuItem.test.tsx index c497a3ee288f..92bfe2ffafb3 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsMenuItem.test.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsMenuItem.test.tsx @@ -6,6 +6,7 @@ import {type ReactNode} from 'react' import {defineConfig} from 'sanity' import {createTestProvider} from '../../../../../test/testUtils/TestProvider' +import {WhatsNewHelpMenuItemClicked} from '../__telemetry__/studioAnnouncements.telemetry' import {StudioAnnouncementsMenuItem} from '../StudioAnnouncementsMenuItem' import {type StudioAnnouncementDocument} from '../types' import {useStudioAnnouncements} from '../useStudioAnnouncements' @@ -32,6 +33,8 @@ const MOCKED_ANNOUNCEMENT: StudioAnnouncementDocument = { announcementType: 'whats-new', publishedDate: '2024-09-10T14:44:00.000Z', audience: 'everyone', + name: 'announcement-1', + subtitle: "What's new", } const useStudioAnnouncementsMock = useStudioAnnouncements as jest.Mock< typeof useStudioAnnouncements @@ -109,20 +112,12 @@ describe('StudioAnnouncementsMenuItem', () => { expect(onDialogOpenMock).toHaveBeenCalledWith('help_menu') expect(mockLog).toHaveBeenCalledTimes(1) - expect(mockLog).toHaveBeenCalledWith( - { - description: 'User clicked the "Whats new" help menu item', - name: 'Whats New Help Menu Item Clicked', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-1', - announcement_title: 'Announcement 1', - source: 'studio', - studio_version: '3.57.0', - }, - ) + expect(mockLog).toHaveBeenCalledWith(WhatsNewHelpMenuItemClicked, { + announcement_id: 'studioAnnouncement-1', + announcement_title: 'Announcement 1', + announcement_internal_name: 'announcement-1', + source: 'studio', + studio_version: '3.57.0', + }) }) }) diff --git a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsProvider.test.tsx b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsProvider.test.tsx index e9577d195bb0..b998aee04203 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsProvider.test.tsx +++ b/packages/sanity/src/core/studio/studioAnnouncements/__tests__/StudioAnnouncementsProvider.test.tsx @@ -7,6 +7,13 @@ import {defineConfig} from 'sanity' import {createTestProvider} from '../../../../../test/testUtils/TestProvider' import {useClient} from '../../../hooks/useClient' +import { + ProductAnnouncementCardClicked, + ProductAnnouncementCardDismissed, + ProductAnnouncementCardSeen, + ProductAnnouncementModalDismissed, + ProductAnnouncementViewed, +} from '../__telemetry__/studioAnnouncements.telemetry' import {StudioAnnouncementsProvider} from '../StudioAnnouncementsProvider' import {type StudioAnnouncementDocument} from '../types' import {useSeenAnnouncements} from '../useSeenAnnouncements' @@ -72,6 +79,7 @@ const mockAnnouncements: StudioAnnouncementDocument[] = [ subtitle: "What's new", publishedDate: '2024-09-10T14:44:00.000Z', audience: 'everyone', + name: 'announcement-1', }, { _id: 'studioAnnouncement-2', @@ -85,6 +93,7 @@ const mockAnnouncements: StudioAnnouncementDocument[] = [ subtitle: "What's new", publishedDate: '2024-09-10T14:44:00.000Z', audience: 'everyone', + name: 'announcement-2', }, ] @@ -218,53 +227,29 @@ describe('StudioAnnouncementsProvider', () => { // Opening the dialog calls the telemetry only once, with the seen card expect(mockLog).toBeCalledTimes(3) - expect(mockLog).toBeCalledWith( - { - description: 'User viewed the product announcement card', - name: 'Product Announcement Card Seen', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User clicked the product announcement card', - name: 'Product Announcement Card Clicked', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User viewed the product announcement', - name: 'Product Announcement Viewed', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - origin: 'card', - scrolled_into_view: false, - source: 'studio', - studio_version: '3.57.0', - }, - ) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardSeen, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardClicked, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementViewed, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + origin: 'card', + scrolled_into_view: false, + source: 'studio', + studio_version: '3.57.0', + }) }) test("dismisses card, then it's hidden, dialog doesn't render", async () => { @@ -285,36 +270,20 @@ describe('StudioAnnouncementsProvider', () => { // Dismissing the card calls telemetry with the seen and dismiss logs expect(mockLog).toBeCalledTimes(2) - expect(mockLog).toBeCalledWith( - { - description: 'User viewed the product announcement card', - name: 'Product Announcement Card Seen', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User dismissed the product announcement card', - name: 'Product Announcement Card Dismissed', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardSeen, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardDismissed, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) }) test('dismisses dialog, card and dialog are hidden', async () => { @@ -339,69 +308,37 @@ describe('StudioAnnouncementsProvider', () => { expect(queryByText(mockAnnouncements[1].title)).toBeNull() expect(mockLog).toBeCalledTimes(4) - expect(mockLog).toBeCalledWith( - { - description: 'User viewed the product announcement card', - name: 'Product Announcement Card Seen', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User clicked the product announcement card', - name: 'Product Announcement Card Clicked', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User dismissed the product announcement modal ', - name: 'Product Announcement Dismissed', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - origin: 'card', - source: 'studio', - studio_version: '3.57.0', - }, - ) - expect(mockLog).toBeCalledWith( - { - description: 'User viewed the product announcement', - name: 'Product Announcement Viewed', - schema: undefined, - type: 'log', - version: 1, - }, - { - announcement_id: 'studioAnnouncement-2', - announcement_title: 'Announcement 2', - origin: 'card', - scrolled_into_view: false, - source: 'studio', - studio_version: '3.57.0', - }, - ) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardSeen, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementCardClicked, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementModalDismissed, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + origin: 'card', + source: 'studio', + studio_version: '3.57.0', + }) + expect(mockLog).toBeCalledWith(ProductAnnouncementViewed, { + announcement_id: 'studioAnnouncement-2', + announcement_title: 'Announcement 2', + announcement_internal_name: 'announcement-2', + origin: 'card', + scrolled_into_view: false, + source: 'studio', + studio_version: '3.57.0', + }) }) test('opens the dialog from outside the card, so it shows all unseen', async () => { const Component = () => { diff --git a/packages/sanity/src/core/studio/studioAnnouncements/types.ts b/packages/sanity/src/core/studio/studioAnnouncements/types.ts index 7deb016085e9..aa797a5734c6 100644 --- a/packages/sanity/src/core/studio/studioAnnouncements/types.ts +++ b/packages/sanity/src/core/studio/studioAnnouncements/types.ts @@ -18,6 +18,7 @@ export interface StudioAnnouncementDocument { _createdAt: string _updatedAt: string title: string + name: string body: PortableTextBlock[] announcementType: 'whats-new' publishedDate: string