Skip to content
5 changes: 3 additions & 2 deletions app/controllers/users/backup_code_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def index
def create
generate_codes
result = BackupCodeSetupForm.new(current_user).submit
analytics_properties = result.to_h
analytics_properties = result.to_h.merge(analytics_properties_for_visit)
analytics.backup_code_setup_visit(**analytics_properties)
irs_attempts_api_tracker.mfa_enroll_backup_code(success: result.success?)

Expand Down Expand Up @@ -65,7 +65,7 @@ def confirm_backup_codes; end
private

def analytics_properties_for_visit
ParseControllerFromReferer.new(request.referer).call
{ in_multi_mfa_selection_flow: in_multi_mfa_selection_flow? }
end

def track_backup_codes_created
Expand All @@ -82,6 +82,7 @@ def mfa_user
def track_backup_codes_confirmation_setup_visit
analytics.multi_factor_auth_enter_backup_code_confirmation_visit(
enabled_mfa_methods_count: mfa_user.enabled_mfa_methods_count,
in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?,
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def error
end

def delete
analytics.user_registration_piv_cac_disabled
analytics.piv_cac_disabled
remove_piv_cac
clear_piv_cac_information
create_user_event(:piv_cac_disabled)
Expand All @@ -57,8 +57,9 @@ def submit_new_piv_cac

def track_piv_cac_setup_visit
mfa_user = MfaContext.new(current_user)
analytics.user_registration_piv_cac_setup_visit(
analytics.piv_cac_setup_visit(
enabled_mfa_methods_count: mfa_user.enabled_mfa_methods_count,
in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?,
)
end

Expand Down Expand Up @@ -131,6 +132,7 @@ def track_mfa_method_added
mfa_user = MfaContext.new(current_user)
analytics.multi_factor_auth_added_piv_cac(
enabled_mfa_methods_count: mfa_user.enabled_mfa_methods_count,
in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?,
)
Funnel::Registration::AddMfa.call(current_user.id, 'piv_cac', analytics)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/piv_cac_login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def error
private

def render_prompt
analytics.user_registration_piv_cac_setup_visit
analytics.piv_cac_setup_visit(in_multi_mfa_selection_flow: false)
@presenter = PivCacAuthenticationLoginPresenter.new(piv_cac_login_form, url_options)
render :new
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def decline
private

def render_prompt
analytics.user_registration_piv_cac_setup_visit
analytics.piv_cac_setup_visit(in_multi_mfa_selection_flow: false)
render :prompt
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users/totp_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def track_event
user_signed_up: MfaPolicy.new(current_user).two_factor_enabled?,
totp_secret_present: new_totp_secret.present?,
enabled_mfa_methods_count: mfa_user.enabled_mfa_methods_count,
in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?,
)
end

Expand All @@ -96,6 +97,7 @@ def create_events
mfa_user = MfaContext.new(current_user)
analytics.multi_factor_auth_added_totp(
enabled_mfa_methods_count: mfa_user.enabled_mfa_methods_count,
in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?,
)
Funnel::Registration::AddMfa.call(current_user.id, 'auth_app', analytics)
end
Expand Down
67 changes: 42 additions & 25 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def backup_code_created(enabled_mfa_methods_count:, **extra)
end

# Tracks when the user visits the Backup Code Regenerate page.
# @param [String] request_came_from the controller/action the request came from
def backup_code_regenerate_visit(request_came_from:, **extra)
track_event('Backup Code Regenerate Visited', request_came_from:, **extra)
# @param [Boolean] in_multi_mfa_selection_flow whether user is going through MFA selection Flow
def backup_code_regenerate_visit(in_multi_mfa_selection_flow:, **extra)
track_event('Backup Code Regenerate Visited', in_multi_mfa_selection_flow:, **extra)
end

# Track user creating new BackupCodeSetupForm, record form submission Hash
Expand Down Expand Up @@ -2602,25 +2602,31 @@ def multi_factor_auth_added_phone(enabled_mfa_methods_count:, **extra)

# Tracks when the user has added the MFA method piv_cac to their account
# @param [Integer] enabled_mfa_methods_count number of registered mfa methods for the user
def multi_factor_auth_added_piv_cac(enabled_mfa_methods_count:, **extra)
# @param [Boolean] in_multi_mfa_selection_flow whether user is going through MFA selection Flow
def multi_factor_auth_added_piv_cac(enabled_mfa_methods_count:, in_multi_mfa_selection_flow:,
**extra)
track_event(
'Multi-Factor Authentication: Added PIV_CAC',
{
method_name: :piv_cac,
enabled_mfa_methods_count: enabled_mfa_methods_count,
enabled_mfa_methods_count:,
in_multi_mfa_selection_flow:,
**extra,
}.compact,
)
end

# Tracks when the user has added the MFA method TOTP to their account
# @param [Integer] enabled_mfa_methods_count number of registered mfa methods for the user
def multi_factor_auth_added_totp(enabled_mfa_methods_count:, **extra)
# @param [Boolean] in_multi_mfa_selection_flow whether user is going through MFA selection Flow
def multi_factor_auth_added_totp(enabled_mfa_methods_count:, in_multi_mfa_selection_flow:,
**extra)
track_event(
'Multi-Factor Authentication: Added TOTP',
{
method_name: :totp,
enabled_mfa_methods_count: enabled_mfa_methods_count,
in_multi_mfa_selection_flow:,
enabled_mfa_methods_count:,
**extra,
}.compact,
)
Expand Down Expand Up @@ -2651,13 +2657,17 @@ def multi_factor_auth_backup_code_download

# Tracks when the user visits the backup code confirmation setup page
# @param [Integer] enabled_mfa_methods_count number of registered mfa methods for the user
# @param [Boolean] in_multi_mfa_selection_flow tell whether its in MFA selection flow or not
def multi_factor_auth_enter_backup_code_confirmation_visit(
enabled_mfa_methods_count:, **extra
enabled_mfa_methods_count:,
in_multi_mfa_selection_flow:,
**extra
)
track_event(
'Multi-Factor Authentication: enter backup code confirmation visited',
{
enabled_mfa_methods_count: enabled_mfa_methods_count,
enabled_mfa_methods_count:,
in_multi_mfa_selection_flow:,
**extra,
}.compact,
)
Expand Down Expand Up @@ -3247,6 +3257,12 @@ def phone_deletion(success:, phone_configuration_id:, **extra)
)
end

