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
3 changes: 2 additions & 1 deletion app/controllers/idv/cancellations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class CancellationsController < ApplicationController
before_action :confirm_idv_needed

def new
analytics.track_event(Analytics::IDV_CANCELLATION)
properties = ParseControllerFromReferer.new(request.referer).call
analytics.track_event(Analytics::IDV_CANCELLATION, properties)
@presenter = CancellationPresenter.new(view_context: view_context)
end

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/idv/come_back_later_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class ComeBackLaterController < ApplicationController

before_action :confirm_user_needs_usps_confirmation

def show; end
def show
analytics.track_event(Analytics::IDV_COME_BACK_LATER_VISIT)
end

private

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/idv/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class SessionsController < ApplicationController
delegate :attempts_exceeded?, to: :step, prefix: true

def new
analytics.track_event(Analytics::IDV_BASIC_INFO_VISIT)
user_session[:context] = 'idv'
set_idv_form
@selected_state = user_session[:idv_jurisdiction]
analytics.track_event(Analytics::IDV_BASIC_INFO_VISIT)
end

def create
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ def destroy
private

def track_account_deletion_event
controller_and_action_from_referer = ParseControllerFromReferer.new(request.referer).call
properties = {
request_came_from: controller_and_action_from_referer,
}
properties = ParseControllerFromReferer.new(request.referer).call
analytics.track_event(Analytics::ACCOUNT_DELETION, properties)
end

Expand Down
1 change: 1 addition & 0 deletions app/services/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def browser
IDV_BASIC_INFO_SUBMITTED_VENDOR = 'IdV: basic info vendor submitted'.freeze
IDV_CANCELLATION = 'IdV: cancellation visited'.freeze
IDV_CANCELLATION_CONFIRMED = 'IdV: cancellation confirmed'.freeze
IDV_COME_BACK_LATER_VISIT = 'IdV: come back later visited'.freeze
IDV_MAX_ATTEMPTS_EXCEEDED = 'IdV: max attempts exceeded'.freeze
IDV_FINAL = 'IdV: final resolution'.freeze
IDV_INTRO_VISIT = 'IdV: intro visited'.freeze
Expand Down
5 changes: 2 additions & 3 deletions app/services/parse_controller_from_referer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ def initialize(referer)
end

def call
return 'no referer' if referer.nil?

controller_and_action_from_referer
{ request_came_from: controller_and_action_from_referer }
end

private

attr_reader :referer

def controller_and_action_from_referer
return 'no referer' if referer.nil?
"#{controller_that_made_the_request}##{controller_action}"
end

Expand Down
16 changes: 14 additions & 2 deletions spec/controllers/idv/cancellations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

describe Idv::CancellationsController do
describe '#new' do
it 'tracks an analytics event' do
it 'tracks the event in analytics when referer is nil' do
stub_sign_in
stub_analytics
properties = { request_came_from: 'no referer' }

expect(@analytics).to receive(:track_event).with(Analytics::IDV_CANCELLATION, properties)

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/'
properties = { request_came_from: 'users/sessions#new' }

expect(@analytics).to receive(:track_event).with(Analytics::IDV_CANCELLATION)
expect(@analytics).to receive(:track_event).with(Analytics::IDV_CANCELLATION, properties)

get :new
end
Expand Down
4 changes: 4 additions & 0 deletions spec/controllers/idv/come_back_later_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

context 'user needs USPS address verification' do
it 'renders the show template' do
stub_analytics

expect(@analytics).to receive(:track_event).with(Analytics::IDV_COME_BACK_LATER_VISIT)

get :show

expect(response).to render_template :show
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
parser = instance_double(ParseControllerFromReferer)

expect(ParseControllerFromReferer).to receive(:new).and_return(parser)
expect(parser).to receive(:call)
expect(parser).to receive(:call).and_return({})

delete :destroy
end
Expand Down
6 changes: 4 additions & 2 deletions spec/services/parse_controller_from_referer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
context 'when the referer is nil' do
it 'returns "no referer" string' do
parser = ParseControllerFromReferer.new(nil)
result = { request_came_from: 'no referer' }

expect(parser.call).to eq 'no referer'
expect(parser.call).to eq result
end
end

context 'when the referer is present' do
it 'returns the corresponding controller and action' do
parser = ParseControllerFromReferer.new('http://example.com/')
result = { request_came_from: 'users/sessions#new' }

expect(parser.call).to eq 'users/sessions#new'
expect(parser.call).to eq result
end
end
end
Expand Down