Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: analytics for in-person eligibility/enrollment #2402

Merged
merged 7 commits into from
Oct 1, 2024

Conversation

lalver1
Copy link
Member

@lalver1 lalver1 commented Sep 25, 2024

Closes #2245

This PR implements in-person analytics events for

  • started eligibility
  • returned eligibility
  • selected enrollment flow
  • started card tokenization
  • ended card tokenization
  • returned enrollment
  • failed access token request

Since the started card tokenization and ended card tokenization events use the Amplitude browser SDK (instead of the HTTP API used by Client incore/analytics.py), the enrollment views and index.html template have been updated in aef5527 to include the enrollment_method field.

@lalver1 lalver1 self-assigned this Sep 25, 2024
@github-actions github-actions bot added back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev labels Sep 25, 2024
@lalver1 lalver1 force-pushed the feat/in-person-analytics branch from 802972c to 579aeda Compare September 25, 2024 14:29
Copy link

github-actions bot commented Sep 25, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  analytics.py
  benefits/eligibility
  analytics.py
  benefits/enrollment
  analytics.py 35
  benefits/in_person
  views.py 183
Project Total  

This report was generated by python-coverage-comment-action

@lalver1 lalver1 force-pushed the feat/in-person-analytics branch 2 times, most recently from 16fe317 to abd62bb Compare September 26, 2024 14:37
@lalver1 lalver1 marked this pull request as ready for review September 26, 2024 15:08
@lalver1 lalver1 requested a review from a team as a code owner September 26, 2024 15:08
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

This is really good so far.

@@ -30,6 +32,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.started_eligibility(request, flow, enrollment_method=models.EnrollmentMethods.IN_PERSON)
Copy link
Member

Choose a reason for hiding this comment

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

I would think we also want to send the selected enrollment flow event here, right? For consistency with the digital side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, good idea. Added it in 1595941

sentry_sdk.capture_exception(exception)
return redirect(routes.IN_PERSON_SERVER_ERROR)

case Status.REENROLLMENT_ERROR:
return redirect(routes.IN_PERSON_ENROLLMENT_REENROLLMENT_ERROR)
# GET enrollment index
else:
flow = session.flow(request)
eligibility_analytics.returned_success(request, flow, enrollment_method=models.EnrollmentMethods.IN_PERSON)
Copy link
Member

Choose a reason for hiding this comment

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

I think in general, we should move away from sending events in response to GET requests where possible.

It becomes easier to spam the events if all you need to do is visit the URL. Especially for these types of events where we do already have a POST-back, I think ideally the event should be sent there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that makes sense! Moved it to the POST section in e9f5ead

@@ -137,6 +155,7 @@ def enrollment(request):

def reenrollment_error(request):
"""View handler for a re-enrollment attempt that is not yet within the re-enrollment window."""
enrollment_analytics.returned_error(request, "Re-enrollment error.", enrollment_method=models.EnrollmentMethods.IN_PERSON)
Copy link
Member

Choose a reason for hiding this comment

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

Could be moved up into POST-back

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, moved it up in f5a376a

@@ -147,6 +166,7 @@ def reenrollment_error(request):

def retry(request):
"""View handler for card verification failure."""
enrollment_analytics.returned_retry(request, enrollment_method=models.EnrollmentMethods.IN_PERSON)
Copy link
Member

Choose a reason for hiding this comment

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

This one can't be moved since the user is sent here from JavaScript.

Would could enforce that this route is POST-only and make the from POST back to here... that doesn't have to happen in this PR though.

Copy link
Member Author

@lalver1 lalver1 Sep 27, 2024

Choose a reason for hiding this comment

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

Right 👍
So it turns out that the form's (form_retry) method is already POST, so would it be enough to wrap the analytics call in an if request.method == "POST":?

@lalver1 lalver1 force-pushed the feat/in-person-analytics branch from abd62bb to 1595941 Compare September 27, 2024 18:03
@lalver1 lalver1 force-pushed the feat/in-person-analytics branch from 60b1401 to 0ca7d95 Compare October 1, 2024 01:28
@lalver1 lalver1 merged commit 14369bb into main Oct 1, 2024
15 checks passed
@lalver1 lalver1 deleted the feat/in-person-analytics branch October 1, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send analytic events for in-person eligibility verification / enrollment
2 participants