Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG-5951 Document the rest of analytics events #30 #6593

Merged
merged 10 commits into from
Jul 20, 2022
3 changes: 1 addition & 2 deletions app/controllers/idv/gpo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ def flash_error

def max_attempts_reached
if idv_attempter_throttled?
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
analytics.throttler_rate_limit_triggered(
throttle_type: :proof_address,
step_name: :gpo,
)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/idv/gpo_verify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def throttle
end

def render_throttled
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
analytics.throttler_rate_limit_triggered(
throttle_type: :verify_gpo_key,
)

Expand Down
3 changes: 1 addition & 2 deletions app/controllers/idv/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def throttle
end

def max_attempts_reached
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
analytics.throttler_rate_limit_triggered(
throttle_type: :proof_address,
step_name: step_name,
)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/idv_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def index
elsif active_profile? && !strict_ial2_upgrade_required?
redirect_to idv_activated_url
elsif idv_attempter_throttled?
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
analytics.throttler_rate_limit_triggered(
throttle_type: :idv_resolution,
)
redirect_to idv_session_errors_failure_url
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/openid_connect/authorization_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def track_events
user: current_user,
)

analytics.track_event(
Analytics::SP_REDIRECT_INITIATED,
analytics.sp_redirect_initiated(
ial: event_ial_context.ial,
billed_ial: event_ial_context.bill_for_ial_1_or_2,
)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/saml_idp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def render_template_for(message, action_url, type)
end

def track_events
analytics.track_event(
Analytics::SP_REDIRECT_INITIATED,
analytics.sp_redirect_initiated(
ial: ial_context.ial,
billed_ial: ial_context.bill_for_ial_1_or_2,
)
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/users/totp_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def user_opted_remember_device_cookie

def track_event
mfa_user = MfaContext.new(current_user)
properties = {
analytics.totp_setup_visit(
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,
}
analytics.track_event(Analytics::TOTP_SETUP_VISIT, properties)
)
end

def store_totp_secret_in_session
Expand Down Expand Up @@ -102,7 +101,7 @@ def create_events
end

def process_successful_disable
analytics.track_event(Analytics::TOTP_USER_DISABLED)
analytics.totp_user_disabled
create_user_event(:authenticator_disabled)
revoke_remember_device(current_user)
revoke_otp_secret_key
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/users/verify_personal_key_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def throttle
end

def render_throttled
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
analytics.throttler_rate_limit_triggered(
throttle_type: :verify_personal_key,
)

Expand Down
5 changes: 1 addition & 4 deletions app/forms/idv/api_document_verification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ def valid_url?(key)

def throttle_if_rate_limited
return unless @throttled
@analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: :idv_doc_auth,
)
@analytics.throttler_rate_limit_triggered(throttle_type: :idv_doc_auth)
errors.add(:limit, t('errors.doc_auth.throttled_heading'), type: :throttled)
end

Expand Down
2 changes: 1 addition & 1 deletion app/forms/idv/api_image_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def validate_images

def throttle_if_rate_limited
return unless @throttled
track_event(Analytics::THROTTLER_RATE_LIMIT_TRIGGERED, throttle_type: :idv_doc_auth)
analytics.throttler_rate_limit_triggered(throttle_type: :idv_doc_auth)
errors.add(:limit, t('errors.doc_auth.throttled_heading'), type: :throttled)
end

Expand Down
6 changes: 2 additions & 4 deletions app/forms/register_user_email_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def send_sign_up_unconfirmed_email(request_id)
@throttled = throttler.throttled_else_increment?

if @throttled
@analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@analytics.throttler_rate_limit_triggered(
throttle_type: :reg_unconfirmed_email,
)
else
Expand All @@ -144,8 +143,7 @@ def send_sign_up_confirmed_email
@throttled = throttler.throttled_else_increment?

if @throttled
@analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@analytics.throttler_rate_limit_triggered(
throttle_type: :reg_confirmed_email,
)
else
Expand Down
5 changes: 0 additions & 5 deletions app/services/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,4 @@ def session_started_at
end

DOC_AUTH = 'Doc Auth' # visited or submitted is appended
SP_REDIRECT_INITIATED = 'SP redirect initiated'
TELEPHONY_OTP_SENT = 'Telephony: OTP sent'
THROTTLER_RATE_LIMIT_TRIGGERED = 'Throttler Rate Limit Triggered'
TOTP_SETUP_VISIT = 'TOTP Setup Visited'
TOTP_USER_DISABLED = 'TOTP: User Disabled TOTP'
end
46 changes: 46 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,52 @@ def sp_inactive_visit
track_event('SP inactive visited')
end

# Tracks when a user is redirected back to the service provider
# @param [Integer] ial
# @param [Integer] billed_ial
def sp_redirect_initiated(ial:, billed_ial:, **extra)
track_event(
'SP redirect initiated',
ial: ial,
billed_ial: billed_ial,
**extra,
)
end

# Tracks when a user triggered a rate limit throttle
# @param [String] throttle_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we are sending in symbols here, not strings right?

def throttler_rate_limit_triggered(throttle_type:, **extra)
track_event(
'Throttler Rate Limit Triggered',
throttle_type: throttle_type,
**extra,
)
end

# Tracks when a user visits TOTP device setup
# @param [Boolean] user_signed_up
# @param [Boolean] totp_secret_present
# @param [Integer] enabled_mfa_methods_count
def totp_setup_visit(
user_signed_up:,
totp_secret_present:,
enabled_mfa_methods_count:,
**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,
**extra,
)
end

# Tracks when a user disabled a TOTP device
def totp_user_disabled
track_event('TOTP: User Disabled')
end

# Tracks when service provider consent is revoked
# @param [String] issuer issuer of the service provider consent to be revoked
def sp_revoke_consent_revoked(issuer:, **extra)
Expand Down
6 changes: 2 additions & 4 deletions app/services/idv/steps/doc_auth_base_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def throttle
def idv_failure(result)
throttle.increment! if result.extra.dig(:proofing_results, :exception).blank?
if throttle.throttled?
@flow.analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@flow.analytics.throttler_rate_limit_triggered(
throttle_type: :idv_resolution,
step_name: self.class.name,
)
Expand Down Expand Up @@ -81,8 +80,7 @@ def hybrid_flow_mobile?
end

def throttled_response
@flow.analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@flow.analytics.throttler_rate_limit_triggered(
throttle_type: :idv_doc_auth,
)
redirect_to throttled_url
Expand Down
3 changes: 1 addition & 2 deletions app/services/idv/steps/send_link_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def call
private

def throttled_failure
@flow.analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@flow.analytics.throttler_rate_limit_triggered(
throttle_type: :idv_send_link,
)
message = I18n.t(
Expand Down
3 changes: 1 addition & 2 deletions app/services/idv/steps/verify_base_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def enqueue_job
)

if throttle.throttled_else_increment?
@flow.analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
@flow.analytics.throttler_rate_limit_triggered(
throttle_type: :proof_ssn,
step_name: self.class,
)
Expand Down
5 changes: 1 addition & 4 deletions app/services/request_password_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def perform

def send_reset_password_instructions
if Throttle.new(user: user, throttle_type: :reset_password_email).throttled_else_increment?
analytics.track_event(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
throttle_type: :reset_password_email,
)
analytics.throttler_rate_limit_triggered(throttle_type: :reset_password_email)
else
token = user.set_reset_password_token
UserMailer.reset_password_instructions(user, email, token: token).deliver_now_or_later
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/idv/gpo_verify_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
'IdV: GPO verification visited',
).once
expect(@analytics).to receive(:track_event).with(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
'Throttler Rate Limit Triggered',
throttle_type: :verify_gpo_key,
).once

