Skip to content

Commit

Permalink
✨ Collect viewport size
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Jun 8, 2022
1 parent 386e326 commit 7b1335a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { RumSessionPlan } from './rumSessionManager'
import type { UrlContexts } from './contexts/urlContexts'
import type { RumConfiguration } from './configuration'
import type { ActionContexts } from './rumEventsCollection/action/actionCollection'
import { getDisplayContext } from './contexts/displayContext'

// replaced at build time
declare const __BUILD_ENV__SDK_VERSION__: string
Expand Down Expand Up @@ -121,6 +122,7 @@ export function startRumAssembly(
},
synthetics: syntheticsContext,
ci_test: ciTestContext,
display: getDisplayContext(),
}
const actionId = actionContexts.findActionId(startTime)

Expand Down
23 changes: 23 additions & 0 deletions packages/rum-core/src/domain/contexts/displayContext.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { resetExperimentalFeatures, updateExperimentalFeatures } from '@datadog/browser-core'
import { getDisplayContext } from './displayContext'

describe('displayContext', () => {
afterEach(() => {
resetExperimentalFeatures()
})

it('should return current display context when ff enabled', () => {
updateExperimentalFeatures(['clickmap'])

expect(getDisplayContext()).toEqual({
viewport: {
width: jasmine.any(Number),
height: jasmine.any(Number),
},
})
})

it('should not return current display context when ff disabled', () => {
expect(getDisplayContext()).not.toBeDefined()
})
})
12 changes: 12 additions & 0 deletions packages/rum-core/src/domain/contexts/displayContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { isExperimentalFeatureEnabled } from '@datadog/browser-core'

export function getDisplayContext() {
if (!isExperimentalFeatureEnabled('clickmap')) return

return {
viewport: {
width: window.innerWidth,
height: window.innerHeight,
},
}
}
6 changes: 6 additions & 0 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ export interface RumContext {
type: string
has_replay?: boolean
}
display?: {
viewport: {
width: number
height: number
}
}
synthetics?: {
test_id: string
result_id: string
Expand Down

0 comments on commit 7b1335a

Please sign in to comment.