@datadog/browser-rum-core
Advanced tools
Comparing version 4.8.1 to 4.9.0
@@ -10,3 +10,3 @@ import type { Observable } from '@datadog/browser-core'; | ||
export declare function startRum(configuration: RumConfiguration, getCommonContext: () => CommonContext, recorderApi: RecorderApi, initialViewOptions?: ViewOptions): { | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
addAction: (action: import("../domain/rumEventsCollection/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
addError: ({ error, handlingStack, startClocks, context: customerContext }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void; | ||
@@ -27,5 +27,5 @@ addTiming: (name: string, time?: import("@datadog/browser-core").TimeStamp | import("@datadog/browser-core").RelativeTime) => void; | ||
}; | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
actionContexts: import("../domain/rumEventsCollection/action/trackActions").ActionContexts; | ||
addAction: (action: import("../domain/rumEventsCollection/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
actionContexts: import("../domain/rumEventsCollection/action/trackClickActions").ActionContexts; | ||
stop: () => void; | ||
}; |
@@ -49,3 +49,3 @@ "use strict"; | ||
}, | ||
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.8.1" : undefined, | ||
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.9.0" : undefined, | ||
}, | ||
@@ -52,0 +52,0 @@ application: { |
@@ -7,3 +7,3 @@ import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core'; | ||
import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection'; | ||
import type { AutoAction } from './rumEventsCollection/action/trackActions'; | ||
import type { AutoAction } from './rumEventsCollection/action/actionCollection'; | ||
import type { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews'; | ||
@@ -10,0 +10,0 @@ export declare const enum LifeCycleEventType { |
@@ -1,8 +0,16 @@ | ||
import type { Observable } from '@datadog/browser-core'; | ||
import type { ClocksState, Context, Observable } from '@datadog/browser-core'; | ||
import type { CommonContext } from '../../../rawRumEvent.types'; | ||
import { ActionType } from '../../../rawRumEvent.types'; | ||
import type { LifeCycle } from '../../lifeCycle'; | ||
import type { ForegroundContexts } from '../../foregroundContexts'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { ActionContexts, CustomAction } from './trackActions'; | ||
import type { ActionContexts, ClickAction } from './trackClickActions'; | ||
export type { ActionContexts }; | ||
export interface CustomAction { | ||
type: ActionType.CUSTOM; | ||
name: string; | ||
startClocks: ClocksState; | ||
context?: Context; | ||
} | ||
export declare type AutoAction = ClickAction; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, foregroundContexts: ForegroundContexts): { | ||
@@ -9,0 +17,0 @@ addAction: (action: CustomAction, savedCommonContext?: CommonContext | undefined) => void; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var browser_core_1 = require("@datadog/browser-core"); | ||
var trackActions_1 = require("./trackActions"); | ||
var trackClickActions_1 = require("./trackClickActions"); | ||
function startActionCollection(lifeCycle, domMutationObservable, configuration, foregroundContexts) { | ||
@@ -13,3 +13,3 @@ lifeCycle.subscribe(1 /* AUTO_ACTION_COMPLETED */, function (action) { | ||
if (configuration.trackInteractions) { | ||
actionContexts = (0, trackActions_1.trackActions)(lifeCycle, domMutationObservable, configuration).actionContexts; | ||
actionContexts = (0, trackClickActions_1.trackClickActions)(lifeCycle, domMutationObservable, configuration).actionContexts; | ||
} | ||
@@ -30,7 +30,10 @@ return { | ||
action: { | ||
id: action.id, | ||
loading_time: (0, browser_core_1.toServerDuration)(action.duration), | ||
frustration: { | ||
type: action.frustrationTypes, | ||
}, | ||
error: { | ||
count: action.counts.errorCount, | ||
}, | ||
id: action.id, | ||
loading_time: (0, browser_core_1.toServerDuration)(action.duration), | ||
long_task: { | ||
@@ -37,0 +40,0 @@ count: action.counts.longTaskCount, |
@@ -14,3 +14,4 @@ "use strict"; | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}, | ||
@@ -17,0 +18,0 @@ }; |
@@ -24,4 +24,7 @@ "use strict"; | ||
action: { | ||
count: view.eventCounts.userActionCount, | ||
count: view.eventCounts.actionCount, | ||
}, | ||
frustration: { | ||
count: view.eventCounts.frustrationCount, | ||
}, | ||
cumulative_layout_shift: view.cumulativeLayoutShift, | ||
@@ -28,0 +31,0 @@ dom_complete: (0, browser_core_1.toServerDuration)(view.timings.domComplete), |
import type { LifeCycle } from './lifeCycle'; | ||
export interface EventCounts { | ||
errorCount: number; | ||
userActionCount: number; | ||
actionCount: number; | ||
longTaskCount: number; | ||
resourceCount: number; | ||
frustrationCount: number; | ||
} | ||
export declare function trackEventCounts(lifeCycle: LifeCycle, callback?: (eventCounts: EventCounts) => void): { | ||
stop: () => void; | ||
eventCounts: { | ||
errorCount: number; | ||
longTaskCount: number; | ||
resourceCount: number; | ||
userActionCount: number; | ||
}; | ||
eventCounts: EventCounts; | ||
}; |
@@ -11,7 +11,7 @@ "use strict"; | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}; | ||
var subscription = lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (_a) { | ||
var type = _a.type; | ||
switch (type) { | ||
var subscription = lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (event) { | ||
switch (event.type) { | ||
case "error" /* ERROR */: | ||
@@ -22,3 +22,6 @@ eventCounts.errorCount += 1; | ||
case "action" /* ACTION */: | ||
eventCounts.userActionCount += 1; | ||
eventCounts.actionCount += 1; | ||
if (event.action.frustration) { | ||
eventCounts.frustrationCount += event.action.frustration.type.length; | ||
} | ||
callback(eventCounts); | ||
@@ -25,0 +28,0 @@ break; |
@@ -79,2 +79,3 @@ import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp } from '@datadog/browser-core'; | ||
resource: Count; | ||
frustration: Count; | ||
in_foreground_periods?: InForegroundPeriod[]; | ||
@@ -124,2 +125,5 @@ }; | ||
loading_time?: ServerDuration; | ||
frustration?: { | ||
type: FrustrationType[]; | ||
}; | ||
error?: Count; | ||
@@ -140,2 +144,7 @@ long_task?: Count; | ||
} | ||
export declare const enum FrustrationType { | ||
RAGE = "rage", | ||
ERROR = "error", | ||
DEAD = "dead" | ||
} | ||
export declare type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent; | ||
@@ -142,0 +151,0 @@ export interface RumContext { |
@@ -43,5 +43,11 @@ /** | ||
/** | ||
* Action frustration types | ||
* Action frustration properties | ||
*/ | ||
readonly frustration_type?: ('rage' | 'dead' | 'error')[]; | ||
readonly frustration?: { | ||
/** | ||
* Action frustration types | ||
*/ | ||
readonly type: ('rage' | 'dead' | 'error')[]; | ||
[k: string]: unknown; | ||
}; | ||
/** | ||
@@ -522,2 +528,12 @@ * Properties of the errors of the action | ||
/** | ||
* Properties of the frustrations of the view | ||
*/ | ||
readonly frustration?: { | ||
/** | ||
* Number of frustrations that occurred on the view | ||
*/ | ||
readonly count: number; | ||
[k: string]: unknown; | ||
}; | ||
/** | ||
* List of the periods of time the user had the view in foreground (focused in the browser) | ||
@@ -524,0 +540,0 @@ */ |
@@ -10,3 +10,3 @@ import type { Observable } from '@datadog/browser-core'; | ||
export declare function startRum(configuration: RumConfiguration, getCommonContext: () => CommonContext, recorderApi: RecorderApi, initialViewOptions?: ViewOptions): { | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
addAction: (action: import("../domain/rumEventsCollection/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
addError: ({ error, handlingStack, startClocks, context: customerContext }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void; | ||
@@ -27,5 +27,5 @@ addTiming: (name: string, time?: import("@datadog/browser-core").TimeStamp | import("@datadog/browser-core").RelativeTime) => void; | ||
}; | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
actionContexts: import("../domain/rumEventsCollection/action/trackActions").ActionContexts; | ||
addAction: (action: import("../domain/rumEventsCollection/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void; | ||
actionContexts: import("../domain/rumEventsCollection/action/trackClickActions").ActionContexts; | ||
stop: () => void; | ||
}; |
@@ -46,3 +46,3 @@ import { combine, isEmptyObject, limitModification, timeStampNow, currentDrift, display, createEventRateLimiter, canUseEventBridge, isExperimentalFeatureEnabled, } from '@datadog/browser-core'; | ||
}, | ||
browser_sdk_version: canUseEventBridge() ? "4.8.1" : undefined, | ||
browser_sdk_version: canUseEventBridge() ? "4.9.0" : undefined, | ||
}, | ||
@@ -49,0 +49,0 @@ application: { |
@@ -7,3 +7,3 @@ import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core'; | ||
import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection'; | ||
import type { AutoAction } from './rumEventsCollection/action/trackActions'; | ||
import type { AutoAction } from './rumEventsCollection/action/actionCollection'; | ||
import type { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews'; | ||
@@ -10,0 +10,0 @@ export declare const enum LifeCycleEventType { |
@@ -1,8 +0,16 @@ | ||
import type { Observable } from '@datadog/browser-core'; | ||
import type { ClocksState, Context, Observable } from '@datadog/browser-core'; | ||
import type { CommonContext } from '../../../rawRumEvent.types'; | ||
import { ActionType } from '../../../rawRumEvent.types'; | ||
import type { LifeCycle } from '../../lifeCycle'; | ||
import type { ForegroundContexts } from '../../foregroundContexts'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { ActionContexts, CustomAction } from './trackActions'; | ||
import type { ActionContexts, ClickAction } from './trackClickActions'; | ||
export type { ActionContexts }; | ||
export interface CustomAction { | ||
type: ActionType.CUSTOM; | ||
name: string; | ||
startClocks: ClocksState; | ||
context?: Context; | ||
} | ||
export declare type AutoAction = ClickAction; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, foregroundContexts: ForegroundContexts): { | ||
@@ -9,0 +17,0 @@ addAction: (action: CustomAction, savedCommonContext?: CommonContext | undefined) => void; |
import { noop, assign, combine, toServerDuration, generateUUID } from '@datadog/browser-core'; | ||
import { trackActions } from './trackActions'; | ||
import { trackClickActions } from './trackClickActions'; | ||
export function startActionCollection(lifeCycle, domMutationObservable, configuration, foregroundContexts) { | ||
@@ -9,3 +9,3 @@ lifeCycle.subscribe(1 /* AUTO_ACTION_COMPLETED */, function (action) { | ||
if (configuration.trackInteractions) { | ||
actionContexts = trackActions(lifeCycle, domMutationObservable, configuration).actionContexts; | ||
actionContexts = trackClickActions(lifeCycle, domMutationObservable, configuration).actionContexts; | ||
} | ||
@@ -25,7 +25,10 @@ return { | ||
action: { | ||
id: action.id, | ||
loading_time: toServerDuration(action.duration), | ||
frustration: { | ||
type: action.frustrationTypes, | ||
}, | ||
error: { | ||
count: action.counts.errorCount, | ||
}, | ||
id: action.id, | ||
loading_time: toServerDuration(action.duration), | ||
long_task: { | ||
@@ -32,0 +35,0 @@ count: action.counts.longTaskCount, |
@@ -11,3 +11,4 @@ import { noop, round, ONE_SECOND, elapsed } from '@datadog/browser-core'; | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}, | ||
@@ -14,0 +15,0 @@ }; |
@@ -20,4 +20,7 @@ import { isEmptyObject, mapValues, toServerDuration, isNumber } from '@datadog/browser-core'; | ||
action: { | ||
count: view.eventCounts.userActionCount, | ||
count: view.eventCounts.actionCount, | ||
}, | ||
frustration: { | ||
count: view.eventCounts.frustrationCount, | ||
}, | ||
cumulative_layout_shift: view.cumulativeLayoutShift, | ||
@@ -24,0 +27,0 @@ dom_complete: toServerDuration(view.timings.domComplete), |
import type { LifeCycle } from './lifeCycle'; | ||
export interface EventCounts { | ||
errorCount: number; | ||
userActionCount: number; | ||
actionCount: number; | ||
longTaskCount: number; | ||
resourceCount: number; | ||
frustrationCount: number; | ||
} | ||
export declare function trackEventCounts(lifeCycle: LifeCycle, callback?: (eventCounts: EventCounts) => void): { | ||
stop: () => void; | ||
eventCounts: { | ||
errorCount: number; | ||
longTaskCount: number; | ||
resourceCount: number; | ||
userActionCount: number; | ||
}; | ||
eventCounts: EventCounts; | ||
}; |
@@ -8,7 +8,7 @@ import { noop } from '@datadog/browser-core'; | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}; | ||
var subscription = lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (_a) { | ||
var type = _a.type; | ||
switch (type) { | ||
var subscription = lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (event) { | ||
switch (event.type) { | ||
case "error" /* ERROR */: | ||
@@ -19,3 +19,6 @@ eventCounts.errorCount += 1; | ||
case "action" /* ACTION */: | ||
eventCounts.userActionCount += 1; | ||
eventCounts.actionCount += 1; | ||
if (event.action.frustration) { | ||
eventCounts.frustrationCount += event.action.frustration.type.length; | ||
} | ||
callback(eventCounts); | ||
@@ -22,0 +25,0 @@ break; |
@@ -79,2 +79,3 @@ import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp } from '@datadog/browser-core'; | ||
resource: Count; | ||
frustration: Count; | ||
in_foreground_periods?: InForegroundPeriod[]; | ||
@@ -124,2 +125,5 @@ }; | ||
loading_time?: ServerDuration; | ||
frustration?: { | ||
type: FrustrationType[]; | ||
}; | ||
error?: Count; | ||
@@ -140,2 +144,7 @@ long_task?: Count; | ||
} | ||
export declare const enum FrustrationType { | ||
RAGE = "rage", | ||
ERROR = "error", | ||
DEAD = "dead" | ||
} | ||
export declare type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent; | ||
@@ -142,0 +151,0 @@ export interface RumContext { |
@@ -43,5 +43,11 @@ /** | ||
/** | ||
* Action frustration types | ||
* Action frustration properties | ||
*/ | ||
readonly frustration_type?: ('rage' | 'dead' | 'error')[]; | ||
readonly frustration?: { | ||
/** | ||
* Action frustration types | ||
*/ | ||
readonly type: ('rage' | 'dead' | 'error')[]; | ||
[k: string]: unknown; | ||
}; | ||
/** | ||
@@ -522,2 +528,12 @@ * Properties of the errors of the action | ||
/** | ||
* Properties of the frustrations of the view | ||
*/ | ||
readonly frustration?: { | ||
/** | ||
* Number of frustrations that occurred on the view | ||
*/ | ||
readonly count: number; | ||
[k: string]: unknown; | ||
}; | ||
/** | ||
* List of the periods of time the user had the view in foreground (focused in the browser) | ||
@@ -524,0 +540,0 @@ */ |
{ | ||
"name": "@datadog/browser-rum-core", | ||
"version": "4.8.1", | ||
"version": "4.9.0", | ||
"license": "Apache-2.0", | ||
@@ -15,3 +15,3 @@ "main": "cjs/index.js", | ||
"dependencies": { | ||
"@datadog/browser-core": "4.8.1" | ||
"@datadog/browser-core": "4.9.0" | ||
}, | ||
@@ -26,3 +26,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "2ea26257558080f3072c3e3654df1f033268e7cb" | ||
"gitHead": "c642198789f3f9c1d399cc00527437376b6f210c" | ||
} |
@@ -7,3 +7,3 @@ import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core' | ||
import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection' | ||
import type { AutoAction } from './rumEventsCollection/action/trackActions' | ||
import type { AutoAction } from './rumEventsCollection/action/actionCollection' | ||
import type { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews' | ||
@@ -10,0 +10,0 @@ |
@@ -35,2 +35,3 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' | ||
}, | ||
frustrationTypes: [], | ||
duration: 100 as Duration, | ||
@@ -52,2 +53,5 @@ id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', | ||
loading_time: (100 * 1e6) as ServerDuration, | ||
frustration: { | ||
type: [], | ||
}, | ||
long_task: { | ||
@@ -54,0 +58,0 @@ count: 10, |
@@ -1,2 +0,2 @@ | ||
import type { Observable } from '@datadog/browser-core' | ||
import type { ClocksState, Context, Observable } from '@datadog/browser-core' | ||
import { noop, assign, combine, toServerDuration, generateUUID } from '@datadog/browser-core' | ||
@@ -10,7 +10,16 @@ | ||
import type { RumConfiguration } from '../../configuration' | ||
import type { ActionContexts, AutoAction, CustomAction } from './trackActions' | ||
import { trackActions } from './trackActions' | ||
import type { ActionContexts, ClickAction } from './trackClickActions' | ||
import { trackClickActions } from './trackClickActions' | ||
export type { ActionContexts } | ||
export interface CustomAction { | ||
type: ActionType.CUSTOM | ||
name: string | ||
startClocks: ClocksState | ||
context?: Context | ||
} | ||
export type AutoAction = ClickAction | ||
export function startActionCollection( | ||
@@ -28,3 +37,3 @@ lifeCycle: LifeCycle, | ||
if (configuration.trackInteractions) { | ||
actionContexts = trackActions(lifeCycle, domMutationObservable, configuration).actionContexts | ||
actionContexts = trackClickActions(lifeCycle, domMutationObservable, configuration).actionContexts | ||
} | ||
@@ -55,7 +64,10 @@ | ||
action: { | ||
id: action.id, | ||
loading_time: toServerDuration(action.duration), | ||
frustration: { | ||
type: action.frustrationTypes, | ||
}, | ||
error: { | ||
count: action.counts.errorCount, | ||
}, | ||
id: action.id, | ||
loading_time: toServerDuration(action.duration), | ||
long_task: { | ||
@@ -62,0 +74,0 @@ count: action.counts.longTaskCount, |
@@ -7,3 +7,3 @@ import type { Context, RelativeTime, Duration } from '@datadog/browser-core' | ||
import type { RumPerformanceNavigationTiming } from '../../../browser/performanceCollection' | ||
import { RumEventType } from '../../../rawRumEvent.types' | ||
import { FrustrationType, RumEventType } from '../../../rawRumEvent.types' | ||
import type { LifeCycle } from '../../lifeCycle' | ||
@@ -228,12 +228,38 @@ import { LifeCycleEventType } from '../../lifeCycle' | ||
expect(getViewUpdateCount()).toEqual(1) | ||
expect(getViewUpdate(0).eventCounts.userActionCount).toEqual(0) | ||
expect(getViewUpdate(0).eventCounts.actionCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { type: RumEventType.ACTION } as RumEvent & Context) | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { | ||
type: RumEventType.ACTION, | ||
action: { type: 'custom' }, | ||
} as RumEvent & Context) | ||
startView() | ||
expect(getViewUpdateCount()).toEqual(3) | ||
expect(getViewUpdate(1).eventCounts.userActionCount).toEqual(1) | ||
expect(getViewUpdate(2).eventCounts.userActionCount).toEqual(0) | ||
expect(getViewUpdate(1).eventCounts.actionCount).toEqual(1) | ||
expect(getViewUpdate(2).eventCounts.actionCount).toEqual(0) | ||
}) | ||
it('should track frustration count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
const { getViewUpdate, getViewUpdateCount, startView } = viewTest | ||
expect(getViewUpdateCount()).toEqual(1) | ||
expect(getViewUpdate(0).eventCounts.frustrationCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { | ||
type: RumEventType.ACTION, | ||
action: { | ||
type: 'click', | ||
frustration: { | ||
type: [FrustrationType.DEAD, FrustrationType.ERROR], | ||
}, | ||
}, | ||
} as RumEvent & Context) | ||
startView() | ||
expect(getViewUpdateCount()).toEqual(3) | ||
expect(getViewUpdate(1).eventCounts.frustrationCount).toEqual(2) | ||
expect(getViewUpdate(2).eventCounts.frustrationCount).toEqual(0) | ||
}) | ||
it('should reset event count when the view changes', () => { | ||
@@ -271,3 +297,4 @@ const { lifeCycle, changeLocation } = setupBuilder.build() | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}) | ||
@@ -286,3 +313,4 @@ | ||
resourceCount: 1, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}) | ||
@@ -289,0 +317,0 @@ }) |
@@ -30,3 +30,4 @@ import type { Duration, RelativeTime, Observable, ClocksState } from '@datadog/browser-core' | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
}, | ||
@@ -33,0 +34,0 @@ } |
@@ -23,3 +23,4 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' | ||
resourceCount: 10, | ||
userActionCount: 10, | ||
actionCount: 10, | ||
frustrationCount: 10, | ||
}, | ||
@@ -93,2 +94,5 @@ id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', | ||
}, | ||
frustration: { | ||
count: 10, | ||
}, | ||
cumulative_layout_shift: 1, | ||
@@ -95,0 +99,0 @@ custom_timings: { |
@@ -56,4 +56,7 @@ import type { Duration, ServerDuration, Observable } from '@datadog/browser-core' | ||
action: { | ||
count: view.eventCounts.userActionCount, | ||
count: view.eventCounts.actionCount, | ||
}, | ||
frustration: { | ||
count: view.eventCounts.frustrationCount, | ||
}, | ||
cumulative_layout_shift: view.cumulativeLayoutShift, | ||
@@ -60,0 +63,0 @@ dom_complete: toServerDuration(view.timings.domComplete), |
import type { Context } from '@datadog/browser-core' | ||
import { objectValues } from '@datadog/browser-core' | ||
import type { RumEvent } from '../rumEvent.types' | ||
import { RumEventType } from '../rawRumEvent.types' | ||
import { FrustrationType, RumEventType } from '../rawRumEvent.types' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
@@ -16,4 +16,4 @@ import type { EventCounts } from './trackEventCounts' | ||
function notifyCollectedRawRumEvent(type: RumEventType) { | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { type } as RumEvent & Context) | ||
function notifyCollectedRawRumEvent(partialEvent: Partial<RumEvent>) { | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, partialEvent as RumEvent & Context) | ||
} | ||
@@ -23,3 +23,3 @@ | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.ERROR) | ||
notifyCollectedRawRumEvent({ type: RumEventType.ERROR }) | ||
expect(eventCounts.errorCount).toBe(1) | ||
@@ -30,3 +30,3 @@ }) | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.LONG_TASK) | ||
notifyCollectedRawRumEvent({ type: RumEventType.LONG_TASK }) | ||
expect(eventCounts.longTaskCount).toBe(1) | ||
@@ -37,4 +37,4 @@ }) | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.VIEW) | ||
expect(objectValues(eventCounts).every((value) => value === 0)).toBe(true) | ||
notifyCollectedRawRumEvent({ type: RumEventType.VIEW }) | ||
expect(objectValues(eventCounts as unknown as { [key: string]: number }).every((value) => value === 0)).toBe(true) | ||
}) | ||
@@ -44,4 +44,4 @@ | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.ACTION) | ||
expect(eventCounts.userActionCount).toBe(1) | ||
notifyCollectedRawRumEvent({ type: RumEventType.ACTION, action: { type: 'custom' } }) | ||
expect(eventCounts.actionCount).toBe(1) | ||
}) | ||
@@ -51,12 +51,26 @@ | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
notifyCollectedRawRumEvent({ type: RumEventType.RESOURCE }) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
}) | ||
it('tracks frustration counts', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent({ | ||
type: RumEventType.ACTION, | ||
action: { | ||
type: 'click', | ||
frustration: { | ||
type: [FrustrationType.ERROR, FrustrationType.DEAD], | ||
}, | ||
}, | ||
}) | ||
expect(eventCounts.frustrationCount).toBe(2) | ||
}) | ||
it('stops tracking when stop is called', () => { | ||
const { eventCounts, stop } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
notifyCollectedRawRumEvent({ type: RumEventType.RESOURCE }) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
stop() | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
notifyCollectedRawRumEvent({ type: RumEventType.RESOURCE }) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
@@ -69,7 +83,7 @@ }) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
notifyCollectedRawRumEvent({ type: RumEventType.RESOURCE }) | ||
expect(spy).toHaveBeenCalledTimes(1) | ||
expect(spy.calls.mostRecent().args[0].resourceCount).toBe(1) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
notifyCollectedRawRumEvent({ type: RumEventType.RESOURCE }) | ||
expect(spy).toHaveBeenCalledTimes(2) | ||
@@ -76,0 +90,0 @@ expect(spy.calls.mostRecent().args[0].resourceCount).toBe(2) |
@@ -8,17 +8,19 @@ import { noop } from '@datadog/browser-core' | ||
errorCount: number | ||
userActionCount: number | ||
actionCount: number | ||
longTaskCount: number | ||
resourceCount: number | ||
frustrationCount: number | ||
} | ||
export function trackEventCounts(lifeCycle: LifeCycle, callback: (eventCounts: EventCounts) => void = noop) { | ||
const eventCounts = { | ||
const eventCounts: EventCounts = { | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
actionCount: 0, | ||
frustrationCount: 0, | ||
} | ||
const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, ({ type }): void => { | ||
switch (type) { | ||
const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event): void => { | ||
switch (event.type) { | ||
case RumEventType.ERROR: | ||
@@ -29,3 +31,6 @@ eventCounts.errorCount += 1 | ||
case RumEventType.ACTION: | ||
eventCounts.userActionCount += 1 | ||
eventCounts.actionCount += 1 | ||
if (event.action.frustration) { | ||
eventCounts.frustrationCount += event.action.frustration.type.length | ||
} | ||
callback(eventCounts) | ||
@@ -32,0 +37,0 @@ break |
@@ -92,2 +92,3 @@ import type { | ||
resource: Count | ||
frustration: Count | ||
in_foreground_periods?: InForegroundPeriod[] | ||
@@ -144,2 +145,5 @@ } | ||
loading_time?: ServerDuration | ||
frustration?: { | ||
type: FrustrationType[] | ||
} | ||
error?: Count | ||
@@ -162,2 +166,8 @@ long_task?: Count | ||
export const enum FrustrationType { | ||
RAGE = 'rage', | ||
ERROR = 'error', | ||
DEAD = 'dead', | ||
} | ||
export type RawRumEvent = | ||
@@ -164,0 +174,0 @@ | RawRumErrorEvent |
@@ -45,5 +45,11 @@ /* eslint-disable */ | ||
/** | ||
* Action frustration types | ||
* Action frustration properties | ||
*/ | ||
readonly frustration_type?: ('rage' | 'dead' | 'error')[] | ||
readonly frustration?: { | ||
/** | ||
* Action frustration types | ||
*/ | ||
readonly type: ('rage' | 'dead' | 'error')[] | ||
[k: string]: unknown | ||
} | ||
/** | ||
@@ -574,2 +580,12 @@ * Properties of the errors of the action | ||
/** | ||
* Properties of the frustrations of the view | ||
*/ | ||
readonly frustration?: { | ||
/** | ||
* Number of frustrations that occurred on the view | ||
*/ | ||
readonly count: number | ||
[k: string]: unknown | ||
} | ||
/** | ||
* List of the periods of time the user had the view in foreground (focused in the browser) | ||
@@ -576,0 +592,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1063568
332
21794
+ Added@datadog/browser-core@4.9.0(transitive)
- Removed@datadog/browser-core@4.8.1(transitive)
Updated@datadog/browser-core@4.9.0