Skip to content

Commit dba3f3a

Browse files
heiskrCopilot
andauthored
Add four new analytics fields to event context (#57930)
Co-authored-by: Copilot <[email protected]>
1 parent 9101e42 commit dba3f3a

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/events/components/events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function sendEvent<T extends EventType>({
9898

9999
// Content information
100100
referrer: getReferrer(document.referrer),
101+
title: document.title,
101102
href: location.href, // full URL
102103
hostname: location.hostname, // origin without protocol or port
103104
path: location.pathname, // path without search or host
@@ -118,6 +119,9 @@ export function sendEvent<T extends EventType>({
118119
is_headless: isHeadless(),
119120
viewport_width: document.documentElement.clientWidth,
120121
viewport_height: document.documentElement.clientHeight,
122+
screen_width: window.screen.width,
123+
screen_height: window.screen.height,
124+
pixel_ratio: window.devicePixelRatio || 1,
121125

122126
// Location information
123127
timezone: new Date().getTimezoneOffset() / -60,

src/events/lib/schema.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const context = {
4444
description: 'The browser value of `document.referrer`.',
4545
format: 'uri-reference',
4646
},
47+
title: {
48+
type: 'string',
49+
description: 'The browser value of `document.title`.',
50+
},
4751
href: {
4852
type: 'string',
4953
description: 'The browser value of `location.href`.',
@@ -142,12 +146,27 @@ const context = {
142146
viewport_width: {
143147
type: 'number',
144148
description: 'The viewport width, not the overall device size.',
145-
minimum: 1,
149+
minimum: 0,
146150
},
147151
viewport_height: {
148152
type: 'number',
149153
description: 'The viewport height, not the overall device height.',
150-
minimum: 1,
154+
minimum: 0,
155+
},
156+
screen_width: {
157+
type: 'number',
158+
description: 'The screen width of the device.',
159+
minimum: 0,
160+
},
161+
screen_height: {
162+
type: 'number',
163+
description: 'The screen height of the device.',
164+
minimum: 0,
165+
},
166+
pixel_ratio: {
167+
type: 'number',
168+
description: 'The device pixel ratio.',
169+
minimum: 0,
151170
},
152171

153172
// Location information

src/events/tests/middleware.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('POST /events', () => {
3232
path: '/github/docs/issues',
3333
hostname: 'github.com',
3434
referrer: 'https://github.com/github/docs',
35+
title: 'Issues · github/docs',
3536
search: '?q=is%3Aissue+is%3Aopen+example+',
3637
href: 'https://github.com/github/docs/issues?q=is%3Aissue+is%3Aopen+example+',
3738
path_language: 'en',
@@ -44,6 +45,9 @@ describe('POST /events', () => {
4445
is_headless: false,
4546
viewport_width: 1418,
4647
viewport_height: 501,
48+
screen_width: 1920,
49+
screen_height: 1080,
50+
pixel_ratio: 2,
4751

4852
// Location information
4953
timezone: -7,
@@ -64,6 +68,7 @@ describe('POST /events', () => {
6468
path: '/github/docs/issues',
6569
hostname: 'github.com',
6670
referrer: 'https://github.com/github/docs',
71+
title: 'Issues · github/docs',
6772
search: '?q=is%3Aissue+is%3Aopen+example+',
6873
href: 'https://github.com/github/docs/issues?q=is%3Aissue+is%3Aopen+example+',
6974
path_language: 'en',
@@ -76,6 +81,9 @@ describe('POST /events', () => {
7681
is_headless: false,
7782
viewport_width: 1418,
7883
viewport_height: 501,
84+
screen_width: 1920,
85+
screen_height: 1080,
86+
pixel_ratio: 2,
7987

8088
// Location information
8189
timezone: -7,

src/events/types.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ export type EventProps = {
2424
created: string
2525
page_event_id: string
2626
referrer: string
27+
title?: string
2728
href: string
2829
hostname: string
2930
path: string
3031
search: string
3132
hash: string
3233
path_language: string
3334
path_version: string
35+
path_product?: string
3436
path_article: string
35-
path_document_type: string
36-
path_type: string
37+
page_document_type: string
38+
page_type: string
3739
status: number
3840
is_logged_in: boolean
3941
dotcom_user: string
@@ -42,15 +44,21 @@ export type EventProps = {
4244
os_version: string
4345
browser: string
4446
browser_version: string
47+
is_headless: boolean
48+
viewport_width?: number
49+
viewport_height?: number
50+
screen_width?: number
51+
screen_height?: number
52+
pixel_ratio?: number
4553
timezone: number
4654
user_language: string
55+
os_preference: string
4756
application_preference: string
4857
color_mode_preference: string
49-
os_preference: string
5058
code_display_preference: string
59+
experiment_variation?: string
5160
event_group_key?: string
5261
event_group_id?: string
53-
is_headless: boolean
5462
}
5563
}
5664

0 commit comments

Comments
 (0)