Skip to content

Commit c007698

Browse files
authored
Add event tracking to code annotations (github#41204)
1 parent 998bf66 commit c007698

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

components/lib/toggle-annotations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Cookies from 'components/lib/cookies'
2+
import { sendEvent, EventType } from 'src/events/components/events'
23

34
enum annotationMode {
45
Beside = 'beside',
@@ -48,6 +49,11 @@ export default function toggleAnnotation() {
4849
// validate the annotation mode and set the cookie with the valid mode
4950
const validMode = validateMode(annotationBtn.getAttribute('value')!)
5051
Cookies.set('annotate-mode', validMode!)
52+
sendEvent({
53+
type: EventType.preference,
54+
preference_name: 'code_display',
55+
preference_value: validMode,
56+
})
5157

5258
// set and display the annotation mode
5359
setActive(annotationButtons, validMode)

src/events/components/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export function sendEvent<T extends EventType>({
169169
application_preference: Cookies.get('toolPreferred'),
170170
color_mode_preference: getColorModePreference(),
171171
os_preference: Cookies.get('osPreferred'),
172+
code_display_preference: Cookies.get('annotate-mode'),
172173
},
173174

174175
...props,

src/events/lib/schema.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ const context = {
156156
enum: ['dark', 'light', 'auto', 'auto:dark', 'auto:light'],
157157
description: 'The color mode selected by the user.',
158158
},
159+
code_display_preference: {
160+
enum: ['beside', 'inline'],
161+
description: 'How the user prefers to view code examples.',
162+
},
159163
},
160164
}
161165

@@ -439,22 +443,29 @@ const preference = {
439443
},
440444
preference_name: {
441445
type: 'string',
442-
enum: ['application', 'color_mode', 'os'],
446+
enum: ['application', 'color_mode', 'os', 'code_display'],
443447
description: 'The preference name, such as os, application, or color_mode',
444448
},
445449
preference_value: {
446450
type: 'string',
447-
enum: Object.keys(allTools).concat(
451+
enum: [
452+
// application
453+
...Object.keys(allTools),
454+
// color_mode
448455
'dark',
449456
'light',
450457
'auto',
451458
'auto:dark',
452459
'auto:light',
460+
// os
453461
'linux',
454462
'mac',
455463
'windows',
456-
),
457-
description: 'The application, color_mode, or os selected by the user.',
464+
// code_display
465+
'beside',
466+
'inline',
467+
],
468+
description: 'The application, color_mode, os, or code_display selected by the user.',
458469
},
459470
},
460471
}

0 commit comments

Comments
 (0)