Repository: cal-itp/benefits

Issue:
Investigate missing event properties
In #1057 we made some changes to the base `Event` type, to include an `eligibility_types` property on all events we send into Amplitude.

## OAuth events

Looking at the event reports over the last 14 days of production data, the [`started sign in` event](https://github.com/cal-itp/benefits/blob/dev/benefits/oauth/analytics.py#L16) is missing the `eligibility_types` property in 100% of recorded events. [See report here](https://data.amplitude.com/compiler/Benefits/events/main/latest/started%20sign%20in).

## Eligibility events

We're also seeing unexpected behavior with the `eligibility` events for `courtesy_card`: the `eligiblity_types` property is coming through with the `event_properties`, but not with `user_properties`, leading to blanks/`(none)` when plotting the events on user-based charts. 

For example, this [user checked `courtesy_card` eligibility](https://analytics.amplitude.com/compiler/project/304110/search/amplitude_id%3D555656738955?collapsed=true&sessionHandle=YXoogID_YXoogIG_IFfuPiL_BKPu_2b6a1cea-210a-8693-6f25-38c5de0f39c3&eventId=b505e207-9ca1-11ed-967a-9bb610a8bd25) and we can see the value in the raw `event_properties` output, but not `user_properties`:

```json
{
  "amplitude_id": 555656738955,
  "app": 304110,
  "client_event_time": "2023-01-25 11:16:23.396000",
  "client_upload_time": "2023-01-25 11:16:23.506000",
  "data_type": "event",
  "display_name": "started eligibility",
  "event_id": 664,
  "event_properties": {
    "eligibility_types": [
      "courtesy_card"
    ],
    "eligibility_verifier": "MST Courtesy Card Eligibility Server Verifier",
    "path": "/eligibility/confirm",
    "transit_agency": "Monterey-Salinas Transit"
  },
  "event_time": "2023-01-25 11:16:23.396000",
  "event_type": "started eligibility",
  "language": "English",
  "library": "http/2.0",
  "server_received_time": "2023-01-25 11:16:23.506000",
  "server_upload_time": "2023-01-25 11:16:23.508000",
  "session_id": 1674645209603,
  "source_id": null,
  "start_version": "2023.01.1",
  "timeline_hidden": false,
  "user_creation_time": "2023-01-25 11:13:29.606000",
  "user_id": "35aabc7e-d98c-451d-95ec-e4033fcec987",
  "user_properties": {
    "eligibility_verifier": "MST Courtesy Card Eligibility Server Verifier",
    "referrer": "https://benefits.calitp.org/eligibility/confirm",
    "referring_domain": "benefits.calitp.org",
    "transit_agency": "Monterey-Salinas Transit",
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
  },
  "uuid": "b505e207-9ca1-11ed-967a-9bb610a8bd25",
  "version_name": "2023.01.1"
}
```

And the resulting user chart shows categorizes this event as `(none)`:

<img width="680" alt="image" src="https://user-images.githubusercontent.com/1783439/215842237-10a52ea7-5bad-4fa2-ad08-004e01d1f174.png">



Discussion:

Resolving patch:
diff --git a/benefits/eligibility/analytics.py b/benefits/eligibility/analytics.py
--- a/benefits/eligibility/analytics.py
+++ b/benefits/eligibility/analytics.py
@@ -11,6 +11,7 @@ def __init__(self, request, event_type, eligibility_types):
         super().__init__(request, event_type)
         # overwrite core.Event eligibility_types
         self.update_event_properties(eligibility_types=eligibility_types)
+        self.update_user_properties(eligibility_types=eligibility_types)
 
 
 class SelectedVerifierEvent(EligibilityEvent):


Test patch:
diff --git a/tests/pytest/eligibility/test_analytics.py b/tests/pytest/eligibility/test_analytics.py
--- a/tests/pytest/eligibility/test_analytics.py
+++ b/tests/pytest/eligibility/test_analytics.py
@@ -1,10 +1,10 @@
 import pytest
 
-from benefits.eligibility.analytics import EligibilityEvent, ReturnedEligibilityEvent
+from benefits.eligibility.analytics import EligibilityEvent
 
 
 @pytest.mark.django_db
-def test_EligibilityEvent_overwrites_event_eligibility_types(app_request, mocker):
+def test_EligibilityEvent_overwrites_eligibility_types(app_request, mocker):
     key, type1, type2 = "eligibility_types", "type1", "type2"
     mocker.patch("benefits.core.analytics.session.eligibility", return_value=[type1])
     mocker.patch("benefits.core.analytics.EligibilityType.get_names", return_value=[type1])
@@ -16,21 +16,7 @@ def test_EligibilityEvent_overwrites_event_eligibility_types(app_request, mocker
     assert type2 in event.event_properties[key]
     assert type1 not in event.event_properties[key]
 
-    # user_properties should not have been overwritten
-    assert key in event.user_properties
-    assert type1 in event.user_properties[key]
-    assert type2 not in event.user_properties[key]
-
-
-@pytest.mark.django_db
-def test_ReturnedEligibilityEvent_success_overwrites_user_eligibility_types(app_request, mocker):
-    key, type1, type2 = "eligibility_types", "type1", "type2"
-    mocker.patch("benefits.core.analytics.session.eligibility", return_value=[type1])
-    mocker.patch("benefits.core.analytics.EligibilityType.get_names", return_value=[type1])
-
-    event = ReturnedEligibilityEvent(app_request, eligibility_types=[type2], status="success")
-
     # user_properties should have been overwritten
     assert key in event.user_properties
-    assert type1 not in event.user_properties[key]
     assert type2 in event.user_properties[key]
+    assert type1 not in event.user_properties[key]