1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Add four new analytics fields to event context (#57930)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Kevin Heis
2025-10-13 08:26:31 -07:00
committed by GitHub
parent 9101e42ace
commit dba3f3a4a1
4 changed files with 45 additions and 6 deletions

View File

@@ -98,6 +98,7 @@ export function sendEvent<T extends EventType>({
// Content information
referrer: getReferrer(document.referrer),
title: document.title,
href: location.href, // full URL
hostname: location.hostname, // origin without protocol or port
path: location.pathname, // path without search or host
@@ -118,6 +119,9 @@ export function sendEvent<T extends EventType>({
is_headless: isHeadless(),
viewport_width: document.documentElement.clientWidth,
viewport_height: document.documentElement.clientHeight,
screen_width: window.screen.width,
screen_height: window.screen.height,
pixel_ratio: window.devicePixelRatio || 1,
// Location information
timezone: new Date().getTimezoneOffset() / -60,

View File

@@ -44,6 +44,10 @@ const context = {
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`.',
@@ -142,12 +146,27 @@ const context = {
viewport_width: {
type: 'number',
description: 'The viewport width, not the overall device size.',
minimum: 1,
minimum: 0,
},
viewport_height: {
type: 'number',
description: 'The viewport height, not the overall device height.',
minimum: 1,
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,
},
// Location information

View File

@@ -32,6 +32,7 @@ describe('POST /events', () => {
path: '/github/docs/issues',
hostname: 'github.com',
referrer: 'https://github.com/github/docs',
title: 'Issues · github/docs',
search: '?q=is%3Aissue+is%3Aopen+example+',
href: 'https://github.com/github/docs/issues?q=is%3Aissue+is%3Aopen+example+',
path_language: 'en',
@@ -44,6 +45,9 @@ describe('POST /events', () => {
is_headless: false,
viewport_width: 1418,
viewport_height: 501,
screen_width: 1920,
screen_height: 1080,
pixel_ratio: 2,
// Location information
timezone: -7,
@@ -64,6 +68,7 @@ describe('POST /events', () => {
path: '/github/docs/issues',
hostname: 'github.com',
referrer: 'https://github.com/github/docs',
title: 'Issues · github/docs',
search: '?q=is%3Aissue+is%3Aopen+example+',
href: 'https://github.com/github/docs/issues?q=is%3Aissue+is%3Aopen+example+',
path_language: 'en',
@@ -76,6 +81,9 @@ describe('POST /events', () => {
is_headless: false,
viewport_width: 1418,
viewport_height: 501,
screen_width: 1920,
screen_height: 1080,
pixel_ratio: 2,
// Location information
timezone: -7,

View File

@@ -24,6 +24,7 @@ export type EventProps = {
created: string
page_event_id: string
referrer: string
title?: string
href: string
hostname: string
path: string
@@ -31,9 +32,10 @@ export type EventProps = {
hash: string
path_language: string
path_version: string
path_product?: string
path_article: string
path_document_type: string
path_type: string
page_document_type: string
page_type: string
status: number
is_logged_in: boolean
dotcom_user: string
@@ -42,15 +44,21 @@ export type EventProps = {
os_version: string
browser: string
browser_version: string
is_headless: boolean
viewport_width?: number
viewport_height?: number
screen_width?: number
screen_height?: number
pixel_ratio?: number
timezone: number
user_language: string
os_preference: string
application_preference: string
color_mode_preference: string
os_preference: string
code_display_preference: string
experiment_variation?: string
event_group_key?: string
event_group_id?: string
is_headless: boolean
}
}