-
Notifications
You must be signed in to change notification settings - Fork 9
/
analytics.py
66 lines (43 loc) · 2.61 KB
/
analytics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
The eligibility application: analytics implementation.
"""
from benefits.core import analytics as core
class EligibilityEvent(core.Event):
"""Base analytics event for eligibility verification."""
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):
"""Analytics event representing the user selecting an eligibility verifier."""
def __init__(self, request, eligibility_types):
super().__init__(request, "selected eligibility verifier", eligibility_types)
class StartedEligibilityEvent(EligibilityEvent):
"""Analytics event representing the beginning of an eligibility verification check."""
def __init__(self, request, eligibility_types):
super().__init__(request, "started eligibility", eligibility_types)
class ReturnedEligibilityEvent(EligibilityEvent):
"""Analytics event representing the end of an eligibility verification check."""
def __init__(self, request, eligibility_types, status, error=None):
super().__init__(request, "returned eligibility", eligibility_types)
status = str(status).lower()
if status in ("error", "fail", "success"):
self.update_event_properties(status=status, error=error)
if status == "success":
self.update_user_properties(eligibility_types=eligibility_types)
def selected_verifier(request, eligibility_types):
"""Send the "selected eligibility verifier" analytics event."""
core.send_event(SelectedVerifierEvent(request, eligibility_types))
def started_eligibility(request, eligibility_types):
"""Send the "started eligibility" analytics event."""
core.send_event(StartedEligibilityEvent(request, eligibility_types))
def returned_error(request, eligibility_types, error):
"""Send the "returned eligibility" analytics event with an error status."""
core.send_event(ReturnedEligibilityEvent(request, eligibility_types, status="error", error=error))
def returned_fail(request, eligibility_types):
"""Send the "returned eligibility" analytics event with a fail status."""
core.send_event(ReturnedEligibilityEvent(request, eligibility_types, status="fail"))
def returned_success(request, eligibility_types):
"""Send the "returned eligibility" analytics event with a success status."""
core.send_event(ReturnedEligibilityEvent(request, eligibility_types, status="success"))