Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/redirect/return_to_sp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def cancel

def failure_to_proof
redirect_url = sp_return_url_resolver.failure_to_proof_url
redirect_to_and_log redirect_url, event: Analytics::RETURN_TO_SP_FAILURE_TO_PROOF

analytics.return_to_sp_failure_to_proof(redirect_url: redirect_url, **location_params)
redirect_to(redirect_url)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/risc/security_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
form = SecurityEventForm.new(body: request.body.read)
result = form.submit

analytics.track_event(Analytics::SECURITY_EVENT_RECEIVED, result.to_h)
analytics.security_event_received(**result.to_h)

if result.success?
head :accepted
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/rules_of_use_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class RulesOfUseController < ApplicationController
before_action :confirm_need_to_accept_rules_of_use

def new
analytics.track_event(Analytics::RULES_OF_USE_VISIT)
analytics.rules_of_use_visit
@rules_of_use_form = new_rules_of_use_form
render :new, formats: :html
end
Expand All @@ -14,7 +14,7 @@ def create

result = @rules_of_use_form.submit(permitted_params)

analytics.track_event(Analytics::RULES_OF_USE_SUBMITTED, result.to_h)
analytics.rules_of_use_submitted(**result.to_h)

if result.success?
process_successful_agreement_to_rules_of_use
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/service_provider_revoke_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class ServiceProviderRevokeController < ApplicationController
def show
@service_provider = ServiceProvider.find(params[:sp_id])
load_identity!(@service_provider)
analytics.track_event(Analytics::SP_REVOKE_CONSENT_VISITED, issuer: @service_provider.issuer)
analytics.sp_revoke_consent_visited(issuer: @service_provider.issuer)
end

def destroy
@service_provider = ServiceProvider.find(params[:sp_id])
identity = load_identity!(@service_provider)

RevokeServiceProviderConsent.new(identity).call
analytics.track_event(Analytics::SP_REVOKE_CONSENT_REVOKED, issuer: @service_provider.issuer)
analytics.sp_revoke_consent_revoked(issuer: @service_provider.issuer)

redirect_to account_connected_accounts_path
end
Expand Down
6 changes: 0 additions & 6 deletions app/services/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ def browser_attributes
REMEMBERED_DEVICE_USED_FOR_AUTH = 'Remembered device used for authentication'
REMOTE_LOGOUT_INITIATED = 'Remote Logout initiated'
RETURN_TO_SP_CANCEL = 'Return to SP: Cancelled'
RETURN_TO_SP_FAILURE_TO_PROOF = 'Return to SP: Failed to proof'
RULES_OF_USE_VISIT = 'Rules Of Use Visited'
RULES_OF_USE_SUBMITTED = 'Rules Of Use Submitted'
SECURITY_EVENT_RECEIVED = 'RISC: Security event received'
SP_REVOKE_CONSENT_REVOKED = 'SP Revoke Consent: Revoked'
SP_REVOKE_CONSENT_VISITED = 'SP Revoke Consent: Visited'
SP_HANDOFF_BOUNCED_DETECTED = 'SP handoff bounced detected'
SP_HANDOFF_BOUNCED_VISIT = 'SP handoff bounced visited'
SP_INACTIVE_VISIT = 'SP inactive visited'
Expand Down
89 changes: 89 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rubocop:disable Metrics/ModuleLength
module AnalyticsEvents
# @identity.idp.event_name Account Reset
# @param [Boolean] success
Expand Down Expand Up @@ -310,6 +311,93 @@ def proofing_document_result_missing
track_event('Proofing Document Result Missing')
end

# @identity.idp.event_name Return to SP: Failed to proof
# Tracks when a user is redirected back to the service provider after failing to proof.
# @param [String] redirect_url the url of the service provider
# @param [String] flow
# @param [String] step
# @param [String] location
def return_to_sp_failure_to_proof(redirect_url:, flow: nil, step: nil, location: nil, **extra)
track_event(
'Return to SP: Failed to proof',
redirect_url: redirect_url,
flow: flow,
step: step,
location: location,
**extra,
)
end

# @identity.idp.event_name Rules of Use Visited
# Tracks when rules of use is visited
def rules_of_use_visit
track_event('Rules of Use Visited')
end

# @identity.idp.event_name Rules of Use Submitted
# Tracks when rules of use is submitted with a success or failure
# @param [Boolean] success
# @param [Hash] errors
def rules_of_use_submitted(success: nil, errors: nil, **extra)
track_event(
'Rules of Use Submitted',
success: success,
errors: errors,
**extra,
)
end

# @identity.idp.event_name RISC: Security event received
# Tracks when security event is received
# @param [Boolean] success
# @param [String] error_code
# @param [Hash] errors
# @param [String] jti
# @param [String] user_id
# @param [String] client_id
def security_event_received(
success:,
error_code: nil,
errors: nil,
jti: nil,
user_id: nil,
client_id: nil,
**extra
)
track_event(
'RISC: Security event received',
success: success,
error_code: error_code,
errors: errors,
jti: jti,
user_id: user_id,
client_id: client_id,
**extra,
)
end

