@atlaskit/insm 0.4.54 → 0.4.55

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/insm
2
2
 
3
+ ## 0.4.55
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
3
9
  ## 0.4.54
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/insm",
3
- "version": "0.4.54",
3
+ "version": "0.4.55",
4
4
  "description": "INSM tooling measures user-perceived interactivity of a page",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@atlaskit/analytics-listeners": "^10.1.0",
29
29
  "@atlaskit/platform-feature-flags": "^1.1.0",
30
- "@atlaskit/tmp-editor-statsig": "^102.0.0",
30
+ "@atlaskit/tmp-editor-statsig": "^103.0.0",
31
31
  "@babel/runtime": "^7.0.0",
32
32
  "bowser-ultralight": "^1.0.6"
33
33
  },
@@ -1,13 +0,0 @@
1
- import type { INSMOptions } from './types';
2
- import type { INSMSession } from './insm-session';
3
- import { INSM } from './insm';
4
- /**
5
- * Initializes the INSM (Interactivity Session Measurement) tooling
6
- */
7
- export declare function init(options: INSMOptions): void;
8
- /**
9
- * **In**teractivity **s**ession **m**onitoring
10
- */
11
- export declare const insm: Pick<INSM, 'start' | 'stopEarly' | 'startHeavyTask' | 'endHeavyTask' | 'overrideExperienceKey'> & {
12
- session: Pick<INSMSession, 'details' | 'startFeature' | 'endFeature' | 'addProperties' | 'setProperty'> | undefined;
13
- };
@@ -1,37 +0,0 @@
1
- import type { Measure, PeriodMeasurer } from '../types';
2
- type Interaction = 'pointerdown' | 'pointerup' | 'click' | 'keydown' | 'keyup';
3
- type INPTrackerOptions = {
4
- /**
5
- * The interactions that should be included in the INP calculation.
6
- * If none provided then 'pointerdown', 'pointerup', 'click', 'keydown', and 'keyup' are used.
7
- */
8
- includedInteractions?: Interaction[];
9
- };
10
- export declare class INPTracker implements PeriodMeasurer {
11
- /**
12
- * INP stands for Interaction to Next Paint
13
- */
14
- name: string;
15
- monitor: InteractionTracker;
16
- includedInteractions: Interaction[];
17
- constructor(options?: INPTrackerOptions);
18
- start(paused: boolean): Measure;
19
- end(): Measure;
20
- pause(): void;
21
- resume(): void;
22
- }
23
- declare class InteractionTracker {
24
- paused: boolean;
25
- private performanceObserver;
26
- private interactionResult;
27
- private includedInteractions;
28
- constructor(includedInteractions: Interaction[]);
29
- private stopTracking;
30
- private startTracking;
31
- private reset;
32
- start(paused: boolean): Measure;
33
- end(): Measure;
34
- pause(): void;
35
- resume(): void;
36
- }
37
- export {};
@@ -1,91 +0,0 @@
1
- import type { INSMSession } from './insm-session';
2
- import type { Measure } from './types';
3
- export declare class PeriodTracking {
4
- private periodMeasurements;
5
- /**
6
- * On creation - this is set to the currently running sessions features,
7
- * and is updated throughout the period for any additional features triggered.
8
- * It is reset when starting a new period.
9
- */
10
- private latestPeriodFeatures;
11
- private latestHeavyTasks;
12
- state: 'inactive' | 'active';
13
- pauses: Set<string>;
14
- /**
15
- * Warning: this can be reset mid period when pausing/resuming.
16
- * It's intended use is to build the `periodMeasurements` duration.
17
- */
18
- private currentPeriodStart;
19
- private session;
20
- constructor(session: INSMSession);
21
- startFeature(featureName: string): void;
22
- startHeavyTask(heavyTaskName: string): void;
23
- endHeavyTask(heavyTaskName: string): void;
24
- /**
25
- * Sets a pause based on a key. If this is the first pause, then it will also halt
26
- * running interactivity measures, and update the current measurements duration.
27
- */
28
- pause(pauseName: string): void;
29
- /**
30
- * Releases a pause for a key.
31
- *
32
- * **NOTE**: The session will only resume if this was the only
33
- * currently tracked pause key.
34
- */
35
- resume(pauseName: string): void;
36
- get endResults(): {
37
- active: {
38
- count: number;
39
- duration: number;
40
- features: Set<string>;
41
- heavyTasks: Set<string>;
42
- measurements: {
43
- [key: string]: Measure;
44
- };
45
- };
46
- inactive: {
47
- count: number;
48
- duration: number;
49
- features: Set<string>;
50
- heavyTasks: Set<string>;
51
- measurements: {
52
- [key: string]: Measure;
53
- };
54
- };
55
- } | {
56
- active: {
57
- features: string[];
58
- heavyTasks: string[];
59
- measurements: {
60
- [key: string]: Measure;
61
- };
62
- duration: number;
63
- count: number;
64
- };
65
- inactive: {
66
- features: string[];
67
- heavyTasks: string[];
68
- measurements: {
69
- [key: string]: Measure;
70
- };
71
- duration: number;
72
- count: number;
73
- };
74
- };
75
- private activeStartListeners;
76
- private setupActiveStartInteractionListeners;
77
- private activeEndListeners;
78
- /**
79
- * This works by;
80
- * On setup
81
- * - starts activity listeners
82
- * - on activity received
83
- * - possible end active count down started.
84
- * 3 animation frames or 3 seconds of inactivity - whichever comes first
85
- * - any existing end count down ended
86
- */
87
- private activeEndCountDownAbortController;
88
- private activeEndCountDownVisibilityListener;
89
- private setupEndActiveInteractionListeners;
90
- private changePeriodAndTrackLast;
91
- }
@@ -1,115 +0,0 @@
1
- import type { INSM } from './insm';
2
- import type { AddedProperties, ExperienceProperties } from './types';
3
- import { PeriodTracking } from './insm-period';
4
- import { LongAnimationFrameMeasurer } from './session-measurers/LongAnimationFrameMeasurer';
5
- /**
6
- * Only intended for internal use.
7
- *
8
- * Exported for consumers who may require the type.
9
- *
10
- * Note: Events are not reliably fired from mobile browsers (ie. when a browser is closed when not in use)
11
- */
12
- export declare class INSMSession {
13
- private experienceKey;
14
- private experienceProperties;
15
- private startedAt;
16
- private pageLoadTime;
17
- insm: INSM;
18
- private running;
19
- private addedProperties;
20
- private staticProperties;
21
- runningFeatures: Set<string>;
22
- periodTracking: PeriodTracking;
23
- longAnimationFrameMeasurer: LongAnimationFrameMeasurer;
24
- constructor(experienceKey: string, experienceProperties: ExperienceProperties, insm: INSM);
25
- /**
26
- * Completes the page load timing. This is called automatically when ending a heavy task
27
- * with the key 'PageLoad'.
28
- */
29
- completePageLoad(): void;
30
- updateExperienceKey(experienceKey: string): void;
31
- /**
32
- * Adds a feature to the currently running session
33
- */
34
- startFeature(featureName: string): void;
35
- /**
36
- * Ends a features usage in the currently running session
37
- */
38
- endFeature(featureName: string): void;
39
- /**
40
- * Returns details on the current session.
41
- */
42
- get details(): {
43
- experienceKey: string;
44
- experienceProperties: ExperienceProperties;
45
- paused: boolean;
46
- periodState: 'inactive' | 'active';
47
- /**
48
- * The only scenario where this value should return false is when
49
- * the experience has been stopped early.
50
- */
51
- running: boolean;
52
- };
53
- /**
54
- * This api is an alternative to addProperties for scenarios
55
- * such as where you have a hot path that will repeatedly fire
56
- * throughout a session.
57
- * The last value for a given key will be used, and if there is a
58
- * matching key from addProperties, the addProperties value will be used.
59
- *
60
- * ```ts
61
- * insm.session.addProperties('custom:lcm', true)
62
- * ```
63
- */
64
- setProperty(key: string, value: number | string | boolean): void;
65
- /**
66
- * This api takes either a static single-level key-value object, or callbacks which return the same and
67
- * will be evaluated on session end.
68
- *
69
- * When ending a session, all properties received via this api are merged, in order, into the resulting
70
- * insm event’s properties; last write wins.
71
- *
72
- * Callback values are evaluated at session end.
73
- *
74
- * For example, for the following
75
- *
76
- * ```ts
77
- * insm.experience.addProperties({ one: 1, two: 2 });
78
- * insm.experience.addProperties(() => ({ one: 'one' }));
79
- * insm.experience.addProperties({ three: 3 });
80
- * ```
81
- *
82
- * The resulting added properties will be
83
- *
84
- * ```ts
85
- * { one: 'one', two: 2, three: 3 }
86
- * ```
87
- */
88
- addProperties(propertiesToAdd: AddedProperties): void;
89
- /**
90
- * In some scenarios (ie. when a page error boundary is hit), you will want to exit early.
91
- * This is api supports these scenarios
92
- *
93
- * ```ts
94
- * insm.stopEarly(reasonKey: string, description: string);
95
- * ```
96
- *
97
- * Sessions closed early are identifiable by their end details
98
- * `"endDetails": { stoppedBy: "early-stop", reasonKey, description }`.
99
- *
100
- * **Note**: The session is ended as soon as this is called, and any `addProperties` handlers will
101
- * called immediately.
102
- */
103
- earlyStop(reason: string, description?: string): void;
104
- end(endDetails: {
105
- contentId?: string | null;
106
- experienceKey: string;
107
- stoppedBy: 'new-experience';
108
- } | {
109
- stoppedBy: 'beforeunload';
110
- } | {
111
- description?: string;
112
- reason: string;
113
- stoppedBy: 'early-stop';
114
- }): void;
115
- }
@@ -1,70 +0,0 @@
1
- import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
2
- import { INSMSession } from './insm-session';
3
- import type { ExperienceProperties, INSMOptions } from './types';
4
- import { AnimationFPSIM } from './period-measurers/afps';
5
- import { INPTracker } from './inp-measurers/inp';
6
- export declare class INSM {
7
- analyticsWebClient?: AnalyticsWebClient;
8
- runningSession?: INSMSession;
9
- options: INSMOptions;
10
- periodMeasurers: [
11
- AnimationFPSIM,
12
- INPTracker
13
- ];
14
- /**
15
- * Heavy tasks are tracked at the insm layer as heavy tasks
16
- * are expected at times to be unrelated to the current
17
- * page session.
18
- */
19
- runningHeavyTasks: Set<string>;
20
- constructor(options: INSMOptions);
21
- /**
22
- * Starts a heavy task in the currently running session.
23
- *
24
- * This also pauses measurement.
25
- *
26
- * For PageLoads using the key 'PageLoad' will mean the heavy task duration
27
- * is added to the insm session event as pageLoadTime.
28
- */
29
- startHeavyTask(heavyTaskName: string): void;
30
- /**
31
- * Ends a heavy task in the currently running session
32
- */
33
- endHeavyTask(heavyTaskName: string): void;
34
- /**
35
- * Call this when starting a new experience. This is expected to be wired to the product
36
- * routing solution.
37
- *
38
- * It's expected this call will be paired with a `insm.session.startHeavyTask('PageLoad')` and
39
- * subsequent `insm.session.endHeavyTask('PageLoad')` so that performance degradations linked
40
- * to the page initialisation are excluded from the active interactivity monitoring.
41
- *
42
- * Using the key 'PageLoad' is special and will result in the heavy task duration being added to the
43
- * insm session event as pageLoadTime.
44
- *
45
- *
46
- * ```ts
47
- * insm.start('edit-page', { initial: true, contentId: '9001' })
48
- * insm.session.startHeavyTask('PageLoad')
49
- * // ... heavy initialisation work
50
- * insm.session.endHeavyTask('PageLoad')
51
- * ```
52
- */
53
- start(experienceKey: string, experienceProperties: ExperienceProperties): void;
54
- private lastStartedExperienceProperties;
55
- /**
56
- * Call this to update the name of the running session after it's started
57
- * In the case it's been started with an unregistered name, and there is not running
58
- * session. This will also trigger the session being started.
59
- */
60
- overrideExperienceKey(experienceKey: string): void;
61
- /**
62
- * This prematurely halts any running experience measurement. It's expected to be used in
63
- * scenarios such as when error boundaries are hit.
64
- */
65
- stopEarly(reasonKey: string, description: string): void;
66
- /**
67
- * Gets the current running session details
68
- */
69
- get session(): INSMSession | undefined;
70
- }
@@ -1,57 +0,0 @@
1
- import type { PeriodMeasurer } from '../types';
2
- export declare class AnimationFPSIM implements PeriodMeasurer {
3
- /**
4
- * AFPS stands for Animation Frames Per Second
5
- */
6
- name: string;
7
- monitor: AnimationFPSMonitor;
8
- start(paused: boolean): {
9
- numerator: number;
10
- denominator: number;
11
- max: number;
12
- min: number;
13
- average: number;
14
- };
15
- end(): {
16
- numerator: number;
17
- denominator: number;
18
- max: number;
19
- min: number;
20
- average: number;
21
- };
22
- pause(): void;
23
- resume(): void;
24
- }
25
- declare class AnimationFPSMonitor {
26
- paused: boolean;
27
- private currentState;
28
- private windowFrameCount;
29
- private windowTotalTime;
30
- private currentFrameStart;
31
- animationFrame?: ReturnType<typeof requestAnimationFrame>;
32
- private measureWindowFPS;
33
- /**
34
- * If there is running tracking - it will be reset
35
- */
36
- private startWindowTracking;
37
- startNewWindow(paused: boolean): {
38
- numerator: number;
39
- denominator: number;
40
- max: number;
41
- min: number;
42
- average: number;
43
- };
44
- private resetWindow;
45
- private endWindowTracking;
46
- private resetOverallTracking;
47
- end(): {
48
- numerator: number;
49
- denominator: number;
50
- max: number;
51
- min: number;
52
- average: number;
53
- };
54
- pause(): void;
55
- resume(): void;
56
- }
57
- export {};
@@ -1,63 +0,0 @@
1
- import type { INSMSession } from '../insm-session';
2
- type LongAnimationFrameMeasurerOptions = {
3
- initial: boolean;
4
- insmSession: INSMSession;
5
- limit: number;
6
- reportingThreshold: number;
7
- };
8
- interface TrackedScriptTiming {
9
- afDuration: number;
10
- duration: number;
11
- features: string[];
12
- forcedStyleAndLayoutDuration: number;
13
- invoker: string;
14
- invokerType: string;
15
- sourceCharPosition: number;
16
- sourceFunctionName: string;
17
- sourceURL: string;
18
- }
19
- export declare class LongAnimationFrameMeasurer {
20
- private observer?;
21
- private longestScriptTimings;
22
- private options;
23
- private paused;
24
- private minimumIndex;
25
- private minimumDuration;
26
- constructor(options: LongAnimationFrameMeasurerOptions);
27
- private handleBatch;
28
- private createScriptTiming;
29
- private processScript;
30
- /**
31
- * Pauses tracking
32
- */
33
- pause(): void;
34
- /**
35
- * Resumes tracking
36
- */
37
- resume(): void;
38
- /**
39
- * Returns the current tracked longest script timings sorted by duration
40
- */
41
- get current(): TrackedScriptTiming[];
42
- /**
43
- * Cleans up the performance tracking (tracking cannot be resumed following this).
44
- */
45
- cleanup(): void;
46
- }
47
- export interface _PerformanceScriptTiming extends PerformanceEntry {
48
- readonly duration: DOMHighResTimeStamp;
49
- readonly entryType: string;
50
- readonly executionStart: DOMHighResTimeStamp;
51
- readonly forcedStyleAndLayoutDuration: DOMHighResTimeStamp;
52
- readonly invoker: string;
53
- readonly invokerType: 'classic-script' | 'module-script' | 'event-listener' | 'user-callback' | 'resolve-promise' | 'reject-promise';
54
- readonly name: string;
55
- readonly pauseDuration: DOMHighResTimeStamp;
56
- readonly sourceCharPosition: number;
57
- readonly sourceFunctionName: string;
58
- readonly sourceURL: string;
59
- readonly startTime: DOMHighResTimeStamp;
60
- readonly window?: Window;
61
- readonly windowAttribution: 'self' | 'descendant' | 'ancestor' | 'same-page' | 'other';
62
- }
63
- export {};
@@ -1,90 +0,0 @@
1
- import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
2
- export type INSMOptions = {
3
- /**
4
- * If an experience is missing or not enabled - no session event will be fired
5
- */
6
- experiences: {
7
- [key: string]: {
8
- enabled: boolean;
9
- } | undefined;
10
- };
11
- getAnalyticsWebClient: Promise<AnalyticsWebClient>;
12
- /**
13
- * The Event Population is intended for segmenting traffic based on
14
- * overrides/segments used in Statsig for targeting.
15
- * ie. "customer-test", "internal-test", "release-tracks", "experiment-population"
16
- *
17
- * See https://console.statsig.com/LqivKg6ADZZaGczRfBKfX/dynamic_configs/cc_ufo_group
18
- * for an example dynamic config powering the Confluence population.
19
- */
20
- population?: string;
21
- };
22
- export type ExperienceProperties = {
23
- /**
24
- * An optional content id (ie. for a Confluence page - the page id)
25
- *
26
- * Leaf experiences such as the Confluence Space Overview are
27
- * not expected to provide this property.
28
- */
29
- contentId?: string | null;
30
- /**
31
- * Whether this represents the initial page the user is visiting
32
- */
33
- initial: boolean;
34
- };
35
- export type AddedProperties = {
36
- [key: string]: string | number | boolean | undefined;
37
- } | (() => {
38
- [key: string]: string | number | boolean | undefined;
39
- });
40
- export type Measure = {
41
- average: number;
42
- denominator: number;
43
- max: number;
44
- min: number;
45
- numerator: number;
46
- };
47
- export interface PeriodMeasurer {
48
- /**
49
- * Run any cleanup, and report the last periods interactivity.
50
- *
51
- * Important note: A new period can start after the end has been reached
52
- * in cases where the measurement was ended due to a scenario such as an
53
- * error boundary being hit (via `insm.stopEarly`).
54
- */
55
- end: () => Measure;
56
- /**
57
- * Name of the interactivity measurement (measures in the resulting insm event will be under this key)
58
- */
59
- name: string;
60
- /**
61
- * Pauses measurement (ie. when heavy work is triggered)
62
- */
63
- pause: () => void;
64
- /**
65
- * Pauses measurement (ie. when heavy work completes)
66
- */
67
- resume: () => void;
68
- /**
69
- * Called when an the state changes, and/or a new experience session starts.
70
- *
71
- * Implementers should take care to handle if measurements can be received after
72
- * an animation frame. In this scenario, on resetting - the consumer needs to
73
- * discard any measurements started before the reset.
74
- *
75
- * The possibility of data loss due to this is mitigated by the inactive period logic
76
- * where a session can not be marked as inactive until
77
- * - at least 3 seconds of no user activity
78
- * - and 2 animation frames since the last user activity.
79
- *
80
- * **Important** consumers need to handle starting up both initial tracking and also
81
- * when tracking is restarted after an end.
82
- *
83
- * @returns The interactivity measurements for the current period (or undefined for the initial start)
84
- */
85
- start: (
86
- /**
87
- * When started with paused = true. it indicates a heavy task is running at startup time.
88
- */
89
- paused: boolean) => Measure | undefined;
90
- }