Skip to content

Commit

Permalink
Track eight events from Pinwheel modal interactions
Browse files Browse the repository at this point in the history
These events cover most of what we're hoping to instrument for future
Pinwheel sessions. In the order a user may experience them:

1. `PinwheelShowProviderConfirmationPage` - sent when a provider
   confirmation screen is shown (e.g. "Amazon" showing multiple
   platforms like A to Z and ADP)
2. `PinwheelShowLoginPage` - sent when the first screen of a login is
   shown (whether it's employer disambiguation, username/password, or
   other input required by user)
3. `PinwheelAttemptLogin` - sent when the user attempts login (sent only
   once on the first screen even if there are subsequent screens for MFA
   or other employer-specific questions). Unfortunately, there are no
   Pinwheel events on the subsequent login pages.
4. `PinwheelError` - sent when an error occurs, likely an incorrect
   login or MFA code, but also a system error.
5. `PinwheelSuccess` - sent when the login completes.

If the user doesn't follow the intended path through the modal, they may
trigger:
6. `PinwheelShowDefaultProviderSearch` - sent when the user deselects
   the employer or platform and returns to the beginning of the pinwheel
   modal
7. `PinwheelAttemptClose` - shown when the user clicks the "X" in the
   modal, before confirming the closure
8. `PinwheelCloseModal` - shown when the modal actually closes
  • Loading branch information
tdooner committed Dec 31, 2024
1 parent 5d10d30 commit ac93d9e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
10 changes: 9 additions & 1 deletion app/app/controllers/api/pinwheel_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class Api::PinwheelController < ApplicationController

EVENT_NAMES = %w[
ApplicantSelectedEmployerOrPlatformItem
PinwheelAttemptClose
PinwheelAttemptLogin
PinwheelCloseModal
PinwheelError
PinwheelShowDefaultProviderSearch
PinwheelShowLoginPage
PinwheelShowProviderConfirmationPage
PinwheelSuccess
]

# run the token here with the included employer/payroll provider id
Expand Down Expand Up @@ -51,7 +59,7 @@ def user_action
private

def user_action_params
params.fetch(:pinwheel, {}).permit(:event_name, attributes: {})
params.fetch(:pinwheel, {}).permit(:event_name, :locale, attributes: {})
end

def token_params
Expand Down
44 changes: 33 additions & 11 deletions app/app/javascript/controllers/cbv/employer_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,43 @@ export default class extends Controller {
event.preventDefault()
}

onPinwheelError(event) {
const { type, code } = event;
console.error("Got Pinwheel Error:", type, event);

if (window.NREUM) {
window.NREUM.addPageAction("PinwheelError", { type, code, cbvFlowId: this.cbvFlowIdValue })
}
}

onPinwheelEvent(eventName, eventPayload) {
if (eventName === 'success') {
const { accountId } = eventPayload;
const { accountId } = eventPayload
this.userAccountIdTarget.value = accountId
trackUserAction("PinwheelSuccess", {
account_id: eventPayload.accountId,
platform_id: eventPayload.platformId
})
this.formTarget.submit();
} else if (eventName === 'screen_transition') {
const { screenName } = eventPayload

switch (screenName) {
case "LOGIN":
trackUserAction("PinwheelShowLoginPage", {
screen_name: screenName,
employer_name: eventPayload.selectedEmployerName,
platform_name: eventPayload.selectedPlatformName
})
break
case "PROVIDER_CONFIRMATION":
trackUserAction("PinwheelShowProviderConfirmationPage", {})
break
case "SEARCH_DEFAULT":
trackUserAction("PinwheelShowDefaultProviderSearch", {})
break
case "EXIT_CONFIRMATION":
trackUserAction("PinwheelAttemptClose", {})
break
}
} else if (eventName === 'login_attempt') {
trackUserAction("PinwheelAttemptLogin", {})
} else if (eventName === 'error') {
const { type, code, message } = eventPayload
trackUserAction("PinwheelError", { type, code, message })
} else if (eventName === 'exit') {
trackUserAction("PinwheelCloseModal", {})
}
}

Expand Down Expand Up @@ -74,7 +97,6 @@ export default class extends Controller {
submit(token) {
this.pinwheel.then(Pinwheel => initializePinwheel(Pinwheel, token, {
onEvent: this.onPinwheelEvent.bind(this),
onError: this.onPinwheelError.bind(this),
onExit: this.reenableButtons.bind(this),
}));
}
Expand Down
25 changes: 25 additions & 0 deletions app/spec/controllers/api/pinwheel_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,30 @@
end
end
end

context "when tracking a PinwheelShowLoginPage event" do
let(:event_name) { "PinwheelShowLoginPage" }
let(:event_attributes) do
{
screen_name: "LOGIN",
employer_name: "Bob's Burgers",
platform_name: "Test Payroll Platform Name",
locale: "en"
}
end

it "tracks an event with NewRelic" do
expect(NewRelicEventTracker).to receive(:track).with("PinwheelShowLoginPage", {
timestamp: be_a(Integer),
cbv_flow_id: cbv_flow.id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
locale: "en",
screen_name: "LOGIN",
employer_name: "Bob's Burgers",
platform_name: "Test Payroll Platform Name"
}.stringify_keys)
post :user_action, params: valid_params
end
end
end
end

0 comments on commit ac93d9e

Please sign in to comment.