-
Notifications
You must be signed in to change notification settings - Fork 7
Sign up analytics #767
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
Merged
Merged
Sign up analytics #767
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7cdea14
Swap enum SignUpSteps to SIGN_UP_STEPS add a SIGN_UP_STEPS_TO_STR map.
MelissaAutumn 566fb07
Add telemetry calls to the frontend
MelissaAutumn 3698eda
Add the telemetry endpoint to the backend
MelissaAutumn 803007f
Capture the first sign-up step in posthog and fixing capture call for…
davinotdavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { TELEMETRY_EVENTS } from "@/types"; | ||
| import { SIGN_UP_STEPS, SIGN_UP_STEPS_TO_STR } from "./stores/signUpFlowStore"; | ||
| import { CAPTURE_TELEMETRY } from "@/defines"; | ||
|
|
||
| /** | ||
| * Send the telemetry event to the server. This should not block! | ||
| */ | ||
| const sendTelemetryEvent = (event: TELEMETRY_EVENTS, properties: object | null = null) => { | ||
| if (!CAPTURE_TELEMETRY) { | ||
| return; | ||
| } | ||
| fetch('/api/v1/telemetry/event', { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| event, | ||
| event_properties: properties || null, | ||
| }), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-CSRFToken': window._page?.csrfToken, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export const captureSupportLinkClick = () => { | ||
| sendTelemetryEvent(TELEMETRY_EVENTS.SIGN_UP_SUPPORT) | ||
| }; | ||
|
|
||
| export const captureError = (error_string: string) => { | ||
| sendTelemetryEvent(TELEMETRY_EVENTS.SIGN_UP_ERROR, { 'error': error_string }); | ||
| }; | ||
|
|
||
| export const captureStep = (sign_up_step: SIGN_UP_STEPS) => { | ||
| sendTelemetryEvent(TELEMETRY_EVENTS.SIGN_UP_STEP, { 'step_num': sign_up_step, 'step_str': SIGN_UP_STEPS_TO_STR[sign_up_step] || SIGN_UP_STEPS_TO_STR[SIGN_UP_STEPS.INVALID] }) | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import uuid | ||
| from thunderbird_accounts.telemetry import capture | ||
| from rest_framework.permissions import AllowAny | ||
| from django.conf import settings | ||
| from rest_framework.throttling import UserRateThrottle | ||
| from rest_framework.decorators import api_view, throttle_classes, permission_classes | ||
| from rest_framework.exceptions import ValidationError | ||
| from rest_framework.request import Request | ||
| from rest_framework.response import Response | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
|
|
||
| class AnalyticsThrottle(UserRateThrottle): | ||
| scope = 'analytics' | ||
|
|
||
|
|
||
| @api_view(['POST']) | ||
| @permission_classes([AllowAny]) | ||
| @throttle_classes([AnalyticsThrottle]) | ||
| def capture_frontend_event(request: Request): | ||
| """This function simply takes the log event, | ||
| checks it against acceptable values and if it's valid then we log it. | ||
|
|
||
| This is a fire and forget function, | ||
| it's not vital that they actually capture but this function should not block the frontend either.""" | ||
|
|
||
| event = request.data.get('event') | ||
| event_properties = request.data.get('event_properties') | ||
| if not event or event not in settings.FRONTEND_EVENTS: | ||
| raise ValidationError(_('The event passed is not valid.')) | ||
|
|
||
| if request.user.is_authenticated: | ||
| capture(event, request.user.oidc_id, event_properties) | ||
| else: | ||
| capture(event, str(f'unauthenticated-{uuid.uuid4().hex}'), event_properties) | ||
|
|
||
| return Response(status=200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are only doing the
captureStepwhen the user moves to thenextStep, we are never capturing the initialSIGN_UP_STEPS.USERNAME.So maybe we should add a
captureStep()call in theonMountedof the Step1 component here:https://github.com/thunderbird/thunderbird-accounts/blob/main/assets/app/vue/views/SignUpView/views/Step1Username/index.vue#L54-L59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here:
2e3a27f#diff-a812072850682c732c5320480daba313c803e4c65fa4339595bdff4c111de829R61-R62