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
48 changes: 45 additions & 3 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,25 @@ def idv_cancellation_confirmed(step:, proofing_components: nil, **extra)

# @param [String] step the step that the user was on when they clicked cancel
# @param [Idv::ProofingComponentsLogging] proofing_components User's current proofing components
# @param [boolean,nil] cancelled_enrollment Whether the user's IPP enrollment has been canceled
# @param [String,nil] enrollment_code IPP enrollment code
# @param [Integer,nil] enrollment_id ID of the associated IPP enrollment record
# The user chose to go back instead of cancel IDV
def idv_cancellation_go_back(step:, proofing_components: nil, **extra)
def idv_cancellation_go_back(
step:,
proofing_components: nil,
cancelled_enrollment: nil,
enrollment_code: nil,
enrollment_id: nil,
**extra
)
track_event(
'IdV: cancellation go back',
step: step,
proofing_components: proofing_components,
cancelled_enrollment: cancelled_enrollment,
enrollment_code: enrollment_code,
enrollment_id: enrollment_id,
**extra,
)
end
Expand Down Expand Up @@ -2544,8 +2557,10 @@ def idv_personal_key_downloaded(proofing_components: nil, **extra)
# @param [Boolean] fraud_review_pending Profile is under review for fraud
# @param [Boolean] fraud_rejection Profile is rejected due to fraud
# @param [Boolean] in_person_verification_pending Profile is pending in-person verification
# @param [String] address_verification_method "phone" or "gpo"
# User submitted IDV personal key page
def idv_personal_key_submitted(
address_verification_method:,
fraud_review_pending:,
fraud_rejection:,
in_person_verification_pending:,
Expand All @@ -2555,6 +2570,7 @@ def idv_personal_key_submitted(
)
track_event(
'IdV: personal key submitted',
address_verification_method: address_verification_method,
in_person_verification_pending: in_person_verification_pending,
deactivation_reason: deactivation_reason,
fraud_review_pending: fraud_review_pending,
Expand All @@ -2565,11 +2581,23 @@ def idv_personal_key_submitted(
end

# @param [Idv::ProofingComponentsLogging] proofing_components User's current proofing components
# @param [String] address_verification_method "phone" or "gpo"
# @param [Boolean,nil] in_person_verification_pending
# @param [Boolean] encrypted_profiles_missing True if user's session had no encrypted pii
# User visited IDV personal key page
def idv_personal_key_visited(proofing_components: nil, **extra)
def idv_personal_key_visited(
proofing_components: nil,
address_verification_method: nil,
in_person_verification_pending: nil,
encrypted_profiles_missing: nil,
**extra
)
track_event(
'IdV: personal key visited',
proofing_components: proofing_components,
address_verification_method: address_verification_method,
in_person_verification_pending: in_person_verification_pending,
encrypted_profiles_missing: encrypted_profiles_missing,
**extra,
)
end
Expand Down Expand Up @@ -2633,6 +2661,7 @@ def idv_phone_confirmation_otp_rate_limit_sends(proofing_components: nil, **extr
# @param [String] area_code area code of phone number
# @param [Boolean] rate_limit_exceeded whether or not the rate limit was exceeded by this attempt
# @param [Hash] telephony_response response from Telephony gem
# @param [String] phone_fingerprint Fingerprint string identifying phone number
# @param [Idv::ProofingComponentsLogging] proofing_components User's current proofing components
# The user resent an OTP during the IDV phone step
def idv_phone_confirmation_otp_resent(
Expand All @@ -2643,6 +2672,7 @@ def idv_phone_confirmation_otp_resent(
area_code:,
rate_limit_exceeded:,
telephony_response:,
phone_fingerprint:,
proofing_components: nil,
**extra
)
Expand All @@ -2655,6 +2685,7 @@ def idv_phone_confirmation_otp_resent(
area_code: area_code,
rate_limit_exceeded: rate_limit_exceeded,
telephony_response: telephony_response,
phone_fingerprint: phone_fingerprint,
proofing_components: proofing_components,
**extra,
)
Expand Down Expand Up @@ -3035,10 +3066,16 @@ def idv_session_error_visited(
# @param [String] step
# @param [String] location
# @param [Idv::ProofingComponentsLogging] proofing_components User's current proofing components
# @param [boolean,nil] cancelled_enrollment Whether the user's IPP enrollment has been canceled
# @param [String,nil] enrollment_code IPP enrollment code
# @param [Integer,nil] enrollment_id ID of the associated IPP enrollment record
# User started over idv
def idv_start_over(
step:,
location:,
cancelled_enrollment: nil,
enrollment_code: nil,
enrollment_id: nil,
proofing_components: nil,
**extra
)
Expand All @@ -3047,6 +3084,9 @@ def idv_start_over(
step: step,
location: location,
proofing_components: proofing_components,
cancelled_enrollment: cancelled_enrollment,
enrollment_code: enrollment_code,
enrollment_id: enrollment_id,
**extra,
)
end
Expand Down Expand Up @@ -3832,12 +3872,14 @@ def otp_delivery_selection(
# Tracks if otp phone validation failed
# @identity.idp.previous_event_name Twilio Phone Validation Failed
# @param [String] error
# @param [string] message
# @param [String] context
# @param [String] country
def otp_phone_validation_failed(error:, context:, country:, **extra)
def otp_phone_validation_failed(error:, message:, context:, country:, **extra)
track_event(
'Vendor Phone Validation failed',
error: error,
message: message,
context: context,
country: country,
**extra,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ def handle_max_attempts(_arg = nil)
before do
stub_analytics
stub_attempts_tracker
allow(@analytics).to receive(:track_event)
allow(@irs_attempts_api_tracker).to receive(:track_event)
end

it 'calls analytics tracking event' do
subject.handle_too_many_otp_sends

expect(@analytics).to have_received(:track_event).with(
'Idv: Phone OTP sends rate limited',
proofing_components: nil,
)
expect(@analytics).to have_logged_event('Idv: Phone OTP sends rate limited')
end

it 'calls irs tracking event idv_phone_otp_sent_rate_limited' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
end

context 'user needs USPS address verification' do
it 'renders the show template' do
it 'logs an analytics event' do
stub_analytics

expect(@analytics).to receive(:track_event).with(
get :show

expect(@analytics).to have_logged_event(
'IdV: letter enqueued visited',
proofing_components: nil,
)
end

it 'renders the show template' do
get :show

expect(response).to render_template :show
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rails_helper'

RSpec.describe Idv::ByMail::RequestLetterController, allowed_extra_analytics: [:*] do
RSpec.describe Idv::ByMail::RequestLetterController,
allowed_extra_analytics: [:sample_bucket1, :sample_bucket2] do
let(:user) { create(:user) }

let(:ab_test_args) do
Expand Down
62 changes: 34 additions & 28 deletions spec/controllers/idv/cancellations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@
stub_sign_in
stub_analytics

expect(@analytics).to receive(:track_event).with(
get :new

expect(@analytics).to have_logged_event(
'IdV: cancellation visited',
request_came_from: 'no referer',
step: nil,
proofing_components: nil,
)

get :new
end

it 'tracks the event in analytics when referer is present' do
stub_sign_in
stub_analytics
request.env['HTTP_REFERER'] = 'http://example.com/'

expect(@analytics).to receive(:track_event).with(
get :new

expect(@analytics).to have_logged_event(
'IdV: cancellation visited',
request_came_from: 'users/sessions#new',
step: nil,
proofing_components: nil,
)

get :new
end

it 'tracks the event in analytics when step param is present' do
stub_sign_in
stub_analytics

expect(@analytics).to receive(:track_event).with(
get :new, params: { step: 'first' }

expect(@analytics).to have_logged_event(
'IdV: cancellation visited',
request_came_from: 'no referer',
step: 'first',
proofing_components: nil,
)

get :new, params: { step: 'first' }
end

context 'when no session' do
Expand Down Expand Up @@ -104,34 +104,23 @@

describe '#update' do
let(:user) { create(:user) }
let(:enrollment) { create(:in_person_enrollment, :pending, user: user) }

before do
stub_sign_in(user)
stub_analytics
end

it 'logs cancellation go back' do
expect(@analytics).to receive(:track_event).with(
'IdV: cancellation go back',
step: 'first',
proofing_components: nil,
)

put :update, params: { step: 'first', cancel: 'true' }
end

it 'logs cancellation go back with extra analytics attributes for barcode step' do
expect(@analytics).to receive(:track_event).with(
expect(@analytics).to have_logged_event(
'IdV: cancellation go back',
step: 'barcode',
step: 'first',
proofing_components: nil,
cancelled_enrollment: false,
enrollment_code: enrollment.enrollment_code,
enrollment_id: enrollment.id,
cancelled_enrollment: nil,
enrollment_code: nil,
enrollment_id: nil,
)

put :update, params: { step: 'barcode', cancel: 'true' }
end

it 'redirects to idv_path' do
Expand All @@ -140,6 +129,23 @@
expect(response).to redirect_to idv_url
end

context 'in-person proofing' do
let!(:enrollment) { create(:in_person_enrollment, :pending, user: user) }

it 'logs cancellation go back with extra analytics attributes for barcode step' do
put :update, params: { step: 'barcode', cancel: 'true' }

expect(@analytics).to have_logged_event(
'IdV: cancellation go back',
step: 'barcode',
proofing_components: nil,
cancelled_enrollment: false,
enrollment_code: enrollment.enrollment_code,
enrollment_id: enrollment.id,
)
end
end

context 'with go back path stored in session' do
let(:go_back_path) { '/path/to/return' }

Expand All @@ -162,13 +168,13 @@
stub_sign_in
stub_analytics

expect(@analytics).to receive(:track_event).with(
delete :destroy, params: { step: 'first' }

expect(@analytics).to have_logged_event(
'IdV: cancellation confirmed',
step: 'first',
proofing_components: nil,
)

delete :destroy, params: { step: 'first' }
end

context 'when no session' do
Expand Down
13 changes: 2 additions & 11 deletions spec/controllers/idv/forgot_password_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@
before do
stub_sign_in
stub_analytics

allow(@analytics).to receive(:track_event)
end

it 'tracks the event in analytics when referer is nil' do
get :new

expect(@analytics).to have_received(:track_event).with(
'IdV: forgot password visited',
proofing_components: nil,
)
expect(@analytics).to have_logged_event('IdV: forgot password visited')
end
end

Expand All @@ -32,7 +27,6 @@
stub_sign_in(user)
stub_analytics
stub_attempts_tracker
allow(@analytics).to receive(:track_event)
end

it 'tracks appropriate events' do
Expand All @@ -42,10 +36,7 @@

post :update

expect(@analytics).to have_received(:track_event).with(
'IdV: forgot password confirmed',
proofing_components: nil,
)
expect(@analytics).to have_logged_event('IdV: forgot password confirmed')
end
end
end
8 changes: 4 additions & 4 deletions spec/controllers/idv/otp_verification_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rails_helper'

RSpec.describe Idv::OtpVerificationController do
RSpec.describe Idv::OtpVerificationController,
allowed_extra_analytics: [:sample_bucket1, :sample_bucket2] do
let(:user) { create(:user) }

let(:phone) { '2255555000' }
Expand Down Expand Up @@ -28,7 +29,6 @@
before do
stub_analytics
stub_attempts_tracker
allow(@analytics).to receive(:track_event)
allow(subject).to receive(:ab_test_analytics_buckets).and_return(ab_test_args)

sign_in(user)
Expand Down Expand Up @@ -81,7 +81,7 @@
it 'tracks an analytics event' do
get :show

expect(@analytics).to have_received(:track_event).with(
expect(@analytics).to have_logged_event(
'IdV: phone confirmation otp visited',
proofing_components: nil,
)
Expand Down Expand Up @@ -184,7 +184,7 @@
**ab_test_args,
}

expect(@analytics).to have_received(:track_event).with(
expect(@analytics).to have_logged_event(
'IdV: phone confirmation otp submitted',
expected_result,
)
Expand Down
Loading