-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathschema.ts
More file actions
700 lines (675 loc) · 18.4 KB
/
schema.ts
File metadata and controls
700 lines (675 loc) · 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
import { languageKeys } from '@/languages/lib/languages-server'
import { allVersionKeys } from '@/versions/lib/all-versions'
import { productIds } from '@/products/lib/all-products'
import { allTools } from '@/tools/lib/all-tools'
import { contentTypesEnum } from '@/frame/lib/frontmatter'
const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$'
const context = {
type: 'object',
additionalProperties: false,
required: ['event_id', 'user', 'version', 'created', 'path'],
properties: {
// Required of all events
event_id: {
type: 'string',
description: 'The unique identifier of the event.',
format: 'uuid',
},
user: {
type: 'string',
description:
"The unique identifier of the current user performing the event. Please use randomly generated values or hashed values; we don't want to be able to look up in a database.",
format: 'uuid',
},
version: {
type: 'string',
description: 'The version of the event schema.',
pattern: versionPattern,
},
created: {
type: 'string',
format: 'date-time',
description: 'The time we created the event; please reference UTC.',
},
page_event_id: {
type: 'string',
description: 'The id of the corresponding `page` event.',
format: 'uuid',
},
// Content information
referrer: {
type: 'string',
description: 'The browser value of `document.referrer`.',
format: 'uri-reference',
},
title: {
type: 'string',
description: 'The browser value of `document.title`.',
},
href: {
type: 'string',
description: 'The browser value of `location.href`.',
format: 'uri',
},
hostname: {
type: 'string',
description: 'The browser value of `location.hostname.`',
format: 'uri-reference',
},
path: {
type: 'string',
description: 'The browser value of `location.pathname`.',
format: 'uri-reference',
},
search: {
type: 'string',
description: 'The browser value of `location.search`.',
},
hash: {
type: 'string',
description: 'The browser value of `location.hash`.',
},
path_language: {
type: 'string',
description: 'The language the user is viewing, from the URL path.',
enum: languageKeys,
},
path_version: {
type: 'string',
description: 'The GitHub version of the docs, from the URL path.',
enum: allVersionKeys,
},
path_product: {
type: 'string',
description: 'The GitHub product the docs are for, from the URL path.',
enum: productIds.concat(['homepage']),
},
path_article: {
type: 'string',
description: 'The article path without language or version, from the URL path.',
},
page_document_type: {
type: 'string',
description: 'The generic page document type based on URL path.',
enum: ['homepage', 'early-access', 'product', 'category', 'subcategory', 'article'], // get-document-type.ts
},
page_type: {
type: 'string',
description: 'Optional page type from the content frontmatter.',
enum: ['overview', 'quick_start', 'tutorial', 'how_to', 'reference', 'rai'], // frontmatter.ts
},
content_type: {
type: 'string',
description: 'Optional content type from the content frontmatter (EDI content models).',
enum: contentTypesEnum,
},
status: {
type: 'number',
description: 'The HTTP response status code of the main page HTML.',
minimum: 0,
maximum: 999,
},
is_logged_in: {
type: 'boolean',
description: 'Anonymous -- whether the user has github.com cookies set.',
},
dotcom_user: {
type: 'string',
description: 'The cookie value of dotcom_user',
},
is_staff: {
type: 'boolean',
description: 'The cookie value of staffonly',
},
octo_client_id: {
type: 'string',
description:
'The _octo cookie client ID for cross-subdomain tracking with github.com analytics.',
},
// Device information
os: {
type: 'string',
description: 'The type of operating system the user is working with.',
enum: ['windows', 'mac', 'linux', 'ios', 'android', 'cros', 'other'],
default: 'other',
},
os_version: {
type: 'string',
description: 'The version of the operating system the user is using.',
},
browser: {
type: 'string',
description: 'The type of browser the user is browsing with.',
enum: ['chrome', 'safari', 'firefox', 'edge', 'opera', 'other'],
default: 'other',
},
browser_version: {
type: 'string',
description: 'The version of the browser the user is browsing with.',
},
is_headless: {
type: 'boolean',
},
viewport_width: {
type: 'number',
description: 'The viewport width, not the overall device size.',
minimum: 0,
},
viewport_height: {
type: 'number',
description: 'The viewport height, not the overall device height.',
minimum: 0,
},
screen_width: {
type: 'number',
description: 'The screen width of the device.',
minimum: 0,
},
screen_height: {
type: 'number',
description: 'The screen height of the device.',
minimum: 0,
},
pixel_ratio: {
type: 'number',
description: 'The device pixel ratio.',
minimum: 0,
},
ip: {
type: 'string',
description: 'The IP address of the user.',
},
user_agent: {
type: 'string',
description: 'The raw user agent string from the browser.',
},
// Location information
timezone: {
type: 'number',
description: 'The timezone the user is in, as `new Date().getTimezoneOffset() / -60`.',
},
user_language: {
type: 'string',
description: 'The browser value of `navigator.language`.',
},
// Preference information
os_preference: {
type: 'string',
enum: ['linux', 'mac', 'windows'],
description: 'The os for examples selected by the user.',
},
application_preference: {
type: 'string',
enum: Object.keys(allTools),
description: 'The application selected by the user.',
},
color_mode_preference: {
enum: ['dark', 'light', 'auto', 'auto:dark', 'auto:light'],
description: 'The color mode selected by the user.',
},
code_display_preference: {
enum: ['beside', 'inline'],
description: 'How the user prefers to view code examples.',
},
// Experiments
experiment_variation: {
type: 'string',
description: 'The variation this user we bucketed in is in, such as control or treatment.',
},
// Event Grouping. The comination of key + id should be unique
event_group_key: {
type: 'string',
description: 'A enum indentifier (e.g. "ask-ai") used to put events into a specific group.',
},
event_group_id: {
type: 'string',
description:
'A unique id (uuid) that can be used to identify a group of events made by a user during the same session.',
},
},
}
const page = {
type: 'object',
additionalProperties: false,
required: ['type', 'context'],
properties: {
context,
type: {
type: 'string',
pattern: '^page$',
},
},
}
const exit = {
type: 'object',
additionalProperties: false,
required: ['type', 'context'],
properties: {
context,
type: {
type: 'string',
pattern: '^exit$',
},
exit_render_duration: {
type: 'number',
description: 'How long the server took to render the page content, in seconds.',
minimum: 0.001,
},
exit_first_paint: {
type: 'number',
minimum: 0.001,
description:
'The duration until `first-contentful-paint`, in seconds. Informs CSS performance.',
},
exit_dom_interactive: {
type: 'number',
minimum: 0.001,
description:
'The duration until `PerformanceNavigationTiming.domInteractive`, in seconds. Informs JavaScript loading performance.',
},
exit_dom_complete: {
type: 'number',
minimum: 0.001,
description:
'The duration until `PerformanceNavigationTiming.domComplete`, in seconds. Informs JavaScript execution performance.',
},
exit_visit_duration: {
type: 'number',
minimum: 0.001,
description:
'The duration of exit.timestamp - page.timestamp, in seconds. Informs bounce rate.',
},
exit_scroll_length: {
type: 'number',
minimum: 0,
maximum: 1,
description: 'The percentage of how far the user scrolled on the page.',
},
exit_scroll_flip: {
type: 'number',
minimum: 0,
description: 'The number of times the scroll direction changes.',
},
},
}
const keyboard = {
type: 'object',
additionalProperties: false,
required: ['pressed_key', 'pressed_on'],
properties: {
context,
type: {
type: 'string',
pattern: '^keyboard$',
},
pressed_key: {
type: 'string',
description: 'The key the user pressed.',
},
pressed_on: {
type: 'string',
description: 'The element/identifier the user pressed the key on.',
},
},
}
const link = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'link_url'],
properties: {
context,
type: {
type: 'string',
pattern: '^link$',
},
link_url: {
type: 'string',
format: 'uri',
description:
'The href of the anchor tag the user clicked, or the page or object they directed their browser to.',
},
link_samesite: {
type: 'boolean',
description: 'If the link stays on docs.github.com.',
},
link_samepage: {
type: 'boolean',
description: 'If the link stays on the same page (hash link).',
},
link_container: {
type: 'string',
enum: [
'header',
'nav',
'breadcrumbs',
'title',
'lead',
'notifications',
'article',
'alert',
'toc',
'footer',
'static',
],
description: 'The part of the page where the user clicked the link.',
},
},
}
const hover = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'hover_url'],
properties: {
context,
type: {
type: 'string',
pattern: '^hover$',
},
hover_url: {
type: 'string',
format: 'uri',
description:
'The href of the anchor tag the user hovered, or the page or object they directed their browser to.',
},
hover_samesite: {
type: 'boolean',
description: 'If the hover link stays on docs.github.com.',
},
},
}
const search = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'search_query'],
properties: {
context,
type: {
type: 'string',
pattern: '^search$',
},
search_query: {
type: 'string',
description: 'The actual text content of the query string the user sent to the service.',
},
search_context: {
type: 'string',
description: 'Any additional search context, such as component searched.',
},
search_client: {
type: 'string',
description: 'The client name identifier when the request is not from docs.github.com.',
},
},
}
const searchResult = {
type: 'object',
additionalProperties: false,
required: [
'type',
'context',
'search_result_query',
'search_result_index',
'search_result_total',
'search_result_rank',
'search_result_url',
],
properties: {
context,
type: {
type: 'string',
pattern: '^searchResult$',
},
search_result_query: {
type: 'string',
description: 'The query the user searched for.',
},
search_result_index: {
type: 'number',
description: 'The order position of the user selected search result.',
},
search_result_total: {
type: 'number',
description: 'The total number of search results we returned for the query.',
},
search_result_rank: {
type: 'number',
description:
'The rank score of the order position of the search result, example: `(total - index) / total`.',
},
search_result_url: {
type: 'string',
description: 'The destination url of the search result the user selected.',
},
},
}
const aiSearchResult = {
type: 'object',
additionalProperties: false,
required: [
'type',
'context',
'ai_search_result_links_json',
'ai_search_result_provided_answer',
'ai_search_result_response_status',
],
properties: {
context,
type: {
type: 'string',
pattern: '^aiSearchResult$',
},
ai_search_result_links_json: {
type: 'string',
description:
'Dynamic JSON string of an array of "link" objects in the form: [{ "type": "reference" | "inline", "url": "https://..", "product": "issues" | "pages" | ... }, ...]',
},
ai_search_result_provided_answer: {
type: 'boolean',
description: 'Whether the GPT was able to answer the query.',
},
ai_search_result_response_status: {
type: 'number',
description: 'The status code of the GPT response.',
},
ai_search_result_connected_event_id: {
type: 'string',
description: 'The id of the corresponding CSE copilot conversation event.',
},
},
}
const survey = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'survey_vote'],
properties: {
context,
type: {
type: 'string',
pattern: '^survey$',
},
survey_vote: {
type: 'boolean',
description: 'Whether the user found the page helpful.',
},
survey_comment: {
type: 'string',
description: 'Any textual comments the user wanted to provide.',
},
survey_email: {
type: 'string',
format: 'email',
description: "The user's email address, if the user provided and consented.",
},
survey_rating: {
type: 'number',
description:
'The computed rating of the quality of the survey comment. Used for spam filtering and quality control.',
},
survey_comment_language: {
type: 'string',
description:
'The guessed language of the survey comment. The guessed language is very inaccurate when the string contains fewer than 3 or 4 words.',
},
survey_connected_event_id: {
type: 'string',
description: 'The id of the corresponding CSE copilot conversation event.',
},
},
}
const experiment = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'experiment_name', 'experiment_variation'],
properties: {
context,
type: {
type: 'string',
pattern: '^experiment$',
},
experiment_name: {
type: 'string',
description: 'The test that this event is part of.',
},
experiment_variation: {
type: 'string',
description: 'The variation this user we bucketed in is in, such as control or treatment.',
},
experiment_success: {
type: 'boolean',
default: true,
description: 'Whether or not the user successfully performed the test goal.',
},
},
}
const clipboard = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'clipboard_operation'],
properties: {
context,
type: {
type: 'string',
pattern: '^clipboard$',
},
clipboard_operation: {
type: 'string',
description: 'Which clipboard operation the user is performing.',
enum: ['copy', 'paste', 'cut'],
},
clipboard_target: {
type: 'string',
description: 'How the user got the contents into their clipboard.',
},
},
}
const print = {
type: 'object',
additionalProperties: false,
required: ['type', 'context'],
properties: {
context,
type: {
type: 'string',
pattern: '^print$',
},
},
}
const preference = {
type: 'object',
additionalProperties: false,
required: ['type', 'context', 'preference_name', 'preference_value'],
properties: {
context,
type: {
type: 'string',
pattern: '^preference$',
},
preference_name: {
type: 'string',
enum: ['application', 'color_mode', 'os', 'code_display'],
description: 'The preference name, such as os, application, or color_mode',
},
preference_value: {
type: 'string',
enum: [
// application
...Object.keys(allTools),
// color_mode
'dark',
'light',
'auto',
'auto:dark',
'auto:light',
// os
'linux',
'mac',
'windows',
// code_display
'beside',
'inline',
],
description: 'The application, color_mode, os, or code_display selected by the user.',
},
},
}
const validation = {
type: 'object',
additionalProperties: false,
properties: {
event_id: { type: 'string', format: 'uuid' },
version: { type: 'string', pattern: versionPattern },
created: { type: 'string', format: 'date-time' },
raw: { type: 'string' },
// https://ajv.js.org/api.html#error-objects
keyword: { type: 'string' },
instance_path: { type: 'string' },
schema_path: { type: 'string' },
params: { type: 'string' },
property_name: { type: 'string' },
message: { type: 'string' },
schema: { type: 'string' },
parent_schema: { type: 'string' },
data: { type: 'string' },
},
}
// We are not using `oneOf` to keep the list of errors short.
export const schemas = {
page,
exit,
keyboard,
link,
hover,
search,
searchResult,
aiSearchResult,
survey,
experiment,
clipboard,
print,
preference,
validation,
}
export const hydroNames = {
page: 'docs.v0.PageEvent',
exit: 'docs.v0.ExitEvent',
keyboard: 'docs.v0.KeyboardEvent',
link: 'docs.v0.LinkEvent',
hover: 'docs.v0.HoverEvent',
search: 'docs.v0.SearchEvent',
searchResult: 'docs.v0.SearchResultEvent',
aiSearchResult: 'docs.v0.AISearchResultEvent',
survey: 'docs.v0.SurveyEvent',
experiment: 'docs.v0.ExperimentEvent',
clipboard: 'docs.v0.ClipboardEvent',
print: 'docs.v0.PrintEvent',
preference: 'docs.v0.PreferenceEvent',
validation: 'docs.v0.ValidationEvent',
} as Record<keyof typeof schemas, string>
const schemasKeys = Object.keys(schemas)
const hydroNamesKeys = Object.keys(hydroNames)
if (
schemasKeys.length !== hydroNamesKeys.length ||
!schemasKeys.every((k) => hydroNamesKeys.includes(k))
) {
throw new Error("The keys in 'schemas' doesn't match with the keys in 'hydroNames'")
}