Skip to content

Commit d64788e

Browse files
authored
Merge pull request #19873 from mozilla/password-reset-event-reason
feat(settings): add "reason" to password reset event
2 parents bc25e17 + 1febfe0 commit d64788e

7 files changed

Lines changed: 53 additions & 15 deletions

File tree

packages/fxa-settings/src/lib/glean/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,17 @@ const recordEventMetric = (
353353
passwordReset.createNewRecoveryKeyMessageClick.record();
354354
break;
355355
case 'password_reset_create_new_submit':
356-
passwordReset.createNewSubmit.record();
356+
passwordReset.createNewSubmit.record({
357+
reason: gleanPingMetrics?.event?.['reason'] || '',
358+
});
357359
break;
358360
case 'password_reset_create_new_success_view':
359361
passwordReset.createNewSuccessView.record();
360362
break;
361363
case 'password_reset_create_new_view':
362-
passwordReset.createNewView.record();
364+
passwordReset.createNewView.record({
365+
reason: gleanPingMetrics?.event?.['reason'] || '',
366+
});
363367
break;
364368
case 'password_reset_email_confirmation_different_account':
365369
passwordReset.emailConfirmationDifferentAccount.record();

packages/fxa-settings/src/pages/ResetPassword/CompleteResetPassword/container.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ const CompleteResetPasswordContainer = ({
320320
);
321321
}
322322
} else if (isResetWithoutRecoveryKey) {
323-
GleanMetrics.passwordReset.createNewSubmit();
323+
const reason = recoveryKeyExists ? 'with key' : 'without key';
324+
GleanMetrics.passwordReset.createNewSubmit({ event: { reason } });
324325
const includeRecoveryKeyPrompt = !!isSyncUser;
325326
const accountResetData = await resetPasswordWithoutRecoveryKey(
326327
code,

packages/fxa-settings/src/pages/ResetPassword/CompleteResetPassword/index.test.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ describe('CompleteResetPassword page', () => {
127127
);
128128

129129
await waitFor(() =>
130-
expect(GleanMetrics.passwordReset.createNewView).toHaveBeenCalledTimes(
131-
1
132-
)
130+
expect(GleanMetrics.passwordReset.createNewView).toHaveBeenCalledWith({
131+
event: { reason: 'without key' },
132+
})
133133
);
134134
});
135135
});
@@ -214,6 +214,22 @@ describe('CompleteResetPassword page', () => {
214214
screen.getByRole('link', { name: 'Use account recovery key' })
215215
).toBeVisible();
216216
});
217+
218+
it('sends the expected metrics on render with "with key" reason', async () => {
219+
renderWithLocalizationProvider(
220+
<Subject
221+
hasConfirmedRecoveryKey={false}
222+
recoveryKeyExists={true}
223+
estimatedSyncDeviceCount={2}
224+
/>
225+
);
226+
227+
await waitFor(() =>
228+
expect(GleanMetrics.passwordReset.createNewView).toHaveBeenCalledWith({
229+
event: { reason: 'with key' },
230+
})
231+
);
232+
});
217233
});
218234

219235
describe('reset when account has a recovery key but user lost the key and does not have synced devices', () => {

packages/fxa-settings/src/pages/ResetPassword/CompleteResetPassword/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ const CompleteResetPassword = ({
3535
const location = useLocation();
3636
const searchParams = location.search;
3737
useEffect(() => {
38-
hasConfirmedRecoveryKey
39-
? GleanMetrics.passwordReset.recoveryKeyCreatePasswordView()
40-
: GleanMetrics.passwordReset.createNewView();
41-
}, [hasConfirmedRecoveryKey]);
38+
if (hasConfirmedRecoveryKey) {
39+
GleanMetrics.passwordReset.recoveryKeyCreatePasswordView();
40+
} else {
41+
const reason = recoveryKeyExists ? 'with key' : 'without key';
42+
GleanMetrics.passwordReset.createNewView({ event: { reason } });
43+
}
44+
}, [hasConfirmedRecoveryKey, recoveryKeyExists]);
4245

4346
const ftlMsgResolver = useFtlMsgResolver();
4447

packages/fxa-shared/metrics/glean/fxa-ui-metrics.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,11 @@ password_reset:
10511051
expires: never
10521052
data_sensitivity:
10531053
- interaction
1054+
extra_keys:
1055+
reason:
1056+
description: |
1057+
Indicates the password reset flow context: "with key" when user has a recovery key but chose the standard reset flow, or "without key" when user doesn't have a recovery key.
1058+
type: string
10541059
create_new_success_view:
10551060
type: event
10561061
description: |
@@ -1087,6 +1092,11 @@ password_reset:
10871092
expires: never
10881093
data_sensitivity:
10891094
- interaction
1095+
extra_keys:
1096+
reason:
1097+
description: |
1098+
Indicates the password reset flow context: "with key" when user has a recovery key but chose the standard reset flow, or "without key" when user doesn't have a recovery key.
1099+
type: string
10901100
email_confirmation_different_account:
10911101
type: event
10921102
description: |

packages/fxa-shared/metrics/glean/web/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// AUTOGENERATED BY glean_parser v14.5.2. DO NOT EDIT. DO NOT COMMIT.
66

7-
import StringMetricType from '@mozilla/glean/private/metrics/string';
87
import BooleanMetricType from '@mozilla/glean/private/metrics/boolean';
8+
import StringMetricType from '@mozilla/glean/private/metrics/string';
99

1010
/**
1111
* The name of the framework used by the app (ie React or Backbone).

packages/fxa-shared/metrics/glean/web/passwordReset.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ export const createNewRecoveryKeyMessageClick = new EventMetricType(
6565
*
6666
* Generated from `password_reset.create_new_submit`.
6767
*/
68-
export const createNewSubmit = new EventMetricType(
68+
export const createNewSubmit = new EventMetricType<{
69+
reason?: string;
70+
}>(
6971
{
7072
category: 'password_reset',
7173
name: 'create_new_submit',
7274
sendInPings: ['events'],
7375
lifetime: 'ping',
7476
disabled: false,
7577
},
76-
[]
78+
['reason']
7779
);
7880

7981
/**
@@ -99,15 +101,17 @@ export const createNewSuccessView = new EventMetricType(
99101
*
100102
* Generated from `password_reset.create_new_view`.
101103
*/
102-
export const createNewView = new EventMetricType(
104+
export const createNewView = new EventMetricType<{
105+
reason?: string;
106+
}>(
103107
{
104108
category: 'password_reset',
105109
name: 'create_new_view',
106110
sendInPings: ['events'],
107111
lifetime: 'ping',
108112
disabled: false,
109113
},
110-
[]
114+
['reason']
111115
);
112116

113117
/**

0 commit comments

Comments
 (0)