Skip to content

Commit 0f7f090

Browse files
committed
chore: more cleanup
1 parent cae851c commit 0f7f090

8 files changed

+12
-130
lines changed

Diff for: __tests__/userJourney/measureUserJourneyStep.ts

+1-56
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ describe('measureUserJourneyStep', () => {
1313
let spy: jest.SpyInstance;
1414
let analyticsTrackerSpy: jest.SpyInstance;
1515
let measureSpy: jest.SpyInstance;
16-
let onMarkJourneySpy: jest.SpyInstance;
1716

1817
beforeEach(() => {
1918
(WP as any) = mock.performance();
20-
const perfume = new Perfume(testConfig);
19+
new Perfume(testConfig);
2120
});
2221

2322
afterEach(() => {
@@ -139,59 +138,5 @@ describe('measureUserJourneyStep', () => {
139138
},
140139
});
141140
});
142-
143-
it('should run analyticsTracker with duration starting from App launch', async () => {
144-
config.analyticsTracker = () => {};
145-
spy = jest.spyOn(WP, 'mark');
146-
measureSpy = jest.spyOn(WP, 'measure');
147-
analyticsTrackerSpy = jest.spyOn(config, 'analyticsTracker');
148-
// ============ Mock Data ============
149-
jest.spyOn(WP, 'getEntriesByName').mockImplementation(name =>
150-
name === 'mark.loaded_first_screen_first_journey'
151-
? [
152-
{
153-
name: 'mark.loaded_first_screen_first_journey',
154-
entryType: 'mark',
155-
duration: 0,
156-
startTime: 0,
157-
toJSON: jest.fn(),
158-
},
159-
]
160-
: [],
161-
);
162-
jest.spyOn(WP, 'measure').mockImplementationOnce(() => ({
163-
name: 'mark.loaded_first_screen_first_journey',
164-
entryType: 'mark',
165-
duration: 2000,
166-
startTime: 0,
167-
toJSON: jest.fn(),
168-
detail: '',
169-
}));
170-
171-
// ========== Mock Data end ==========
172-
markJourney('loaded_first_screen_first_journey');
173-
// we wait for promises to flush since getting the launch time duration is async
174-
await Promise.resolve();
175-
expect(spy.mock.calls.length).toBe(1);
176-
expect(spy).toHaveBeenLastCalledWith(
177-
'mark.loaded_first_screen_first_journey',
178-
);
179-
expect(measureSpy).toHaveBeenCalledTimes(1);
180-
expect(analyticsTrackerSpy).toHaveBeenCalledTimes(1);
181-
expect(analyticsTrackerSpy).toHaveBeenLastCalledWith({
182-
metricName: 'load_first_screen_first_journey',
183-
rating: 'good',
184-
data: 2000,
185-
attribution: { category: 'step' },
186-
navigationType: undefined,
187-
navigatorInformation: {
188-
deviceMemory: 0,
189-
hardwareConcurrency: 8,
190-
isLowEndDevice: false,
191-
isLowEndExperience: false,
192-
serviceWorkerStatus: 'unsupported',
193-
},
194-
});
195-
});
196141
});
197142
});

Diff for: __tests__/userJourneyTestConstants.ts

+1-25
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
IPerfumeOptions,
66
IPerfumeConfig,
77
IThresholdTier,
8-
IUserJourneyConfig,
98
IUserJourneyStepsConfig,
109
} from '../src/types';
1110

