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

🐛[RUM] fix wrong url on spa last view event #184

Merged
merged 1 commit into from
Nov 29, 2019
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
6 changes: 3 additions & 3 deletions packages/rum/src/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { matchRequestTiming } from './matchRequestTiming'
import { computePerformanceResourceDetails, computeResourceKind, computeSize, isValidResource } from './resourceUtils'
import { RumGlobal } from './rum.entry'
import { RumSession } from './rumSession'
import { trackView, viewId, ViewMeasures } from './viewTracker'
import { trackView, viewId, viewLocation, ViewMeasures } from './viewTracker'

export interface PerformancePaintTiming extends PerformanceEntry {
entryType: 'paint'
Expand Down Expand Up @@ -148,13 +148,13 @@ export function startRum(
screen: {
// needed for retro compatibility
id: viewId,
url: window.location.href,
url: viewLocation.href,
},
sessionId: session.getId(),
view: {
id: viewId,
referrer: document.referrer,
url: window.location.href,
url: viewLocation.href,
},
},
globalContext
Expand Down
8 changes: 4 additions & 4 deletions packages/rum/src/viewTracker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Batch, generateUUID, monitor, msToNs, throttle } from '@browser-agent/core'

import { LifeCycle, LifeCycleEventType } from './lifeCycle'
import { PerformancePaintTiming, RumEvent, RumEventCategory, RumViewEvent } from './rum'
import { PerformancePaintTiming, RumEvent, RumEventCategory } from './rum'

export interface ViewMeasures {
firstContentfulPaint?: number
Expand All @@ -15,12 +15,12 @@ export interface ViewMeasures {
}

export let viewId: string
export let viewLocation: Location

const THROTTLE_VIEW_UPDATE_PERIOD = 3000
let startTimestamp: number
let startOrigin: number
let documentVersion: number
let activeLocation: Location
let viewMeasures: ViewMeasures

export function trackView(
Expand Down Expand Up @@ -51,7 +51,7 @@ function newView(location: Location, addRumEvent: (event: RumEvent) => void) {
longTaskCount: 0,
userActionCount: 0,
}
activeLocation = { ...location }
viewLocation = { ...location }
addViewEvent(addRumEvent)
}

Expand Down Expand Up @@ -93,7 +93,7 @@ function trackHistory(location: Location, addRumEvent: (event: RumEvent) => void
}

function onUrlChange(location: Location, addRumEvent: (event: RumEvent) => void) {
if (areDifferentViews(activeLocation, location)) {
if (areDifferentViews(viewLocation, location)) {
updateView(addRumEvent)
newView(location, addRumEvent)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/rum/test/viewTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Batch } from '@browser-agent/core'

import { LifeCycle, LifeCycleEventType } from '../src/lifeCycle'
import { PerformanceLongTaskTiming, PerformancePaintTiming, RumEvent, RumViewEvent, UserAction } from '../src/rum'
import { trackView, viewId } from '../src/viewTracker'
import { trackView, viewId, viewLocation } from '../src/viewTracker'

function setup({
addRumEvent,
Expand All @@ -29,28 +29,33 @@ function setup({

describe('rum track url change', () => {
let initialView: string
let initialLocation: Location

beforeEach(() => {
setup()
initialView = viewId
initialLocation = viewLocation
})

it('should update view id on path change', () => {
history.pushState({}, '', '/bar')

expect(viewId).not.toEqual(initialView)
expect(viewLocation).not.toEqual(initialLocation)
})

it('should not update view id on search change', () => {
history.pushState({}, '', '/foo?bar=qux')

expect(viewId).toEqual(initialView)
expect(viewLocation).toEqual(initialLocation)
})

it('should not update view id on hash change', () => {
history.pushState({}, '', '/foo#bar')

expect(viewId).toEqual(initialView)
expect(viewLocation).toEqual(initialLocation)
})
})

Expand Down