feat: Add tracking event for IDV photo mode (#27349)

As part of the ongoing A/B experiment for IDV, we would like to know how users submitted their photos (either by upload or camera) in addition to the other information we are tracking
This commit is contained in:
alangsto
2021-04-15 11:07:40 -04:00
committed by GitHub
parent 9e66979945
commit a45bcd158b
2 changed files with 36 additions and 6 deletions

View File

@@ -1233,6 +1233,8 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
IMAGE_DATA = "data:image/png;base64,1234"
FULL_NAME = "Ḟüḷḷ Ṅäṁë"
EXPERIMENT_NAME = "test-experiment"
PORTRAIT_PHOTO_MODE = "upload"
ID_PHOTO_MODE = "camera"
def setUp(self):
super().setUp()
@@ -1392,12 +1394,14 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
self._submit_photos(face_image=self.IMAGE_DATA)
@patch('lms.djangoapps.verify_student.views.segment.track')
def test_experiment_name_param(self, mock_segment_track):
def test_experiment_params(self, mock_segment_track):
# Submit the photos
self._submit_photos(
face_image=self.IMAGE_DATA,
photo_id_image=self.IMAGE_DATA,
experiment_name=self.EXPERIMENT_NAME
experiment_name=self.EXPERIMENT_NAME,
portrait_photo_mode=self.PORTRAIT_PHOTO_MODE,
id_photo_mode=self.ID_PHOTO_MODE
)
# Verify that the attempt is created in the database
@@ -1405,15 +1409,23 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
assert attempt.status == 'submitted'
# assert that segment tracking has been called with experiment name
data = {
experiment_data = {
"attempt_id": attempt.id,
"experiment_name": self.EXPERIMENT_NAME
}
mock_segment_track.assert_any_call(self.user.id, "edx.bi.experiment.verification.attempt", data)
mock_segment_track.assert_any_call(self.user.id, "edx.bi.experiment.verification.attempt", experiment_data)
mode_data = {
"attempt_id": attempt.id,
"portrait_photo_mode": self.PORTRAIT_PHOTO_MODE,
"id_photo_mode": self.ID_PHOTO_MODE
}
mock_segment_track.assert_any_call(self.user.id, "edx.bi.experiment.verification.attempt.photo.mode", mode_data)
def _submit_photos(
self, face_image=None, photo_id_image=None,
full_name=None, experiment_name=None, expected_status_code=200
full_name=None, experiment_name=None,
portrait_photo_mode=None, id_photo_mode=None, expected_status_code=200
):
"""Submit photos for verification.
@@ -1443,6 +1455,12 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
if experiment_name is not None:
params['experiment_name'] = experiment_name
if portrait_photo_mode is not None:
params['portrait_photo_mode'] = portrait_photo_mode
if id_photo_mode is not None:
params['id_photo_mode'] = id_photo_mode
with self.immediate_on_commit():
response = self.client.post(url, params)
assert response.status_code == expected_status_code

View File

@@ -832,6 +832,8 @@ class SubmitPhotosView(View):
photo_id_image (str): base64-encoded image data of the user's photo ID.
full_name (str): The user's full name, if the user is requesting a name change as well.
experiment_name (str): The name of an A/B experiment associated with this attempt
portrait_photo_mode (str): The mode in which the portrait photo was taken
id_photo_mode (str): The mode in which the id photo was taken
"""
# If the user already has an initial verification attempt, we can re-use the photo ID
@@ -873,6 +875,14 @@ class SubmitPhotosView(View):
}
self._fire_event(request.user, "edx.bi.experiment.verification.attempt", data)
if params.get("portrait_photo_mode"):
mode_data = {
"attempt_id": attempt.id,
"portrait_photo_mode": params.get("portrait_photo_mode"),
"id_photo_mode": params.get("id_photo_mode")
}
self._fire_event(request.user, "edx.bi.experiment.verification.attempt.photo.mode", mode_data)
self._fire_event(request.user, "edx.bi.verify.submitted", {"category": "verification"})
self._send_confirmation_email(request.user)
return JsonResponse({})
@@ -896,7 +906,9 @@ class SubmitPhotosView(View):
"face_image",
"photo_id_image",
"full_name",
"experiment_name"
"experiment_name",
"portrait_photo_mode",
"id_photo_mode"
]
if param_name in request.POST
}