Coverage for benefits/oauth/analytics.py: 78%
41 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-19 16:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-19 16:31 +0000
1"""
2The oauth application: analytics implementation.
3"""
5from benefits.core import analytics as core, session
8class OAuthEvent(core.Event):
9 """Base OAuth analytics event."""
11 def __init__(self, request, event_type):
12 super().__init__(request, event_type)
13 flow = session.flow(request)
14 if flow and flow.uses_claims_verification:
15 self.update_event_properties(claims_provider=flow.claims_provider.client_name)
18class OAuthErrorEvent(OAuthEvent):
19 """Analytics event representing an error using an OAuth client."""
21 def __init__(self, request, message, operation):
22 super().__init__(request, "oauth error")
23 self.update_event_properties(message=message, operation=operation)
26class StartedSignInEvent(OAuthEvent):
27 """Analytics event representing the beginning of the OAuth sign in flow."""
29 def __init__(self, request):
30 super().__init__(request, "started sign in")
33class CanceledSignInEvent(OAuthEvent):
34 """Analytics event representing the canceling of application sign in."""
36 def __init__(self, request):
37 super().__init__(request, "canceled sign in")
40class FinishedSignInEvent(OAuthEvent):
41 """Analytics event representing the end of the OAuth sign in flow."""
43 def __init__(self, request, error=None):
44 super().__init__(request, "finished sign in")
45 if error is not None:
46 self.update_event_properties(error_code=error)
49class StartedSignOutEvent(OAuthEvent):
50 """Analytics event representing the beginning of application sign out."""
52 def __init__(self, request):
53 super().__init__(request, "started sign out")
56class FinishedSignOutEvent(OAuthEvent):
57 """Analytics event representing the end of application sign out."""
59 def __init__(self, request):
60 super().__init__(request, "finished sign out")
61 self.update_event_properties(origin=session.origin(request))
64def error(request, message, operation):
65 """Send the "oauth error" analytics event, specifying the message and operation"""
66 core.send_event(OAuthErrorEvent(request, message, operation))
69def started_sign_in(request):
70 """Send the "started sign in" analytics event."""
71 core.send_event(StartedSignInEvent(request))
74def canceled_sign_in(request):
75 """Send the "canceled sign in" analytics event."""
76 core.send_event(CanceledSignInEvent(request))
79def finished_sign_in(request, error=None):
80 """Send the "finished sign in" analytics event."""
81 core.send_event(FinishedSignInEvent(request, error))
84def started_sign_out(request):
85 """Send the "started signed out" analytics event."""
86 core.send_event(StartedSignOutEvent(request))
89def finished_sign_out(request):
90 """Send the "finished sign out" analytics event."""
91 core.send_event(FinishedSignOutEvent(request))