12-
export const USER_JOURNEY_THRESHOLDS: IUserJourneyThresholds = {
11+
export const STEP_THRESHOLDS: IUserJourneyThresholds = {
1312
[IThresholdTier.instant]: {
1413
vitalsThresholds: [100, 200],
1514
maxOutlierThreshold: 10000,
@@ -31,30 +30,8 @@ export const USER_JOURNEY_THRESHOLDS: IUserJourneyThresholds = {
3130
maxOutlierThreshold: 20000,
3231
},
3332
};
34-
const userJourneys: IUserJourneyConfig = {
35-
first_journey: {
36-
steps: [
37-
'load_first_screen_first_journey',
38-
'load_second_screen_first_journey',
39-
'load_third_screen_first_journey',
40-
'load_fourth_screen_first_journey',
41-
],
42-
},
43-
second_journey: {
44-
steps: [
45-
'load_first_screen_second_journey',
46-
'load_second_screen_second_journey',
47-
'load_third_screen_second_journey',
48-
'load_fourth_screen_second_journey',
49-
],
50-
},
51-
};
5233

5334
const userJourneySteps: IUserJourneyStepsConfig = {
54-
load_first_screen_first_journey: {
55-
threshold: IThresholdTier.unavoidable,
56-
marks: ['launch', 'loaded_first_screen_first_journey'],
57-
},
5835
load_second_screen_first_journey: {
5936
threshold: IThresholdTier.instant,
6037
marks: [
@@ -104,7 +81,6 @@ const userJourneySteps: IUserJourneyStepsConfig = {
10481
};
10582

10683
export const testConfig: IPerfumeOptions = {
107-
userJourneys,
10884
userJourneySteps,
10985
onMarkJourney: jest.fn(),
11086
};

Diff for: src/perfume.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
let ntbtTimeoutID = 0;
2828

2929
export default class Perfume {
30-
v = '8.3.0';
30+
v = '8.4.0';
3131

3232
constructor(options: IPerfumeOptions = {}) {
3333
// Extend default config with external options
@@ -37,7 +37,6 @@ export default class Perfume {
3737
config.maxTime = options.maxMeasureTime || config.maxTime;
3838
config.reportOptions = options.reportOptions || config.reportOptions;
3939
config.userJourneySteps = options.userJourneySteps;
40-
config.userJourneys = options.userJourneys;
4140
config.onMarkJourney = options.onMarkJourney;
4241

4342
// Exit from Perfume when basic Web Performance APIs aren't supported
@@ -73,7 +72,7 @@ export default class Perfume {
7372
WN.storage.estimate().then(reportStorageEstimate);
7473
}
7574
// initializing User Journeys if present
76-
if (config.userJourneys && config.userJourneySteps) {
75+
if (config.userJourneySteps) {
7776
setUserJourneyStepsMap();
7877
setUserJourneyFinalStepsMap();
7978
}

Diff for: src/userJourney/getJourneyStepVitalMetricName.ts

-6
This file was deleted.

Diff for: src/userJourney/measureJourneyStep.ts

+5-34
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,25 @@ import { M, S, WP } from '../constants';
22
import { reportPerf } from '../reportPerf';
33
import { config } from '../config';
44

5-
import { USER_JOURNEY_THRESHOLDS } from '../vitalsScore';
5+
import { STEP_THRESHOLDS } from '../vitalsScore';
66
import { getRating } from '../vitalsScore';
7-
import { getJourneyStepVitalMetricName } from './getJourneyStepVitalMetricName';
87

98
export const measureJourneyStep = (
109
step: string,
1110
startMark: string,
1211
endMark: string,
1312
) => {
1413
const journeyStepMetricName = S + step;
15-
const isLaunchJourney = startMark === 'launch';
1614
const startMarkExists = WP.getEntriesByName(M + startMark).length > 0;
1715
const endMarkExists = WP.getEntriesByName(M + endMark).length > 0;
1816
if (!endMarkExists || !config.userJourneySteps) {
1917
return;
2018
}
2119

2220
const { maxOutlierThreshold, vitalsThresholds } =
23-
USER_JOURNEY_THRESHOLDS[config.userJourneySteps[step].threshold];
21+
STEP_THRESHOLDS[config.userJourneySteps[step].threshold];
2422

25-
if (isLaunchJourney) {
26-
const duration = 0;
27-
const journeyStepMeasure = WP.measure(journeyStepMetricName, {
28-
duration,
29-
end: M + endMark,
30-
});
31-
const score = getRating(duration, vitalsThresholds);
32-
// Do not want to measure or log negative metrics
33-
if (duration >= 0) {
34-
reportPerf(
35-
step,
36-
journeyStepMeasure.duration,
37-
score,
38-
{ category: 'step' },
39-
undefined,
40-
);
41-
}
42-
} else if (startMarkExists) {
23+
if (startMarkExists) {
4324
const journeyStepMeasure = WP.measure(
4425
journeyStepMetricName,
4526
M + startMark,
@@ -50,18 +31,8 @@ export const measureJourneyStep = (
5031
const score = getRating(duration, vitalsThresholds);
5132
// Do not want to measure or log negative metrics
5233
if (duration >= 0) {
53-
reportPerf(
54-
step,
55-
duration,
56-
score,
57-
{ category: 'step' },
58-
undefined,
59-
);
60-
const journeyStepVitalMetricName = getJourneyStepVitalMetricName(
61-
step,
62-
score,
63-
);
64-
WP.measure(journeyStepVitalMetricName, {
34+
reportPerf(step, duration, score, { category: 'step' }, undefined);
35+
WP.measure(`user_journey_step.${step}_vitals_${score}`, {
6536
start: journeyStepMeasure.startTime + journeyStepMeasure.duration,
6637
end: journeyStepMeasure.startTime + journeyStepMeasure.duration,
6738
detail: {

Diff for: src/userJourney/measureJourneySteps.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export const measureJourneySteps = (endMark: string) => {
1515
Object.keys(finalSteps).forEach(startMark => {
1616
const steps = finalSteps[startMark];
1717
steps.forEach(removeActiveStep);
18-
1918
Promise.all(
2019
steps.map(async step => {
2120
// measure

Diff for: src/userJourney/userJourneyMap.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export const userJourneyMap = {
66
};
77

88
/**
9-
* this method allows to add new steps by passing the start mark
10-
*
9+
* This method allows to add new steps by passing the start mark
1110
*/
1211
export const addActiveSteps = (startMark: string) => {
1312
const newSteps = userJourneyMap.startMarkToStepsMap[startMark] ?? [];
@@ -22,8 +21,7 @@ export const addActiveSteps = (startMark: string) => {
2221
};
2322

2423
/**
25-
* removes one step from active steps
26-
*
24+
* Removes one step from active steps
2725
*/
2826
export const removeActiveStep = (step: string) => {
2927
delete userJourneyMap.activeSteps[step];

Diff for: src/vitalsScore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const rtScore = [100, 200];
99
const tbtScore = [200, 600];
1010
const ntbtScore = [200, 600];
1111

12-
export const USER_JOURNEY_THRESHOLDS: IUserJourneyThresholds = {
12+
export const STEP_THRESHOLDS: IUserJourneyThresholds = {
1313
[IThresholdTier.instant]: {
1414
vitalsThresholds: [100, 200],
1515
maxOutlierThreshold: 10000,

0 commit comments

Comments
 (0)