Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [RUMF-794] Add isActive attribute to view events #648

Merged
merged 6 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,45 @@ describe('rum track loading type', () => {
})
})

describe('rum track view is active', () => {
let setupBuilder: TestSetupBuilder
let handler: jasmine.Spy
let getViewEvent: (index: number) => View

beforeEach(() => {
;({ handler, getViewEvent } = spyOnViews())

setupBuilder = setup()
.withFakeLocation('/foo')
.beforeBuild(({ location, lifeCycle }) => {
lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler)
return trackViews(location, lifeCycle)
})
})

afterEach(() => {
setupBuilder.cleanup()
})

it('should set initial view as active', () => {
setupBuilder.build()
expect(getViewEvent(0).isActive).toBe(true)
})

it('should set old view as inactive and new one as active after a route change', () => {
setupBuilder.build()
history.pushState({}, '', '/bar')
expect(getViewEvent(1).isActive).toBe(false)
expect(getViewEvent(2).isActive).toBe(true)
})

it('should keep view as active after a search change', () => {
setupBuilder.build()
history.pushState({}, '', '/foo?bar=qux')
expect(getViewEvent(1).isActive).toBe(true)
})
})

describe('rum track loading time', () => {
let setupBuilder: TestSetupBuilder
let handler: jasmine.Spy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface View {
documentVersion: number
startTime: number
duration: number
isActive: boolean
loadingTime?: number | undefined
loadingType: ViewLoadingType
cumulativeLayoutShift?: number
Expand Down Expand Up @@ -51,8 +52,8 @@ export function trackViews(location: Location, lifeCycle: LifeCycle) {
function onLocationChange() {
if (currentView.isDifferentView(location)) {
// Renew view on location changes
currentView.triggerUpdate()
currentView.end()
currentView.triggerUpdate()
currentView = newView(lifeCycle, location, ViewLoadingType.ROUTE_CHANGE, currentView.url)
} else {
currentView.updateLocation(location)
Expand All @@ -69,8 +70,8 @@ export function trackViews(location: Location, lifeCycle: LifeCycle) {

// End the current view on page unload
lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, () => {
currentView.triggerUpdate()
currentView.end()
currentView.triggerUpdate()
})

// Session keep alive
Expand Down Expand Up @@ -163,6 +164,7 @@ function newView(
startTime,
timings,
duration: (endTime === undefined ? performance.now() : endTime) - startTime,
isActive: endTime === undefined,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('viewCollection', () => {
userActionCount: 10,
},
id: 'xxx',
isActive: false,
loadingTime: 20,
loadingType: ViewLoadingType.INITIAL_LOAD,
location: {},
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('viewCollection', () => {
},
firstContentfulPaint: 10 * 1e6,
firstInputDelay: 12 * 1e6,
isActive: false,
largestContentfulPaint: 10 * 1e6,
loadEvent: 10 * 1e6,
loadingTime: 20 * 1e6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function processViewUpdate(view: View) {
},
firstContentfulPaint: msToNs(view.timings.firstContentfulPaint),
firstInputDelay: msToNs(view.timings.firstInputDelay),
isActive: view.isActive,
largestContentfulPaint: msToNs(view.timings.largestContentfulPaint),
loadEvent: msToNs(view.timings.loadEvent),
loadingTime: msToNs(view.loadingTime),
Expand Down
1 change: 1 addition & 0 deletions packages/rum/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface RawRumViewEvent {
loadEvent?: number
loadingTime?: number
timeSpent: number
isActive: boolean
error: Count
action: Count
longTask: Count
Expand Down
1 change: 1 addition & 0 deletions packages/rum/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
view: {
action: { count: 0 },
error: { count: 0 },
isActive: true,
loadingType: ViewLoadingType.INITIAL_LOAD,
longTask: { count: 0 },
resource: { count: 0 },
Expand Down