diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index ae88634539e..feb6314d61d 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -16,6 +16,10 @@ def update result = @update_user_password_form.submit(user_params) analytics.password_changed(**result.to_h) + irs_attempts_api_tracker.logged_in_password_change( + success: result.success?, + failure_reason: result.to_h[:error_details], + ) if result.success? handle_valid_password diff --git a/app/services/irs_attempts_api/tracker_events.rb b/app/services/irs_attempts_api/tracker_events.rb index 05877a2b10b..f95b69791d5 100644 --- a/app/services/irs_attempts_api/tracker_events.rb +++ b/app/services/irs_attempts_api/tracker_events.rb @@ -101,6 +101,13 @@ def forgot_password_new_password_submitted(success:, failure_reason: nil) ) end + # The user has exceeded the rate limit during idv document upload + def idv_document_upload_rate_limited + track_event( + :idv_document_upload_rate_limited, + ) + end + # @param [Boolean] success # @param [String] document_state # @param [String] document_number @@ -139,42 +146,6 @@ def idv_document_upload_submitted( ) end - # Tracks when the user submits their idv phone number - # @param [String] phone_number - # param [Boolean] success - # @param [Hash>] failure_reason - def idv_phone_submitted(phone_number:, success:, failure_reason: nil) - track_event( - :idv_phone_submitted, - phone_number: phone_number, - success: success, - failure_reason: failure_reason, - ) - end - - # Tracks Idv phone OTP sent rate limits - def idv_phone_otp_sent_rate_limited - track_event( - :idv_phone_otp_sent_rate_limited, - ) - end - - # The user has exceeded the rate limit during idv document upload - def idv_document_upload_rate_limited - track_event( - :idv_document_upload_rate_limited, - ) - end - - # Tracks when the user submits a password for identity proofing - # @param [Boolean] success - def idv_password_entered(success:) - track_event( - :idv_password_entered, - success: success, - ) - end - # param [Boolean] Success # param [Hash>] failure_reason displays GPO submission failed # GPO verification submitted from Letter sent to verify address @@ -204,6 +175,15 @@ def idv_letter_requested(success:, resend:) ) end + # Tracks when the user submits a password for identity proofing + # @param [Boolean] success + def idv_password_entered(success:) + track_event( + :idv_password_entered, + success: success, + ) + end + # @param [Boolean] success # Personal Key got generated for user def idv_personal_key_generated(success:) @@ -236,6 +216,13 @@ def idv_phone_confirmation_otp_sent_rate_limited ) end + # Tracks Idv phone OTP sent rate limits + def idv_phone_otp_sent_rate_limited + track_event( + :idv_phone_otp_sent_rate_limited, + ) + end + # Tracks when a user submits OTP code sent to their phone # @param [String] phone_number # param [Boolean] success @@ -258,6 +245,19 @@ def idv_phone_otp_submitted_rate_limited(phone:) ) end + # Tracks when the user submits their idv phone number + # @param [String] phone_number + # param [Boolean] success + # @param [Hash>] failure_reason + def idv_phone_submitted(phone_number:, success:, failure_reason: nil) + track_event( + :idv_phone_submitted, + phone_number: phone_number, + success: success, + failure_reason: failure_reason, + ) + end + # @param [Boolean] success # @param [String] phone_number # The phone number that the link was sent to during the IDV process @@ -340,6 +340,16 @@ def idv_verification_submitted( ) end + # @param [Boolean] success True if the password was successfully changed + # A logged-in user has attempted to change their password + def logged_in_password_change(success:, failure_reason: nil) + track_event( + :logged_in_password_change, + success: success, + failure_reason: failure_reason, + ) + end + # @param [String] email # A login attempt was rejected due to too many incorrect attempts def login_rate_limited(email) diff --git a/spec/controllers/users/passwords_controller_spec.rb b/spec/controllers/users/passwords_controller_spec.rb index c869f2048d7..0cca150a5de 100644 --- a/spec/controllers/users/passwords_controller_spec.rb +++ b/spec/controllers/users/passwords_controller_spec.rb @@ -8,13 +8,17 @@ it 'redirects to profile and sends a password change email' do stub_sign_in stub_analytics + stub_attempts_tracker allow(@analytics).to receive(:track_event) + allow(@irs_attempts_api_tracker).to receive(:track_event) params = { password: 'salty new password' } patch :update, params: { update_user_password_form: params } expect(@analytics).to have_received(:track_event). with('Password Changed', success: true, errors: {}) + expect(@irs_attempts_api_tracker).to have_received(:track_event). + with(:logged_in_password_change, failure_reason: nil, success: true) expect(response).to redirect_to account_url expect(flash[:info]).to eq t('notices.password_changed') expect(flash[:personal_key]).to be_nil @@ -77,7 +81,9 @@ stub_sign_in stub_analytics + stub_attempts_tracker allow(@analytics).to receive(:track_event) + allow(@irs_attempts_api_tracker).to receive(:track_event) params = { password: 'new' } patch :update, params: { update_user_password_form: params } @@ -92,6 +98,13 @@ }, error_details: { password: [:too_short] }, ) + expect(@irs_attempts_api_tracker).to have_received(:track_event).with( + :logged_in_password_change, + success: false, + failure_reason: { + password: [:too_short], + }, + ) expect(response).to render_template(:edit) end