# @identity.idp.event_name SP Revoke Consent: Revoked
# 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)
track_event(
'SP Revoke Consent: Revoked',
issuer: issuer,
**extra,
)
end

# @identity.idp.event_name SP Revoke Consent: Visited
# Tracks when the page to revoke consent (unlink from) a service provider visited
# @param [String] issuer which issuer
def sp_revoke_consent_visited(issuer:, **extra)
track_event(
'SP Revoke Consent: Visited',
issuer: issuer,
**extra,
)
end

# @identity.idp.event_name SAML Auth Request
# @param [Boolean] identity_needs_verification indicates whether identity verification is needed
# @param [Boolean] profile_needs_verification indicates if proofing is needed for a pending/reset
Expand All @@ -336,3 +424,4 @@ def saml_auth_request(
)
end
end
# rubocop:enable Metrics/ModuleLength
14 changes: 8 additions & 6 deletions spec/controllers/redirect/return_to_sp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@

expect(response).to redirect_to('https://sp.gov/failure_to_proof')
expect(@analytics).to have_received(:track_event).with(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
redirect_url: 'https://sp.gov/failure_to_proof',
'Return to SP: Failed to proof',
hash_including(redirect_url: 'https://sp.gov/failure_to_proof'),
Copy link
Contributor

Choose a reason for hiding this comment

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

this would still work without hash_including, right?

)
end
end
Expand All @@ -110,10 +110,12 @@
get 'failure_to_proof', params: { step: 'first', location: 'bottom' }

expect(@analytics).to have_received(:track_event).with(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
redirect_url: a_kind_of(String),
step: 'first',
location: 'bottom',
'Return to SP: Failed to proof',
hash_including(
redirect_url: a_kind_of(String),
step: 'first',
location: 'bottom',
),
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/risc/security_events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
it 'tracks an successful in analytics' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::SECURITY_EVENT_RECEIVED,
with('RISC: Security event received',
client_id: service_provider.issuer,
error_code: nil,
errors: {},
Expand Down Expand Up @@ -77,7 +77,7 @@
it 'tracks an error event in analytics' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::SECURITY_EVENT_RECEIVED,
with('RISC: Security event received',
client_id: service_provider.issuer,
error_code: SecurityEventForm::ErrorCodes::JWT_AUD,
errors: kind_of(Hash),
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/users/rules_of_use_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

it 'logs an analytics event for visiting' do
stub_analytics
expect(@analytics).to receive(:track_event).with(Analytics::RULES_OF_USE_VISIT)
expect(@analytics).to receive(:track_event).with('Rules of Use Visited')

action
end
Expand Down Expand Up @@ -64,7 +64,7 @@

it 'logs an analytics event for visiting' do
stub_analytics
expect(@analytics).to receive(:track_event).with(Analytics::RULES_OF_USE_VISIT)
expect(@analytics).to receive(:track_event).with('Rules of Use Visited')

action
end
Expand Down Expand Up @@ -117,7 +117,7 @@
it 'logs a successful analytics event' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::RULES_OF_USE_SUBMITTED, hash_including(success: true))
with('Rules of Use Submitted', hash_including(success: true))

action
end
Expand Down Expand Up @@ -147,7 +147,7 @@
it 'logs a failure analytics event' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::RULES_OF_USE_SUBMITTED, hash_including(success: false))
with('Rules of Use Submitted', hash_including(success: false))

action
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
it 'logs an analytics event for visiting' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::SP_REVOKE_CONSENT_VISITED, issuer: service_provider.issuer)
with('SP Revoke Consent: Visited', issuer: service_provider.issuer)

subject
end
Expand Down Expand Up @@ -75,7 +75,7 @@
it 'logs an analytics event for revoking' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(Analytics::SP_REVOKE_CONSENT_REVOKED, issuer: service_provider.issuer)
with('SP Revoke Consent: Revoked', issuer: service_provider.issuer)

subject
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/idv/doc_auth/document_capture_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

within_window new_window do
expect(fake_analytics).to have_logged_event(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
'Return to SP: Failed to proof',
step: 'document_capture',
location: 'document_capture_troubleshooting_options',
)
Expand Down
4 changes: 2 additions & 2 deletions spec/features/idv/doc_auth/welcome_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def expect_doc_auth_upload_step
click_on t('idv.troubleshooting.options.get_help_at_sp', sp_name: sp_name)

expect(fake_analytics).to have_logged_event(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
'Return to SP: Failed to proof',
step: 'welcome',
location: 'missing_items',
)
Expand Down Expand Up @@ -90,7 +90,7 @@ def expect_doc_auth_upload_step

click_on "‹ #{t('links.back_to_sp', sp: sp_name)}"
expect(fake_analytics).to have_logged_event(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
'Return to SP: Failed to proof',
step: 'welcome',
location: 'cancel',
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

within_window new_window do
expect(fake_analytics).to have_logged_event(
Analytics::RETURN_TO_SP_FAILURE_TO_PROOF,
'Return to SP: Failed to proof',
step: 'document_capture',
location: 'document_capture_troubleshooting_options',
)
Expand Down