-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add visual-editing telemetry (#2263)
* chore(dnd-telemetry): wip * chore(dnd-telemetry): add sendVisualEditingTelemetry * chore(dnd-telemetry): throw error if unknown event is passed * chore(dnd-telemetry): rename sendVisualEditingTelemetry > sendTelemetry, update event name * chore(dnd-telemetry): fix linter issues - node env turbo definition, no console * chore(dnd-telemetry): remove telemetry vars from studio turbo config * chore(dnd-telemetry): add debug env variable to studio turbo.json * chore(dnd-telemetry): wip * chore(dnd-telemetry): remove custom debug vars, rely on new studio implementation * chore(dnd-telemetry): remove unused env vars * chore(dnd-telemetry): update sequence end event to be completed
- Loading branch information
1 parent
1713da7
commit 8d2fd18
Showing
7 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
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
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
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,25 @@ | ||
import {useTelemetry} from '@sanity/telemetry/react' | ||
import {memo, useEffect, type FC} from 'react' | ||
import type {VisualEditingConnection} from './types' | ||
|
||
export interface PostMessageTelemetryProps { | ||
comlink: VisualEditingConnection | ||
} | ||
|
||
const PostMessageTelemetry: FC<PostMessageTelemetryProps> = (props) => { | ||
const {comlink} = props | ||
|
||
const telemetry = useTelemetry() | ||
|
||
useEffect(() => { | ||
return comlink.on('visual-editing/telemetry-log', async (message) => { | ||
const {event, data} = message | ||
|
||
// SANITY_STUDIO_DEBUG_TELEMETRY ensures noop/in-browser logging for telemetry events | ||
data ? telemetry.log(event, data) : telemetry.log(event) | ||
}) | ||
}, [comlink, telemetry]) | ||
|
||
return null | ||
} | ||
export default memo(PostMessageTelemetry) |
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
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
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
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,34 @@ | ||
import {defineEvent} from '@sanity/telemetry' | ||
import type {VisualEditingNode} from '../../types' | ||
|
||
const events = { | ||
'Visual Editing Drag Sequence Completed': defineEvent({ | ||
name: 'Visual Editing Drag Sequence Completed', | ||
description: 'An array is successfully reordered using drag and drop.', | ||
version: 1, | ||
}), | ||
} | ||
|
||
type EventDataMap = { | ||
[K in keyof typeof events]: (typeof events)[K] extends ReturnType<typeof defineEvent<infer T>> | ||
? T | ||
: never | ||
} | ||
|
||
function sendTelemetry<K extends keyof typeof events>( | ||
name: K, | ||
data: EventDataMap[K] extends void ? null | undefined : EventDataMap[K], | ||
comlink: VisualEditingNode | undefined, | ||
): void { | ||
if (!comlink) return | ||
|
||
const event = events[name] | ||
|
||
if (!event) { | ||
throw new Error(`Telemetry event: ${name} does not exist`) | ||
} else { | ||
comlink.post('visual-editing/telemetry-log', {event, data}) | ||
} | ||
} | ||
|
||
export {sendTelemetry} |