-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comments): add telemetry (#6541)
- Loading branch information
1 parent
46a02e2
commit 2d35256
Showing
4 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
packages/sanity/src/core/comments/__telemetry__/comments.telemetry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {defineEvent} from '@sanity/telemetry' | ||
|
||
import {type CommentStatus} from '../types' | ||
|
||
export const CommentLinkCopied = defineEvent({ | ||
name: 'Comment Link Copied', | ||
version: 1, | ||
description: 'The link to a comment is copied', | ||
}) | ||
|
||
export const CommentViewedFromLink = defineEvent({ | ||
name: 'Comment Viewed From Link', | ||
version: 1, | ||
description: 'A comment is viewed from a link', | ||
}) | ||
|
||
export const CommentListViewChanged = defineEvent<{view: CommentStatus}>({ | ||
name: 'Comment List View Changed', | ||
version: 1, | ||
description: 'The view of the comment list is changed', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/sanity/src/core/comments/hooks/useCommentsTelemetry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {useTelemetry} from '@sanity/telemetry/react' | ||
import {useCallback, useMemo} from 'react' | ||
|
||
import { | ||
CommentLinkCopied, | ||
CommentListViewChanged, | ||
CommentViewedFromLink, | ||
} from '../__telemetry__/comments.telemetry' | ||
import {type CommentStatus} from '../types' | ||
|
||
interface CommentsTelemetryHookValue { | ||
commentLinkCopied: () => void | ||
commentListViewChanged: (view: CommentStatus) => void | ||
commentViewedFromLink: () => void | ||
} | ||
|
||
/** @internal */ | ||
export function useCommentsTelemetry(): CommentsTelemetryHookValue { | ||
const telemetry = useTelemetry() | ||
|
||
const commentLinkCopied = useCallback(() => { | ||
telemetry.log(CommentLinkCopied) | ||
}, [telemetry]) | ||
|
||
const commentViewedFromLink = useCallback(() => { | ||
telemetry.log(CommentViewedFromLink) | ||
}, [telemetry]) | ||
|
||
const commentListViewChanged = useCallback( | ||
(view: CommentStatus) => { | ||
telemetry.log(CommentListViewChanged, {view}) | ||
}, | ||
[telemetry], | ||
) | ||
|
||
return useMemo( | ||
(): CommentsTelemetryHookValue => ({ | ||
commentLinkCopied, | ||
commentListViewChanged, | ||
commentViewedFromLink, | ||
}), | ||
[commentLinkCopied, commentListViewChanged, commentViewedFromLink], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters