Skip to content

Commit

Permalink
chore(core): update studio announcements telemetry, add internal_name
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Sep 23, 2024
1 parent ef18a1e commit 8d265b1
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ButtonRoot = styled.div`
interface StudioAnnouncementCardProps {
title: string
id: string
name: string
isOpen: boolean
preHeader: string
onCardClick: () => void
Expand All @@ -93,6 +94,7 @@ export function StudioAnnouncementsCard({
title,
id,
isOpen,
name,
preHeader,
onCardClick,
onCardDismiss,
Expand All @@ -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 (
<Popover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Announcement({announcement, mode, isFirst, parentRef}: AnnouncementProp
telemetry.log(ProductAnnouncementLinkClicked, {
announcement_id: announcement._id,
announcement_title: announcement.title,
announcement_internal_name: announcement.name,
source: 'studio',
studio_version: SANITY_VERSION,
origin: mode,
Expand All @@ -83,13 +84,14 @@ function Announcement({announcement, mode, isFirst, parentRef}: AnnouncementProp
telemetry.log(ProductAnnouncementViewed, {
announcement_id: announcement._id,
announcement_title: announcement.title,
announcement_internal_name: announcement.name,
source: 'studio',
studio_version: SANITY_VERSION,
scrolled_into_view: scrolledIntoView,
origin: mode,
})
},
[announcement._id, announcement.title, mode, telemetry],
[announcement._id, announcement.title, mode, telemetry, announcement.name],
)

useEffect(() => {
Expand Down Expand Up @@ -139,7 +141,10 @@ function Announcement({announcement, mode, isFirst, parentRef}: AnnouncementProp
</Flex>
</DialogHeader>
<Box padding={4}>
<UpsellDescriptionSerializer blocks={announcement.body} onLinkClick={handleLinkClick} />
<UpsellDescriptionSerializer
blocks={announcement.body || []}
onLinkClick={handleLinkClick}
/>
</Box>
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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',
Expand All @@ -139,6 +142,7 @@ export function StudioAnnouncementsProvider({children}: StudioAnnouncementsProvi
<StudioAnnouncementsCard
preHeader={unseenAnnouncements[0].preHeader}
title={unseenAnnouncements[0].title}
name={unseenAnnouncements[0].name}
id={unseenAnnouncements[0]._id}
onCardClick={handleCardClick}
isOpen={!isCardDismissed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {defineEvent} from '@sanity/telemetry'
interface ProductAnnouncementSharedProperties {
announcement_id: string
announcement_title: string
announcement_internal_name: string
source: 'studio'
studio_version?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const announcementCardProps = {
title: 'New Features Available',
id: 'foo',
preHeader: "What's new",
name: 'new-features',
} as const

describe('StudioAnnouncementsCard', () => {
Expand Down Expand Up @@ -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',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -27,6 +31,7 @@ const MOCKED_ANNOUNCEMENTS: StudioAnnouncementDocument[] = [
_updatedAt: '',
title: 'Announcement 1',
preHeader: "What's new",
name: 'announcement-1',
body: [
{
_type: 'block',
Expand Down Expand Up @@ -67,6 +72,7 @@ const MOCKED_ANNOUNCEMENTS: StudioAnnouncementDocument[] = [
_updatedAt: '',
title: 'Announcement 2',
preHeader: "What's new",
name: 'announcement-2',
body: [
{
_type: 'block',
Expand Down Expand Up @@ -170,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',
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -33,6 +34,7 @@ const MOCKED_ANNOUNCEMENT: StudioAnnouncementDocument = {
publishedDate: '2024-09-10T14:44:00.000Z',
audience: 'everyone',
preHeader: "What's new",
name: 'announcement-1',
}
const useStudioAnnouncementsMock = useStudioAnnouncements as jest.Mock<
typeof useStudioAnnouncements
Expand Down Expand Up @@ -110,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',
})
})
})
Loading

0 comments on commit 8d265b1

Please sign in to comment.