@cloudcare/browser-rum 3.0.5 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +1 -1
  4. package/cjs/boot/rum.js +16 -7
  5. package/cjs/boot/rumPublicApi.js +27 -55
  6. package/cjs/domain/assembly.js +2 -2
  7. package/cjs/domain/configuration.js +1 -0
  8. package/cjs/domain/contexts/commonContext.js +14 -0
  9. package/cjs/domain/performanceCollection.js +3 -3
  10. package/cjs/domain/replay/record/serialize.js +7 -5
  11. package/cjs/domain/replay/segmentCollection/segmentCollection.js +2 -2
  12. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +2 -2
  13. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  14. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +34 -10
  15. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  16. package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -67
  17. package/cjs/domain/rumEventsCollection/view/viewCollection.js +2 -1
  18. package/cjs/domain/rumSessionManager.js +3 -1
  19. package/cjs/domain/waitPageActivityEnd.js +9 -9
  20. package/cjs/transport/startRumBatch.js +20 -6
  21. package/esm/boot/buildEnv.js +1 -1
  22. package/esm/boot/recorderApi.js +1 -1
  23. package/esm/boot/rum.js +15 -7
  24. package/esm/boot/rumPublicApi.js +25 -54
  25. package/esm/domain/assembly.js +2 -2
  26. package/esm/domain/configuration.js +1 -0
  27. package/esm/domain/contexts/commonContext.js +7 -0
  28. package/esm/domain/performanceCollection.js +2 -2
  29. package/esm/domain/replay/record/serialize.js +7 -5
  30. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  31. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +3 -3
  32. package/esm/domain/rumEventsCollection/actions/clickChain.js +1 -1
  33. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +33 -10
  34. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  35. package/esm/domain/rumEventsCollection/view/trackViews.js +46 -68
  36. package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -1
  37. package/esm/domain/rumSessionManager.js +3 -1
  38. package/esm/domain/waitPageActivityEnd.js +3 -3
  39. package/esm/transport/startRumBatch.js +21 -7
  40. package/package.json +31 -31
  41. package/src/boot/recorderApi.js +1 -0
  42. package/src/boot/rum.js +29 -9
  43. package/src/boot/rumPublicApi.js +37 -51
  44. package/src/domain/assembly.js +2 -2
  45. package/src/domain/configuration.js +4 -0
  46. package/src/domain/contexts/commonContext.js +11 -0
  47. package/src/domain/performanceCollection.js +4 -2
  48. package/src/domain/replay/record/serialize.js +6 -5
  49. package/src/domain/replay/segmentCollection/segmentCollection.js +3 -1
  50. package/src/domain/replay/segmentCollection/startDeflateWorker.js +8 -3
  51. package/src/domain/rumEventsCollection/actions/clickChain.js +6 -1
  52. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +42 -11
  53. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  54. package/src/domain/rumEventsCollection/view/trackViews.js +69 -77
  55. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
  56. package/src/domain/rumSessionManager.js +3 -1
  57. package/src/domain/waitPageActivityEnd.js +8 -5
  58. package/src/transport/startRumBatch.js +35 -12
@@ -1,23 +1,39 @@
1
1
  import {
2
2
  makePublicApi,
3
- assign,
4
3
  areCookiesAuthorized,
5
4
  BoundedBuffer,
6
5
  display,
7
6
  buildCookieOptions,
8
7
  createContextManager,
8
+ CustomerDataType,
9
9
  clocksNow,
10
10
  timeStampNow,
11
11
  ActionType,
12
12
  deepClone,
13
- createHandlingStack
13
+ createHandlingStack,
14
+ sanitizeUser,
15
+ checkUser,
16
+ noop
14
17
  } from '@cloudcare/browser-core'
15
18
  import { validateAndBuildRumConfiguration } from '../domain/configuration'
