diff --git a/app/controllers/frontend_log_controller.rb b/app/controllers/frontend_log_controller.rb index 0231d8f5144..5516a0b690e 100644 --- a/app/controllers/frontend_log_controller.rb +++ b/app/controllers/frontend_log_controller.rb @@ -2,7 +2,6 @@ class FrontendLogController < ApplicationController respond_to :json skip_before_action :verify_authenticity_token - before_action :check_user_authenticated before_action :validate_parameter_types # rubocop:disable Layout/LineLength @@ -27,6 +26,7 @@ class FrontendLogController < ApplicationController 'IdV: download personal key' => :idv_personal_key_downloaded, 'IdV: Native camera forced after failed attempts' => :idv_native_camera_forced, 'Multi-Factor Authentication: download backup code' => :multi_factor_auth_backup_code_download, + 'Show Password Button Clicked' => :show_password_button_clicked, }.transform_values do |method| method.is_a?(Proc) ? method : AnalyticsEvents.instance_method(method) end.freeze @@ -48,12 +48,6 @@ def log_params params.permit(:event, payload: {}) end - def check_user_authenticated - return if effective_user - - render json: { success: false }, status: :unauthorized - end - def validate_parameter_types return if valid_event? && valid_payload? diff --git a/app/javascript/packages/password-toggle/password-toggle-element.spec.ts b/app/javascript/packages/password-toggle/password-toggle-element.spec.ts index bb3ec06f2ba..e2dd0229f68 100644 --- a/app/javascript/packages/password-toggle/password-toggle-element.spec.ts +++ b/app/javascript/packages/password-toggle/password-toggle-element.spec.ts @@ -1,10 +1,13 @@ import userEvent from '@testing-library/user-event'; import { getByLabelText } from '@testing-library/dom'; +import { useSandbox } from '@18f/identity-test-helpers'; +import * as analytics from '@18f/identity-analytics'; import './password-toggle-element'; import type PasswordToggleElement from './password-toggle-element'; describe('PasswordToggleElement', () => { let idCounter = 0; + const sandbox = useSandbox(); function createElement() { const element = document.createElement('lg-password-toggle') as PasswordToggleElement; @@ -45,4 +48,16 @@ describe('PasswordToggleElement', () => { expect(input.type).to.equal('text'); }); + + it('logs an event when clicking the Show Password button', async () => { + sandbox.stub(analytics, 'trackEvent'); + const element = createElement(); + const toggle = getByLabelText(element, 'Show password') as HTMLInputElement; + + await userEvent.click(toggle); + + expect(analytics.trackEvent).to.have.been.calledWith('Show Password button clicked', { + path: window.location.pathname, + }); + }); }); diff --git a/app/javascript/packages/password-toggle/password-toggle-element.ts b/app/javascript/packages/password-toggle/password-toggle-element.ts index efd9ec4c58f..58d4963cacc 100644 --- a/app/javascript/packages/password-toggle/password-toggle-element.ts +++ b/app/javascript/packages/password-toggle/password-toggle-element.ts @@ -1,4 +1,5 @@ import { once } from '@18f/identity-decorators'; +import { trackEvent } from '@18f/identity-analytics'; interface PasswordToggleElements { /** @@ -16,6 +17,7 @@ class PasswordToggleElement extends HTMLElement { connectedCallback() { this.elements.toggle.addEventListener('change', () => this.setInputType()); this.setInputType(); + this.showPasswordButtonClick(); } @once() @@ -29,6 +31,12 @@ class PasswordToggleElement extends HTMLElement { setInputType() { this.elements.input.type = this.elements.toggle.checked ? 'text' : 'password'; } + + showPasswordButtonClick() { + this.elements.toggle.addEventListener('click', () => { + trackEvent('Show Password button clicked', { path: window.location.pathname }); + }); + } } declare global { diff --git a/app/services/analytics_events.rb b/app/services/analytics_events.rb index 64804f71381..d347340688c 100644 --- a/app/services/analytics_events.rb +++ b/app/services/analytics_events.rb @@ -2593,5 +2593,10 @@ def contact_redirect(redirect_url:, step: nil, location: nil, flow: nil, **extra **extra, ) end + + # Tracks if a user clicks the "Show Password button" + def show_password_button_clicked + track_event('Show Password Button Clicked') + end end # rubocop:enable Metrics/ModuleLength diff --git a/spec/controllers/frontend_log_controller_spec.rb b/spec/controllers/frontend_log_controller_spec.rb index d899f6a0389..e98db41278f 100644 --- a/spec/controllers/frontend_log_controller_spec.rb +++ b/spec/controllers/frontend_log_controller_spec.rb @@ -173,19 +173,6 @@ end end - context 'user is not signed in' do - it 'returns unauthorized' do - allow(Analytics).to receive(:new).and_return(fake_analytics) - - expect(fake_analytics).not_to receive(:track_event) - - action - - expect(response).to have_http_status(:unauthorized) - expect(json[:success]).to eq(false) - end - end - context 'anonymous user with session-associated user id' do let(:user_id) { user.id }