# @identity.idp.previous_event_name User Registration: piv cac disabled
# Tracks when user's piv cac is disabled
def piv_cac_disabled
track_event('PIV CAC disabled')
end

# @param [Boolean] success
# @param [Hash] errors
# tracks piv cac login event
Expand All @@ -3259,6 +3275,17 @@ def piv_cac_login(success:, errors:, **extra)
)
end

# @identity.idp.previous_event_name User Registration: piv cac setup visited
# Tracks when user's piv cac setup
# @param [Boolean] in_multi_mfa_selection_flow
def piv_cac_setup_visit(in_multi_mfa_selection_flow:, **extra)
track_event(
'PIV CAC setup visited',
in_multi_mfa_selection_flow:,
**extra,
)
end

# @param [String] redirect_url URL user was directed to
# @param [String, nil] step which step
# @param [String, nil] location which part of a step, if applicable
Expand Down Expand Up @@ -3751,17 +3778,20 @@ def telephony_otp_sent(
# @param [Boolean] user_signed_up
# @param [Boolean] totp_secret_present
# @param [Integer] enabled_mfa_methods_count
# @param [Boolean] in_multi_mfa_selection_flow
def totp_setup_visit(
user_signed_up:,
totp_secret_present:,
enabled_mfa_methods_count:,
in_multi_mfa_selection_flow:,
**extra
)
track_event(
'TOTP Setup Visited',
user_signed_up: user_signed_up,
totp_secret_present: totp_secret_present,
enabled_mfa_methods_count: enabled_mfa_methods_count,
user_signed_up:,
totp_secret_present:,
enabled_mfa_methods_count:,
in_multi_mfa_selection_flow:,
**extra,
)
end
Expand Down Expand Up @@ -4059,19 +4089,6 @@ def user_registration_phone_setup_visit(enabled_mfa_methods_count:, **extra)
)
end

# Tracks when user's piv cac is disabled
def user_registration_piv_cac_disabled
track_event('User Registration: piv cac disabled')
end

# Tracks when user's piv cac setup
def user_registration_piv_cac_setup_visit(**extra)
track_event(
'User Registration: piv cac setup visited',
**extra,
)
end

# Tracks when user skips Suggest Another MFA Page
def user_registration_suggest_another_mfa_notice_skipped
track_event('User Registration: Suggest Another MFA Notice Skipped')
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/users/backup_code_setup_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
pii_like_keypaths: [[:mfa_method_counts, :phone]],
error_details: nil,
enabled_mfa_methods_count: 1,
in_multi_mfa_selection_flow: false,
})
expect(@analytics).to receive(:track_event).
with('Backup Code Created', {
Expand Down Expand Up @@ -151,7 +152,7 @@
get :edit
expect(@analytics).to have_logged_event(
'Backup Code Regenerate Visited',
hash_including(request_came_from: 'no referer'),
hash_including(in_multi_mfa_selection_flow: false),
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
get :new
expect(response).to render_template(:new)
end

it 'tracks the analytic event of visited' do
stub_analytics
expect(@analytics).to receive(:track_event).
with('PIV CAC setup visited', {
in_multi_mfa_selection_flow: false,
enabled_mfa_methods_count: 1,
})

get :new
end
end

context 'when redirected with a good token' do
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/users/piv_cac_login_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

it 'tracks the piv_cac setup' do
expect(@analytics).to have_received(:track_event).with(
'User Registration: piv cac setup visited',
'PIV CAC setup visited',
in_multi_mfa_selection_flow: false,
)
end

Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/users/totp_setup_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
user_signed_up: true,
totp_secret_present: true,
enabled_mfa_methods_count: 1,
in_multi_mfa_selection_flow: false,
}

expect(@analytics).
Expand Down Expand Up @@ -77,6 +78,7 @@
user_signed_up: false,
totp_secret_present: true,
enabled_mfa_methods_count: 0,
in_multi_mfa_selection_flow: false,
}

expect(@analytics).
Expand Down