19
+ import { buildCommonContext } from '../domain/contexts/commonContext'
16
20
  export function makeRumPublicApi(startRumImpl, recorderApi) {
17
21
  var isAlreadyInitialized = false
18
22
 
19
- var globalContextManager = createContextManager()
20
- var userContextManager = createContextManager()
23
+ var globalContextManager = createContextManager(
24
+ CustomerDataType.GlobalContext
25
+ )
26
+ var userContextManager = createContextManager(CustomerDataType.User)
27
+
28
+ var getInternalContextStrategy = function () {
29
+ return undefined
30
+ }
31
+ var getInitConfigurationStrategy = function () {
32
+ return undefined
33
+ }
34
+ var stopSessionStrategy = function () {
35
+ return noop()
36
+ }
21
37
  var bufferApiCalls = new BoundedBuffer()
22
38
  var addTimingStrategy = function (name, time) {
23
39
  if (typeof time === 'undefined') {
@@ -37,10 +53,11 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
37
53
  }
38
54
  var addActionStrategy = function (action, commonContext) {
39
55
  if (typeof commonContext == 'undefined') {
40
- commonContext = {
41
- context: globalContextManager.getContext(),
42
- user: userContextManager.getContext()
43
- }
56
+ commonContext = buildCommonContext(
57
+ globalContextManager,
58
+ userContextManager,
59
+ recorderApi
60
+ )
44
61
  }
45
62
  bufferApiCalls.add(function () {
46
63
  return addActionStrategy(action, commonContext)
@@ -48,23 +65,17 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
48
65
  }
49
66
  var addErrorStrategy = function (providedError, commonContext) {
50
67
  if (typeof commonContext == 'undefined') {
51
- commonContext = {
52
- context: globalContextManager.getContext(),
53
- user: userContextManager.getContext()
54
- }
68
+ commonContext = buildCommonContext(
69
+ globalContextManager,
70
+ userContextManager,
71
+ recorderApi
72
+ )
55
73
  }
56
74
  bufferApiCalls.add(function () {
57
75
  return addErrorStrategy(providedError, commonContext)
58
76
  })
59
77
  }
60
78
 
61
- var getInternalContextStrategy = function () {
62
- return undefined
63
- }
64
- var getInitConfigurationStrategy = function () {
65
- return undefined
66
- }
67
-
68
79
  function initRum(initConfiguration) {
69
80
  if (!canHandleSession(initConfiguration)) {
70
81
  return
@@ -102,14 +113,9 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
102
113
  function doStartRum(configuration, initialViewOptions) {
103
114
  var startRumResults = startRumImpl(
104
115
  configuration,
105
- function () {
106
- return {
107
- user: userContextManager.getContext(),
108
- context: globalContextManager.getContext(),
109
- hasReplay: recorderApi.isRecording() ? true : undefined
110
- }
111
- },
112
116
  recorderApi,
117
+ globalContextManager,
118
+ userContextManager,
113
119
  initialViewOptions
114
120
  )
115
121
  startViewStrategy = startRumResults.startView
@@ -117,6 +123,7 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
117
123
  addErrorStrategy = startRumResults.addError
118
124
  addTimingStrategy = startRumResults.addTiming
119
125
  getInternalContextStrategy = startRumResults.getInternalContext
126
+ stopSessionStrategy = startRumResults.stopSession
120
127
  bufferApiCalls.drain()
121
128
  recorderApi.onRumStart(
122
129
  startRumResults.lifeCycle,
@@ -167,14 +174,6 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
167
174
  type: ActionType.CUSTOM
168
175
  })
169
176
  },
170
-
171
- /**
172
- * @deprecated use addAction instead
173
- */
174
- // addUserAction: function (name, context) {
175
- // rumPublicApi.addAction(name, context)
176
- // },
177
-
178
177
  addError: function (error, context) {
179
178
  var handlingStack = createHandlingStack()
180
179
  addErrorStrategy({
@@ -188,9 +187,7 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
188
187
  addTimingStrategy(name, time)
189
188
  },
190
189
  setUser: function (newUser) {
191
- if (typeof newUser !== 'object' || !newUser) {
192
- display.error('Unsupported user:', newUser)
193
- } else {
190
+ if (checkUser(newUser)) {
194
191
  userContextManager.setContext(sanitizeUser(newUser))
195
192
  }
196
193
  },
@@ -207,24 +204,13 @@ export function makeRumPublicApi(startRumImpl, recorderApi) {
207
204
  removeUser: userContextManager.clearContext,
208
205
  clearUser: userContextManager.clearContext,
209
206
  startView: startView,
207
+ stopSession: function () {
208
+ stopSessionStrategy()
209
+ },
210
210
  startSessionReplayRecording: recorderApi.start,
211
211
  stopSessionReplayRecording: recorderApi.stop
212
212
  })
213
213
  return rumPublicApi
214
-
215
- function sanitizeUser(newUser) {
216
- var shallowClonedUser = assign(newUser, {})
217
- if ('id' in shallowClonedUser) {
218
- shallowClonedUser.id = String(shallowClonedUser.id)
219
- }
220
- if ('name' in shallowClonedUser) {
221
- shallowClonedUser.name = String(shallowClonedUser.name)
222
- }
223
- if ('email' in shallowClonedUser) {
224
- shallowClonedUser.email = String(shallowClonedUser.email)
225
- }
226
- return shallowClonedUser
227
- }
228
214
  function canHandleSession(initConfiguration) {
229
215
  if (!areCookiesAuthorized(buildCookieOptions(initConfiguration))) {
230
216
  display.warn('Cookies are not authorized, we will not send any data.')
@@ -40,7 +40,7 @@ export function startRumAssembly(
40
40
  viewContexts,
41
41
  urlContexts,
42
42
  actionContexts,
43
- getCommonContext,
43
+ buildCommonContext,
44
44
  reportError
45
45
  ) {
46
46
  var eventRateLimiters = {}
@@ -69,7 +69,7 @@ export function startRumAssembly(
69
69
  )
70
70
  if (session && viewContext && urlContext) {
71
71
  var actionId = actionContexts.findActionId(startTime)
72
- var commonContext = savedCommonContext || getCommonContext()
72
+ var commonContext = savedCommonContext || buildCommonContext()
73
73
  var rumContext = {
74
74
  _dd: {
75
75
  sdkName: configuration.sdkName,
@@ -74,6 +74,10 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
74
74
  {
75
75
  applicationId: initConfiguration.applicationId,
76
76
  actionNameAttribute: initConfiguration.actionNameAttribute,
77
+ sessionReplaySampleRate: isNullUndefinedDefaultValue(
78
+ initConfiguration.sessionReplaySampleRate,
79
+ 100
80
+ ),
77
81
  tracingSampleRate: initConfiguration.tracingSampleRate,
78
82
  allowedTracingOrigins: isNullUndefinedDefaultValue(
79
83
  initConfiguration.allowedTracingOrigins ||
@@ -0,0 +1,11 @@
1
+ export function buildCommonContext(
2
+ globalContextManager,
3
+ userContextManager,
4
+ recorderApi
5
+ ) {
6
+ return {
7
+ context: globalContextManager.getContext(),
8
+ user: userContextManager.getContext(),
9
+ hasReplay: recorderApi.isRecording() ? true : undefined
10
+ }
11
+ }
@@ -10,7 +10,9 @@ import {
10
10
  relativeNow,
11
11
  DOM_EVENT,
12
12
  LifeCycleEventType,
13
- runOnReadyState
13
+ runOnReadyState,
14
+ setTimeout,
15
+ addEventListener
14
16
  } from '@cloudcare/browser-core'
15
17
  import {
16
18
  FAKE_INITIAL_DOCUMENT,
@@ -73,7 +75,7 @@ export function startPerformanceCollection(lifeCycle, configuration) {
73
75
  mainObserver.observe({ entryTypes: mainEntries })
74
76
  if (supportPerformanceObject() && 'addEventListener' in performance) {
75
77
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
76
- performance.addEventListener('resourcetimingbufferfull', function () {
78
+ addEventListener(performance, 'resourcetimingbufferfull', function () {
77
79
  performance.clearResourceTimings()
78
80
  })
79
81
  }
@@ -369,12 +369,13 @@ function isSVGElement(el) {
369
369
  return el.tagName === 'svg' || el instanceof SVGElement
370
370
  }
371
371
  function transformAttribute(doc, tagName, name, value) {
372
+ if (!value) return value
372
373
  if (
373
374
  name === 'src' ||
374
- (name === 'href' && value && !(tagName === 'use' && value[0] === '#'))
375
+ (name === 'href' && !(tagName === 'use' && value[0] === '#'))
375
376
  ) {
376
377
  return absoluteToDoc(doc, value)
377
- } else if (name === 'xlink:href' && value && value[0] !== '#') {
378
+ } else if (name === 'xlink:href' && value[0] !== '#') {
378
379
  return absoluteToDoc(doc, value)
379
380
  } else if (
380
381
  name === 'background' &&
@@ -382,11 +383,11 @@ function transformAttribute(doc, tagName, name, value) {
382
383
  (tagName === 'table' || tagName === 'td' || tagName === 'th')
383
384
  ) {
384
385
  return absoluteToDoc(doc, value)
385
- } else if (name === 'srcset' && value) {
386
+ } else if (name === 'srcset') {
386
387
  return getAbsoluteSrcsetString(doc, value)
387
- } else if (name === 'style' && value) {
388
+ } else if (name === 'style') {
388
389
  return switchToAbsoluteUrl(value, getHref())
389
- } else if (tagName === 'object' && name === 'data' && value) {
390
+ } else if (tagName === 'object' && name === 'data') {
390
391
  return absoluteToDoc(doc, value)
391
392
  } else {
392
393
  return value
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  ONE_SECOND,
3
3
  LifeCycleEventType,
4
- isPageExitReason
4
+ isPageExitReason,
5
+ setTimeout,
6
+ clearTimeout
5
7
  } from '@cloudcare/browser-core'
6
8
  import { buildReplayPayload } from './buildReplayPayload'
7
9
  import { Segment } from './segment'
@@ -1,4 +1,9 @@
1
- import { display, includes, each } from '@cloudcare/browser-core'
1
+ import {
2
+ display,
3
+ includes,
4
+ each,
5
+ addEventListener
6
+ } from '@cloudcare/browser-core'
2
7
  import { createDeflateWorker } from './deflateWorker'
3
8
 
4
9
  /**
@@ -55,8 +60,8 @@ export function doStartDeflateWorker(createDeflateWorkerImpl) {
55
60
  }
56
61
  try {
57
62
  var worker = createDeflateWorkerImpl()
58
- worker.addEventListener('error', onError)
59
- worker.addEventListener('message', function (event) {
63
+ addEventListener(worker, 'error', onError)
64
+ addEventListener(worker, 'message', function (event) {
60
65
  var data = event.data
61
66
  if (data.type === 'errored') {
62
67
  onError(data.error)
@@ -1,4 +1,9 @@
1
- import { ONE_SECOND, every } from '@cloudcare/browser-core'
1
+ import {
2
+ ONE_SECOND,
3
+ every,
4
+ setTimeout,
5
+ clearTimeout
6
+ } from '@cloudcare/browser-core'
2
7
 
3
8
  export var MAX_DURATION_BETWEEN_CLICKS = ONE_SECOND
4
9
  export var MAX_DISTANCE_BETWEEN_CLICKS = 100
@@ -6,19 +6,38 @@ import {
6
6
  find,
7
7
  findLast,
8
8
  LifeCycleEventType,
9
- ONE_MINUTE
9
+ ONE_MINUTE,
10
+ setTimeout,
11
+ relativeNow
10
12
  } from '@cloudcare/browser-core'
11
13
  import { trackFirstHidden } from './trackFirstHidden'
12
14
  // Discard LCP and FCP timings above a certain delay to avoid incorrect data
13
15
  // It happens in some cases like sleep mode or some browser implementations
14
16
  export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE
15
- export function trackInitialViewTimings(lifeCycle, callback) {
17
+ /**
18
+ * The initial view can finish quickly, before some metrics can be produced (ex: before the page load
19
+ * event, or the first input). Also, we don't want to trigger a view update indefinitely, to avoid
20
+ * updates on views that ended a long time ago. Keep watching for metrics after the view ends for a
21
+ * limited amount of time.
22
+ */
23
+ export const KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
24
+ export function trackInitialViewTimings(
25
+ lifeCycle,
26
+ setLoadEvent,
27
+ scheduleViewUpdate
28
+ ) {
16
29
  var timings = {}
17
30
  function setTimings(newTimings) {
18
31
  timings = extend(timings, newTimings)
19
- callback(timings)
32
+ scheduleViewUpdate()
20
33
  }
21
- var _trackNavigationTimings = trackNavigationTimings(lifeCycle, setTimings)
34
+ var _trackNavigationTimings = trackNavigationTimings(
35
+ lifeCycle,
36
+ function (newTimings) {
37
+ setLoadEvent(newTimings.loadEvent)
38
+ setTimings(newTimings)
39
+ }
40
+ )
22
41
  var stopNavigationTracking = _trackNavigationTimings.stop
23
42
  var _trackFirstContentfulPaint = trackFirstContentfulPaint(
24
43
  lifeCycle,
@@ -45,13 +64,17 @@ export function trackInitialViewTimings(lifeCycle, callback) {
45
64
  }
46
65
  )
47
66
  var stopFIDTracking = _trackFirstInputTimings.stop
48
-
67
+ function stop() {
68
+ stopNavigationTracking()
69
+ stopFCPTracking()
70
+ stopLCPTracking()
71
+ stopFIDTracking()
72
+ }
49
73
  return {
50
- stop: function () {
51
- stopNavigationTracking()
52
- stopFCPTracking()
53
- stopLCPTracking()
54
- stopFIDTracking()
74
+ stop: stop,
75
+ timings: timings,
76
+ scheduleStop: function () {
77
+ setTimeout(stop, KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY)
55
78
  }
56
79
  }
57
80
  }
@@ -73,7 +96,15 @@ export function trackNavigationTimings(lifeCycle, callback) {
73
96
  loadEventEnd: entry.loadEventEnd,
74
97
  loadEventStart: entry.loadEventStart,
75
98
  domContentLoadedEventEnd: entry.domContentLoadedEventEnd,
76
- domContentLoadedEventStart: entry.domContentLoadedEventStart
99
+ domContentLoadedEventStart: entry.domContentLoadedEventStart,
100
+ // In some cases the value reported is negative or is larger
101
+ // than the current page time. Ignore these cases:
102
+ // https://github.com/GoogleChrome/web-vitals/issues/137
103
+ // https://github.com/GoogleChrome/web-vitals/issues/162
104
+ firstByte:
105
+ entry.responseStart >= 0 && entry.responseStart <= relativeNow()
106
+ ? entry.responseStart
107
+ : undefined
77
108
  })
78
109
  }
79
110
  }
@@ -1,4 +1,4 @@
1
- import { ONE_MINUTE } from '@cloudcare/browser-core'
1
+ import { ONE_MINUTE, setTimeout } from '@cloudcare/browser-core'
2
2
  import { trackEventCounts } from '../../trackEventCounts'
3
3
 
4
4
  // Some events are not being counted as they transcend views. To reduce the occurrence;
@@ -13,7 +13,11 @@ import {
13
13
  LifeCycleEventType,
14
14
  PageExitReason,
15
15
  isHashAnAnchor,
16
- getPathFromHash
16
+ getPathFromHash,
17
+ noop,
18
+ setInterval,
19
+ clearInterval,
20
+ isNullUndefinedDefaultValue
17
21
  } from '@cloudcare/browser-core'
18
22
 
19
23
  import { trackInitialViewTimings } from './trackInitialViewTimings'
@@ -31,64 +35,41 @@ export function trackViews(
31
35
  areViewsTrackedAutomatically,
32
36
  initialViewOptions
33
37
  ) {
34
- var _trackInitialView = trackInitialView(initialViewOptions)
35
- var stopInitialViewTracking = _trackInitialView.stop
36
- var initialView = _trackInitialView.initialView
37
- var currentView = initialView
38
-
39
- var _startViewLifeCycle = startViewLifeCycle()
40
- var stopViewLifeCycle = _startViewLifeCycle.stop
41
- var locationChangeSubscription
42
- if (areViewsTrackedAutomatically) {
43
- locationChangeSubscription = renewViewOnLocationChange(
44
- locationChangeObservable
45
- )
46
- }
47
-
48
- function trackInitialView(options) {
49
- var initialView = newView(
50
- lifeCycle,
51
- domMutationObservable,
52
- configuration,
53
- location,
54
- ViewLoadingType.INITIAL_LOAD,
55
- clocksOrigin(),
56
- options
57
- )
58
- var _trackInitialViewTimings = trackInitialViewTimings(
59
- lifeCycle,
60
- function (timings) {
61
- initialView.updateTimings(timings)
62
- initialView.scheduleUpdate()
63
- }
64
- )
65
- return { initialView: initialView, stop: _trackInitialViewTimings.stop }
66
- }
67
-
68
- function trackViewChange(startClocks, viewOptions) {
38
+ function startNewView(loadingType, startClocks, viewOptions) {
69
39
  return newView(
70
40
  lifeCycle,
71
41
  domMutationObservable,
72
42
  configuration,
73
43
  location,
74
- ViewLoadingType.ROUTE_CHANGE,
44
+ loadingType,
75
45
  startClocks,
76
46
  viewOptions
77
47
  )
78
48
  }
79
-
49
+ var currentView = startNewView(
50
+ ViewLoadingType.INITIAL_LOAD,
51
+ clocksOrigin(),
52
+ initialViewOptions
53
+ )
54
+ startViewLifeCycle()
55
+ var locationChangeSubscription
56
+ if (areViewsTrackedAutomatically) {
57
+ locationChangeSubscription = renewViewOnLocationChange(
58
+ locationChangeObservable
59
+ )
60
+ }
80
61
  function startViewLifeCycle() {
81
62
  lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
82
- // do not trigger view update to avoid wrong data
83
- currentView.end()
84
- // Renew view on session renewal
85
- currentView = trackViewChange(undefined, {
63
+ startNewView(ViewLoadingType.ROUTE_CHANGE, undefined, {
86
64
  name: currentView.name,
87
65
  service: currentView.service,
88
66
  version: currentView.version
89
67
  })
90
68
  })
91
69
 
70
+ lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
71
+ currentView.end({ sessionIsActive: false })
72
+ })
92
73
  // End the current view on page unload
93
74
  lifeCycle.subscribe(
94
75
  LifeCycleEventType.PAGE_EXITED,
@@ -98,20 +79,9 @@ export function trackViews(
98
79
  pageExitEvent.reason === PageExitReason.PAGEHIDE
99
80
  ) {
100
81
  currentView.end()
101
- currentView.triggerUpdate()
102
82
  }
103
83
  }
104
84
  )
105
- // Session keep alive
106
- var keepAliveInterval = window.setInterval(function () {
107
- currentView.triggerUpdate()
108
- }, SESSION_KEEP_ALIVE_INTERVAL)
109
-
110
- return {
111
- stop: function () {
112
- clearInterval(keepAliveInterval)
113
- }
114
- }
115
85
  }
116
86
 
117
87
  function renewViewOnLocationChange(locationChangeObservable) {
@@ -120,8 +90,7 @@ export function trackViews(
120
90
  var newLocation = params.newLocation
121
91
  if (areDifferentLocation(oldLocation, newLocation)) {
122
92
  currentView.end()
123
- currentView.triggerUpdate()
124
- currentView = trackViewChange()
93
+ currentView = startNewView(ViewLoadingType.ROUTE_CHANGE)
125
94
  return
126
95
  }
127
96
  })
@@ -133,19 +102,19 @@ export function trackViews(
133
102
  time = timeStampNow()
134
103
  }
135
104
  currentView.addTiming(name, time)
136
- currentView.scheduleUpdate()
137
105
  },
138
106
  startView: function (options, startClocks) {
139
- currentView.end(startClocks)
140
- currentView.triggerUpdate()
141
- currentView = trackViewChange(startClocks, options)
107
+ currentView.end({ endClocks: startClocks })
108
+ currentView = startNewView(
109
+ ViewLoadingType.ROUTE_CHANGE,
110
+ startClocks,
111
+ options
112
+ )
142
113
  },
143
114
  stop: function () {
144
115
  if (locationChangeSubscription) {
145
116
  locationChangeSubscription.unsubscribe()
146
117
  }
147
- stopInitialViewTracking()
148
- stopViewLifeCycle()
149
118
  currentView.end()
150
119
  }
151
120
  }
@@ -165,12 +134,12 @@ function newView(
165
134
  startClocks = clocksNow()
166
135
  }
167
136
  var id = UUID()
168
- var timings = {}
169
137
  var customTimings = {}
170
138
  var documentVersion = 0
171
139
  var endClocks
172
140
  var location = shallowClone(initialLocation)
173
141
 
142
+ var sessionIsActive = true
174
143
  var name
175
144
  var service
176
145
  var version
@@ -210,6 +179,15 @@ function newView(
210
179
  var setLoadEvent = _trackViewMetrics.setLoadEvent
211
180
  var stopViewMetricsTracking = _trackViewMetrics.stop
212
181
  var viewMetrics = _trackViewMetrics.viewMetrics
182
+
183
+ var _trackInitialViewTimings =
184
+ loadingType === ViewLoadingType.INITIAL_LOAD
185
+ ? trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate)
186
+ : { scheduleStop: noop, timings: {} }
187
+ var scheduleStopInitialViewTimingsTracking =
188
+ _trackInitialViewTimings.scheduleStop
189
+ var timings = _trackInitialViewTimings.timings
190
+
213
191
  var _trackViewEventCounts = trackViewEventCounts(
214
192
  lifeCycle,
215
193
  id,
@@ -217,10 +195,18 @@ function newView(
217
195
  )
218
196
  var scheduleStopEventCountsTracking = _trackViewEventCounts.scheduleStop
219
197
  var eventCounts = _trackViewEventCounts.eventCounts
198
+
199
+ // Session keep alive
200
+ var keepAliveIntervalId = setInterval(
201
+ triggerViewUpdate,
202
+ SESSION_KEEP_ALIVE_INTERVAL
203
+ )
220
204
  // Initial view update
221
205
  triggerViewUpdate()
222
206
 
223
207
  function triggerViewUpdate() {
208
+ cancelScheduleViewUpdate()
209
+
224
210
  documentVersion += 1
225
211
  var currentEnd =
226
212
  endClocks === undefined ? timeStampNow() : endClocks.timeStamp
@@ -240,6 +226,7 @@ function newView(
240
226
  timings: timings,
241
227
  duration: elapsed(startClocks.timeStamp, currentEnd),
242
228
  isActive: endClocks === undefined,
229
+ sessionIsActive: sessionIsActive,
243
230
  eventCounts: eventCounts
244
231
  },
245
232
  viewMetrics
@@ -252,31 +239,36 @@ function newView(
252
239
  service: service,
253
240
  version: version,
254
241
  scheduleUpdate: scheduleViewUpdate,
255
- end: function (clocks) {
256
- if (typeof clocks === 'undefined') {
257
- clocks = clocksNow()
242
+ end: function (options) {
243
+ if (endClocks) {
244
+ // view already ended
245
+ return
258
246
  }
259
- endClocks = clocks
247
+ endClocks = isNullUndefinedDefaultValue(
248
+ options && options.endClocks,
249
+ clocksNow()
250
+ )
251
+ sessionIsActive = isNullUndefinedDefaultValue(
252
+ options && options.sessionIsActive,
253
+ true
254
+ )
260
255
  lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks })
256
+ clearInterval(keepAliveIntervalId)
261
257
  stopViewMetricsTracking()
262
- scheduleStopEventCountsTracking
263
- },
264
- triggerUpdate: function () {
265
- // cancel any pending view updates execution
266
- cancelScheduleViewUpdate()
258
+ scheduleStopInitialViewTimingsTracking()
259
+ scheduleStopEventCountsTracking()
267
260
  triggerViewUpdate()
268
261
  },
269
- updateTimings: function (newTimings) {
270
- timings = newTimings
271
- if (newTimings.loadEvent !== undefined) {
272
- setLoadEvent(newTimings.loadEvent)
273
- }
274
- },
262
+
275
263
  addTiming: function (name, time) {
264
+ if (endClocks) {
265
+ return
266
+ }
276
267
  var relativeTime = looksLikeRelativeTime(time)
277
268
  ? time
278
269
  : elapsed(startClocks.timeStamp, time)
279
270
  customTimings[sanitizeTiming(name)] = relativeTime
271
+ scheduleViewUpdate()
280
272
  }
281
273
  }
282
274
  }
@@ -127,7 +127,8 @@ function processViewUpdate(view, foregroundContexts, recorderApi) {
127
127
  )
128
128
  },
129
129
  session: {
130
- has_replay: replayStats ? true : undefined
130
+ has_replay: replayStats ? true : undefined,
131
+ is_active: view.sessionIsActive ? undefined : false
131
132
  }
132
133
  }
133
134
  if (!isEmptyObject(view.customTimings)) {
@@ -52,7 +52,9 @@ export function startRumSessionManager(configuration, lifeCycle) {
52
52
  plan: plan,
53
53
  sessionReplayAllowed: plan === RumSessionPlan.WITH_SESSION_REPLAY
54
54
  }
55
- }
55
+ },
56
+ expire: sessionManager.expire,
57
+ expireObservable: sessionManager.expireObservable
56
58
  }
57
59
  }
58
60