diff --git a/app/controllers/idv/otp_verification_controller.rb b/app/controllers/idv/otp_verification_controller.rb index b792ad544eb..2ad46468497 100644 --- a/app/controllers/idv/otp_verification_controller.rb +++ b/app/controllers/idv/otp_verification_controller.rb @@ -18,6 +18,12 @@ def show def update result = phone_confirmation_otp_verification_form.submit(code: params[:code]) analytics.idv_phone_confirmation_otp_submitted(**result.to_h) + irs_attempts_api_tracker.idv_phone_otp_submitted( + phone_number: idv_session.user_phone_confirmation_session.phone, + success: result.success?, + failure_reason: result.success? ? {} : result.extra.slice(:code_expired, :code_matches), + ) + if result.success? idv_session.user_phone_confirmation = true redirect_to idv_review_url diff --git a/app/services/irs_attempts_api/tracker_events.rb b/app/services/irs_attempts_api/tracker_events.rb index a51347c575e..b6f957a0118 100644 --- a/app/services/irs_attempts_api/tracker_events.rb +++ b/app/services/irs_attempts_api/tracker_events.rb @@ -130,6 +130,19 @@ def idv_document_upload_submitted( ) end + # Tracks when a user submits OTP code sent to their phone + # @param [String] phone_number + # param [Boolean] success + # @param [Hash>] failure_reason + def idv_phone_otp_submitted(phone_number:, success:, failure_reason: nil) + track_event( + :idv_phone_otp_submitted, + phone_number: phone_number, + success: success, + failure_reason: failure_reason, + ) + end + # The user has exceeded the rate limit during idv document upload def idv_document_upload_rate_limited track_event( diff --git a/spec/controllers/idv/otp_verification_controller_spec.rb b/spec/controllers/idv/otp_verification_controller_spec.rb index 9d7509f4905..6c434283cb9 100644 --- a/spec/controllers/idv/otp_verification_controller_spec.rb +++ b/spec/controllers/idv/otp_verification_controller_spec.rb @@ -19,7 +19,9 @@ before do stub_analytics + stub_attempts_tracker allow(@analytics).to receive(:track_event) + allow(@irs_attempts_api_tracker).to receive(:track_event) sign_in(user) stub_verify_steps_one_and_two(user) @@ -97,5 +99,36 @@ expected_result, ) end + + describe 'track irs analytics event' do + context 'when the phone otp code is valid' do + it 'captures success event' do + put :update, params: { code: phone_confirmation_otp_code } + + expect(@irs_attempts_api_tracker).to have_received(:track_event).with( + :idv_phone_otp_submitted, + phone_number: phone, + success: true, + failure_reason: {}, + ) + end + end + + context 'when the phone otp code is invalid' do + it 'captures failure event' do + put :update, params: { code: '000' } + + expect(@irs_attempts_api_tracker).to have_received(:track_event).with( + :idv_phone_otp_submitted, + phone_number: phone, + success: false, + failure_reason: { + code_matches: false, + code_expired: false, + }, + ) + end + end + end end end