Expand Down Expand Up @@ -147,7 +147,7 @@
).exactly(max_attempts).times

expect(@analytics).to receive(:track_event).with(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
'Throttler Rate Limit Triggered',
throttle_type: :verify_gpo_key,
).once

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/idv/phone_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
allow(@analytics).to receive(:track_event)

expect(@analytics).to receive(:track_event).with(
Analytics::THROTTLER_RATE_LIMIT_TRIGGERED,
'Throttler Rate Limit Triggered',
throttle_type: :proof_address,
step_name: a_kind_of(Symbol),
)
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/openid_connect/authorization_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
scope: 'openid')
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 1,
billed_ial: 1,
)
Expand Down Expand Up @@ -119,7 +119,7 @@
scope: 'openid profile')
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 2,
billed_ial: 2,
)
Expand Down Expand Up @@ -218,7 +218,7 @@
scope: 'openid profile')
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 0,
billed_ial: 2,
)
Expand Down Expand Up @@ -259,7 +259,7 @@
scope: 'openid profile')
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 0,
billed_ial: 1,
)
Expand Down Expand Up @@ -301,7 +301,7 @@
scope: 'openid profile')
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 0,
billed_ial: 1,
)
Expand Down Expand Up @@ -377,7 +377,7 @@
user_fully_authenticated: true,
acr_values: 'http://idmanagement.gov/ns/assurance/ial/1',
scope: 'openid')
expect(@analytics).to_not receive(:track_event).with(Analytics::SP_REDIRECT_INITIATED)
expect(@analytics).to_not receive(:track_event).with('SP redirect initiated')

action

Expand Down Expand Up @@ -405,7 +405,7 @@
user_fully_authenticated: true,
acr_values: 'http://idmanagement.gov/ns/assurance/ial/1',
scope: 'openid')
expect(@analytics).to_not receive(:track_event).with(Analytics::SP_REDIRECT_INITIATED)
expect(@analytics).to_not receive(:track_event).with('SP redirect initiated')

action

Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/saml_idp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def name_id_version(format_urn)
finish_profile: false)
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: ial,
billed_ial: [ial, 2].min,
)
Expand Down Expand Up @@ -711,7 +711,7 @@ def name_id_version(format_urn)
finish_profile: false)
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 0,
billed_ial: 2,
)
Expand Down Expand Up @@ -1876,7 +1876,7 @@ def stub_requested_attributes
expect(@analytics).to receive(:track_event).with('SAML Auth', analytics_hash)
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 1,
billed_ial: 1,
)
Expand Down Expand Up @@ -1913,7 +1913,7 @@ def stub_requested_attributes
expect(@analytics).to receive(:track_event).with('SAML Auth', analytics_hash)
expect(@analytics).to receive(:track_event).
with(
Analytics::SP_REDIRECT_INITIATED,
'SP redirect initiated',
ial: 1,
billed_ial: 1,
)
Expand Down
Loading