Skip to content

Commit 273ac77

Browse files
authored
chore: rename 'incrementUjNavigation' to 'trackUJNavigation' (#235)
1 parent 0bff39c commit 273ac77

9 files changed

+42
-56
lines changed

Diff for: README.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ initPerfume({
100100
data,
101101
navigatorInformation,
102102
rating,
103-
navigationType
103+
navigationType,
104104
} = options;
105105
switch (metricName) {
106106
case 'navigationTiming':
@@ -147,7 +147,7 @@ initPerfume({
147147
myAnalyticsTool.track('userJourneyStep', {
148148
duration: data,
149149
stepName: attribution.step_name,
150-
vitals_score: rating
150+
vitals_score: rating,
151151
});
152152
break;
153153
default:
@@ -398,11 +398,12 @@ const ScreenB = () => {
398398
```
399399

400400
#### Defining Steps
401+
401402
In order for Perfume to be able to track metrics for Steps, we need to configure the steps and provide them when initializing Perfume.
402403

403404
Below you can find an example of how to do this.
404405

405-
``` typescript
406+
```typescript
406407
export const steps = {
407408
load_screen_A: {
408409
threshold: ThresholdTier.quick,
@@ -415,33 +416,31 @@ export const steps = {
415416
};
416417

417418
initPerfume({ steps });
418-
419419
```
420420

421421
#### MarkStep
422+
422423
`markStep` is the function used to start and end steps in applications.
423424

424425
For example, if we wanted to mark the beginning of load_screen_B step above, we would add in `markStep('navigate_to_screen_B')` to our code.
425426

426-
#### `enableNavigationTracking`
427+
#### `trackUJNavigation`
427428

428-
`enableNavigationTracking` is a boolean in the config that will tell Perfume to take into account page navigation changes or not. By default this is `true`, but it can be set to false if needed.
429-
430-
The purpose of this feature is to only account for active steps that the user is working on. The feature will remove any inactive or 'stale' steps that are not currently in progress.
429+
The purpose of this function is to only account for active steps that the user is working on. The feature will remove any inactive or 'stale' steps that are not currently in progress.
431430

432431
Stale steps can be created by navigating away from a page before it fully loads, this would cause the start mark to be triggered, but the end mark to not be called. This would affect the `active` steps being returned to `onMarkStep` as well as would create incorrect data if we returned back to the end mark much later than expected.
433432

434-
`enableNavigationTracking` works together with the `incrementUjNavigation` function. The `incrementUjNavigation` function is to be called anytime there is a navigation change in your application. Below is an example for how this would work in a React Application:
433+
The `trackUJNavigation` function is to be called anytime there is a navigation change in your application. Below is an example for how this would work in a React Application:
435434

436-
``` typescript
435+
```typescript
437436
import { useLocation } from 'react-router-dom';
438437

439438
const MyComponent = () => {
440439
const location = useLocation()
441440

442441
React.useEffect(() => {
443442
// runs on location, i.e. route, change
444-
incrementUjNavigation();
443+
trackUJNavigation();
445444
}, [location])
446445
...
447446
}
@@ -476,7 +475,6 @@ Below are the thresholds available for each step:
476475
| SLOW | [1000, 2000] |
477476
| UNAVOIDABLE | [2000, 5000] |
478477

479-
480478
## Perfume custom options
481479

482480
Default options provided to Perfume.js constructor.

Diff for: __tests__/steps/navSteps.spec.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import { WP } from '../../src/constants';
55
import mock from '../_mock';
66
import { initPerfume } from '../../src/initPerfume';
77
import { markStep } from '../../src/steps/markStep';
8-
import {
9-
getNavigationState
10-
} from '../../src/steps/steps';
8+
import { getNavigationState } from '../../src/steps/steps';
119
import {
1210
getActiveStepsFromNavigationSteps,
13-
incrementUjNavigation,
11+
trackUJNavigation,
1412
} from '../../src/steps/navigationSteps';
1513

1614
import { navigationTestConfig } from '../stepsTestConstants';
@@ -55,9 +53,9 @@ describe('navSteps', () => {
5553
});
5654

5755
it('incrementCujNavigation the navigation state on page navigations', () => {
58-
incrementUjNavigation();
56+
trackUJNavigation();
5957
expect(getNavigationState()).toMatchObject({ 0: {} });
60-
incrementUjNavigation();
58+
trackUJNavigation();
6159
expect(getNavigationState()).toMatchObject({ 0: {}, 1: {} });
6260
});
6361
});
@@ -98,7 +96,7 @@ describe('navSteps', () => {
9896

9997
it('returns the active steps for the last navigation step', () => {
10098
// load app
101-
incrementUjNavigation();
99+
trackUJNavigation();
102100

103101
markStep('start_navigate_to_second_screen_first_journey');
104102
expect(getNavigationState()).toMatchObject({
@@ -114,10 +112,10 @@ describe('navSteps', () => {
114112
it('returns the active steps for the last 2 navigation steps', () => {
115113
markStep('start_navigate_to_second_screen_first_journey');
116114
// load some next page
117-
incrementUjNavigation();
115+
trackUJNavigation();
118116
markStep('start_navigate_to_third_screen_first_journey');
119117

120-
incrementUjNavigation();
118+
trackUJNavigation();
121119
markStep('start_navigate_to_fourth_screen_first_journey');
122120
expect(getNavigationState()).toMatchObject({
123121
0: {
@@ -133,15 +131,15 @@ describe('navSteps', () => {
133131

134132
it('does not return stale steps - i.e. steps older than the last 2 navigations', () => {
135133
// navigate to some page
136-
incrementUjNavigation();
134+
trackUJNavigation();
137135
markStep('start_navigate_to_second_screen_first_journey');
138136

139137
// navigate to next page
140-
incrementUjNavigation();
138+
trackUJNavigation();
141139
markStep('start_navigate_to_third_screen_first_journey');
142140

143141
// navigate to a third page
144-
incrementUjNavigation();
142+
trackUJNavigation();
145143
markStep('start_navigate_to_fourth_screen_first_journey');
146144

147145
expect(getNavigationState()).toMatchObject({

Diff for: __tests__/stepsTestConstants.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const steps: IStepsConfig = {
4343
'loaded_second_screen_first_journey',
4444
],
4545
},
46-
test_load_reusing_marks: { // step with the same start and end mark as another
46+
test_load_reusing_marks: {
47+
// step with the same start and end mark as another
4748
threshold: IThresholdTier.instant,
4849
marks: [
4950
'start_navigate_to_fourth_screen_second_journey',
@@ -94,7 +95,6 @@ const steps: IStepsConfig = {
9495
export const testConfig: IPerfumeOptions = {
9596
steps,
9697
onMarkStep: jest.fn(),
97-
enableNavigationTracking: false,
9898
};
9999
export const navigationTestConfig: IPerfumeOptions = {
100100
steps,

Diff for: src/config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ export const config: IPerfumeConfig = {
88
maxTime: 30000,
99
// web-vitals report options
1010
reportOptions: {},
11-
enableNavigationTracking: true,
1211
};

Diff for: src/initPerfume.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
*
66
* @license
77
*/
8-
import { config } from './config';
9-
import { W, WN } from './constants';
10-
import { getNavigationTiming } from './getNavigationTiming';
11-
import { getNetworkInformation } from './getNetworkInformation';
12-
import { isPerformanceSupported } from './isSupported';
13-
import { logData, logMetric } from './log';
14-
import { initPerformanceObserver } from './observe';
15-
import { didVisibilityChange } from './onVisibilityChange';
16-
import { reportStorageEstimate } from './storageEstimate';
17-
import { IPerfumeOptions } from './types';
18-
import { getVitalsScore } from './vitalsScore';
19-
import { setStepsMap } from './steps/setStepsMap';
20-
8+
import { config } from './config';
9+
import { W, WN } from './constants';
10+
import { getNavigationTiming } from './getNavigationTiming';
11+
import { getNetworkInformation } from './getNetworkInformation';
12+
import { isPerformanceSupported } from './isSupported';
13+
import { logData, logMetric } from './log';
14+
import { initPerformanceObserver } from './observe';
15+
import { didVisibilityChange } from './onVisibilityChange';
16+
import { reportStorageEstimate } from './storageEstimate';
17+
import { IPerfumeOptions } from './types';
18+
import { getVitalsScore } from './vitalsScore';
19+
import { setStepsMap } from './steps/setStepsMap';
20+
2121
export const initPerfume = (options: IPerfumeOptions = {}) => {
2222
// Extend default config with external options
2323
config.analyticsTracker = options.analyticsTracker;
@@ -27,7 +27,6 @@ export const initPerfume = (options: IPerfumeOptions = {}) => {
2727
config.reportOptions = options.reportOptions || config.reportOptions;
2828
config.steps = options.steps;
2929
config.onMarkStep = options.onMarkStep;
30-
config.enableNavigationTracking = options.enableNavigationTracking;
3130

3231
// Exit from Perfume when basic Web Performance APIs aren't supported
3332
if (!isPerformanceSupported()) {

Diff for: src/perfume.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { initPerfume } from './initPerfume';
22

33
import { clear, end, endPaint, markStep, start } from './steps/markStep';
44
import { markStepOnce } from './steps/markStepOnce';
5-
import { incrementUjNavigation } from './steps/navigationSteps';
5+
import { trackUJNavigation } from './steps/navigationSteps';
66

7-
export {
7+
export {
88
clear,
99
end,
1010
endPaint,
1111
initPerfume,
1212
markStep,
1313
markStepOnce,
14-
incrementUjNavigation,
15-
start
14+
trackUJNavigation,
15+
start,
1616
};

Diff for: src/steps/measureSteps.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export const measureSteps = (mark: string) => {
2929
recordStartMark(mark);
3030
addActiveSteps(mark);
3131
}
32-
if (config.enableNavigationTracking) {
33-
const navigationBasedActiveSteps = getActiveStepsFromNavigationSteps();
34-
config.onMarkStep?.(mark, Object.keys(navigationBasedActiveSteps));
35-
} else {
36-
config.onMarkStep?.(mark, Object.keys(steps.active));
37-
}
32+
const navigationBasedActiveSteps = getActiveStepsFromNavigationSteps();
33+
config.onMarkStep?.(mark, Object.keys(navigationBasedActiveSteps));
3834
};

Diff for: src/steps/navigationSteps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const recordEndMark = (endMark: string) => {
117117
* steps that don't hit their final mark because the users navigates
118118
* backwards in journey.
119119
*/
120-
export const incrementUjNavigation = () => {
120+
export const trackUJNavigation = () => {
121121
// navigationSteps are 0-index based, so size will give us the next key value
122122
const navigationLength = Object.keys(steps.navigationSteps).length;
123123
steps.navigationSteps[navigationLength] = {};

Diff for: src/types.ts

-4
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ export interface IPerfumeConfig {
9797
steps?: IStepsConfig;
9898
// Callback that will run each time a mark is called
9999
onMarkStep?: (mark: string, steps: string[]) => void;
100-
// Boolean to decide to utilize navigation based steps
101-
enableNavigationTracking?: boolean;
102100
}
103101

104102
export interface IPerfumeOptions {
@@ -115,8 +113,6 @@ export interface IPerfumeOptions {
115113
steps?: IStepsConfig;
116114
// Callback that will run each time a mark is called
117115
onMarkStep?: (mark: string, steps: string[]) => void;
118-
// Boolean to decide to utilize navigation based steps
119-
enableNavigationTracking?: boolean;
120116
}
121117

122118
export interface IMetricMap {

0 commit comments

Comments
 (0)