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
8 changes: 1 addition & 7 deletions app/controllers/frontend_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

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

This mapping is not working as expected, and the events are still being logged with the "Frontend:" prefix. I think it has to do with the difference in case, "Show Password Button Clicked" vs. "Show Password button clicked".

Suggested change
'Show Password Button Clicked' => :show_password_button_clicked,
'Show Password button clicked' => :show_password_button_clicked,

}.transform_values do |method|
method.is_a?(Proc) ? method : AnalyticsEvents.instance_method(method)
end.freeze
Expand All @@ -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?

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { once } from '@18f/identity-decorators';
import { trackEvent } from '@18f/identity-analytics';

interface PasswordToggleElements {
/**
Expand All @@ -16,6 +17,7 @@ class PasswordToggleElement extends HTMLElement {
connectedCallback() {
this.elements.toggle.addEventListener('change', () => this.setInputType());
this.setInputType();
this.showPasswordButtonClick();
}

@once()
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions spec/controllers/frontend_log_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down