diff --git a/app/controllers/sign_up/registrations_controller.rb b/app/controllers/sign_up/registrations_controller.rb index 6f5558e6522..c1ef375710c 100644 --- a/app/controllers/sign_up/registrations_controller.rb +++ b/app/controllers/sign_up/registrations_controller.rb @@ -23,6 +23,11 @@ def create result = @register_user_email_form.submit(permitted_params) analytics.user_registration_email(**result.to_h) + irs_attempts_api_tracker.user_registration_email_submitted( + email: permitted_params[:email], + success: result.success?, + failure_reason: result.to_h[:error_details], + ) if result.success? process_successful_creation diff --git a/app/controllers/users/reset_passwords_controller.rb b/app/controllers/users/reset_passwords_controller.rb index 290c5b96b63..943ef7e6cdf 100644 --- a/app/controllers/users/reset_passwords_controller.rb +++ b/app/controllers/users/reset_passwords_controller.rb @@ -86,6 +86,11 @@ def create_account_if_email_not_found return unless result analytics.user_registration_email(**result.to_h) + irs_attempts_api_tracker.user_registration_email_submitted( + email: email, + success: result.success?, + failure_reason: result.to_h[:error_details], + ) create_user_event(:account_created, user) end diff --git a/app/services/irs_attempts_api/tracker_events.rb b/app/services/irs_attempts_api/tracker_events.rb index 36d2fe73599..b4e0c9b2938 100644 --- a/app/services/irs_attempts_api/tracker_events.rb +++ b/app/services/irs_attempts_api/tracker_events.rb @@ -49,5 +49,22 @@ def user_registration_email_confirmation( failure_reason: failure_reason, ) end + + # Tracks when user submits registration email + # @param [Boolean] success + # @param [String] email + # @param [Hash>] failure_reason + def user_registration_email_submitted( + success:, + email:, + failure_reason: nil + ) + track_event( + :user_registration_email_submitted, + success: success, + email: email, + failure_reason: failure_reason, + ) + end end end diff --git a/spec/controllers/sign_up/registrations_controller_spec.rb b/spec/controllers/sign_up/registrations_controller_spec.rb index eb029dd3cb2..e47dbe4c46a 100644 --- a/spec/controllers/sign_up/registrations_controller_spec.rb +++ b/spec/controllers/sign_up/registrations_controller_spec.rb @@ -33,8 +33,10 @@ context 'when registering with a new email' do it 'tracks successful user registration' do stub_analytics + stub_attempts_tracker allow(@analytics).to receive(:track_event) + allow(@irs_attempts_api_tracker).to receive(:track_event) allow(subject).to receive(:create_user_event) post :create, params: { user: { email: 'new@example.com', terms_accepted: '1' } } @@ -53,6 +55,13 @@ expect(@analytics).to have_received(:track_event). with('User Registration: Email Submitted', analytics_hash) + expect(@irs_attempts_api_tracker).to have_received(:track_event).with( + :user_registration_email_submitted, + email: 'new@example.com', + success: true, + failure_reason: nil, + ) + expect(subject).to have_received(:create_user_event).with(:account_created, user) end @@ -88,6 +97,7 @@ existing_user = create(:user, email: 'test@example.com') stub_analytics + stub_attempts_tracker analytics_hash = { success: true, @@ -100,6 +110,14 @@ expect(@analytics).to receive(:track_event). with('User Registration: Email Submitted', analytics_hash) + + expect(@irs_attempts_api_tracker).to receive(:track_event).with( + :user_registration_email_submitted, + email: 'TEST@example.com ', + success: true, + failure_reason: nil, + ) + expect(subject).to_not receive(:create_user_event) post :create, params: { user: { email: 'TEST@example.com ', terms_accepted: '1' } } @@ -107,6 +125,7 @@ it 'tracks unsuccessful user registration' do stub_analytics + stub_attempts_tracker analytics_hash = { success: false, @@ -121,6 +140,13 @@ expect(@analytics).to receive(:track_event). with('User Registration: Email Submitted', analytics_hash) + expect(@irs_attempts_api_tracker).to receive(:track_event).with( + :user_registration_email_submitted, + email: 'invalid@', + success: false, + failure_reason: { email: [:invalid] }, + ) + post :create, params: { user: { email: 'invalid@', request_id: '', terms_accepted: '1' } } end diff --git a/spec/controllers/users/reset_passwords_controller_spec.rb b/spec/controllers/users/reset_passwords_controller_spec.rb index 8127559f321..467d5e4ae30 100644 --- a/spec/controllers/users/reset_passwords_controller_spec.rb +++ b/spec/controllers/users/reset_passwords_controller_spec.rb @@ -312,6 +312,8 @@ context 'no user matches email' do it 'send an email to tell the user they do not have an account yet' do stub_analytics + stub_attempts_tracker + allow(@irs_attempts_api_tracker).to receive(:track_event) email = 'nonexistent@example.com' expect do @@ -342,6 +344,12 @@ 'User Registration: Email Submitted', analytics_hash, ) + expect(@irs_attempts_api_tracker).to have_received(:track_event).with( + :user_registration_email_submitted, + email: email, + success: true, + failure_reason: nil, + ) expect(response).to redirect_to forgot_password_path end