Skip to content

Commit

Permalink
Refactor: analytics for claims_provider (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman authored Oct 1, 2024
2 parents df3bf4a + 5f56d3d commit f99b434
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions benefits/eligibility/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, request, event_type, flow: models.EnrollmentFlow, enrollment_
self.update_enrollment_flows(flow)


class SelectedVerifierEvent(EligibilityEvent):
class SelectedFlowEvent(EligibilityEvent):
"""Analytics event representing the user selecting an enrollment flow."""

def __init__(self, request, flow: models.EnrollmentFlow, enrollment_method=models.EnrollmentMethods.DIGITAL):
Expand All @@ -40,9 +40,9 @@ def __init__(
self.update_event_properties(status=status, error=error)


def selected_verifier(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
"""Send the "selected eligibility verifier" analytics event."""
core.send_event(SelectedVerifierEvent(request, flow, enrollment_method=enrollment_method))
def selected_flow(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
"""Send the "selected enrollment flow" analytics event."""
core.send_event(SelectedFlowEvent(request, flow, enrollment_method=enrollment_method))


def started_eligibility(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
Expand Down
2 changes: 1 addition & 1 deletion benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def index(request):
flow = EnrollmentFlow.objects.get(id=flow_id)
session.update(request, flow=flow)

analytics.selected_verifier(request, flow)
analytics.selected_flow(request, flow)

eligibility_start = reverse(routes.ELIGIBILITY_START)
response = redirect(eligibility_start)
Expand Down
2 changes: 1 addition & 1 deletion benefits/in_person/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def eligibility(request):
flow_id = form.cleaned_data.get("flow")
flow = models.EnrollmentFlow.objects.get(id=flow_id)
session.update(request, flow=flow)
eligibility_analytics.selected_verifier(request, flow, enrollment_method=models.EnrollmentMethods.IN_PERSON)
eligibility_analytics.selected_flow(request, flow, enrollment_method=models.EnrollmentMethods.IN_PERSON)
eligibility_analytics.started_eligibility(request, flow, enrollment_method=models.EnrollmentMethods.IN_PERSON)

in_person_enrollment = reverse(routes.IN_PERSON_ENROLLMENT)
Expand Down
6 changes: 3 additions & 3 deletions benefits/oauth/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class OAuthEvent(core.Event):

def __init__(self, request, event_type):
super().__init__(request, event_type)
verifier = session.flow(request)
if verifier and verifier.uses_claims_verification:
self.update_event_properties(auth_provider=verifier.claims_provider.client_name)
flow = session.flow(request)
if flow and flow.uses_claims_verification:
self.update_event_properties(claims_provider=flow.claims_provider.client_name)


class OAuthErrorEvent(OAuthEvent):
Expand Down
2 changes: 1 addition & 1 deletion docs/development/application-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ flowchart LR
agency -. update -.-o session
eligibility -. update -.-o session
eligibility -. selected eligibility verifier -.-o analytics
eligibility -. selected enrollment flow -.-o analytics
```

Depending upon the choice of enrollment pathway, the _Next phase_ above may be:
Expand Down
4 changes: 2 additions & 2 deletions docs/product-and-design/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Read more on each of these events on the [Amplitude event documentation for Bene

### Eligibility events

These events track the progress of a user choosing an eligibility verifier and completing eligibility verification.
These events track the progress of a user choosing an enrollment flow and completing eligibility verification.

- selected enrollment flow
- started eligibility
Expand All @@ -100,5 +100,5 @@ Read more on each of these events on the [Amplitude event documentation for Bene
Various key metrics are collected and analyzed, including:

- **Number of users who successfully completed authentication**: Users who `started sign in`, `finished sign in`
- **Number of users who successfully verified eligibility**: Users who completed the above and `selected eligibility verifier`, `started eligibility`, `returned eligibility` with a status of `True`
- **Number of users who successfully verified eligibility**: Users who completed the above and `selected enrollment flow`, `started eligibility`, `returned eligibility` with a status of `True`
- **Numbers of users who successfully completed enrollment**: Users who completed all of the above and `started card tokenization`, `ended card tokenization` and `returned enrollment` with a status of `Success`
2 changes: 1 addition & 1 deletion tests/pytest/eligibility/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_index_post_valid_form(client, model_EnrollmentFlow, mocked_session_upda
assert response.status_code == 302
assert response.url == reverse(routes.ELIGIBILITY_START)
assert mocked_session_update.call_args.kwargs["flow"] == model_EnrollmentFlow
mocked_analytics_module.selected_verifier.assert_called_once()
mocked_analytics_module.selected_flow.assert_called_once()


@pytest.mark.django_db
Expand Down
6 changes: 3 additions & 3 deletions tests/pytest/oauth/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def test_OAuthEvent_flow_client_name_when_uses_claims_verification(app_request,

event = OAuthEvent(app_request, "event type")

assert "auth_provider" in event.event_properties
assert event.event_properties["auth_provider"] == mocked_flow.claims_provider.client_name
assert "claims_provider" in event.event_properties
assert event.event_properties["claims_provider"] == mocked_flow.claims_provider.client_name


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_flow_does_not_use_claims_verification")
def test_OAuthEvent_flow_no_client_name_when_does_not_use_claims_verification(app_request):
event = OAuthEvent(app_request, "event type")

assert "auth_provider" not in event.event_properties
assert "claims_provider" not in event.event_properties


@pytest.mark.django_db
Expand Down

0 comments on commit f99b434

Please sign in to comment.