Skip to content
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

feat: add analytics events for the login flow #3038

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private enum ViewState
public override CanvasOrdering.SortingLayer Layer => CanvasOrdering.SortingLayer.Fullscreen;

public ReactiveProperty<AuthenticationStatus> CurrentState { get; } = new (AuthenticationStatus.Init);
public string CurrentRequestID { get; private set; } = string.Empty;

public AuthenticationScreenController(
ViewFactoryMethod viewFactory,
Expand Down Expand Up @@ -251,6 +252,8 @@ async UniTaskVoid StartLoginFlowUntilEndAsync(CancellationToken ct)
{
try
{
CurrentRequestID = string.Empty;

viewInstance!.ConnectingToServerContainer.SetActive(true);
viewInstance.LoginButton.interactable = false;

Expand Down Expand Up @@ -289,9 +292,10 @@ async UniTaskVoid StartLoginFlowUntilEndAsync(CancellationToken ct)
StartLoginFlowUntilEndAsync(loginCancellationToken.Token).Forget();
}

private void ShowVerification(int code, DateTime expiration)
private void ShowVerification(int code, DateTime expiration, string requestID)
{
viewInstance!.VerificationCodeLabel.text = code.ToString();
CurrentRequestID = requestID;

CancelVerificationCountdown();
verificationCountdownCancellationToken = new CancellationTokenSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ MonoBehaviour:
isEnabled: 1
- eventName: error
isEnabled: 1
- eventName: loading_error
isEnabled: 1
- groupName: Map
events:
- eventName: map_jump_in
Expand Down Expand Up @@ -85,6 +87,16 @@ MonoBehaviour:
isEnabled: 1
- eventName: delete_photo
isEnabled: 1
- groupName: Authentication
events:
- eventName: logged_in_cached
isEnabled: 1
- eventName: logged_in
isEnabled: 1
- eventName: login_requested
isEnabled: 1
- eventName: verification_requested
isEnabled: 1
useLocalEnvVariableFallback: 0
flushSize: 20
flushInterval: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,13 @@ public static class Livekit
{
public const string LIVEKIT_HEALTH_CHECK_FAILED = "livekit_health_check_failed"; // 🔴 - needs testing
}

public static class Authentication
{
public const string LOGGED_IN_CACHED = "logged_in_cached";
public const string LOGGED_IN = "logged_in";
public const string LOGIN_REQUESTED = "login_requested";
public const string VERIFICATION_REQUESTED = "verification_requested";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using DCL.AuthenticationScreenFlow;
using Segment.Serialization;
using System;
using static DCL.AuthenticationScreenFlow.AuthenticationScreenController;
using static DCL.PerformanceAndDiagnostics.Analytics.AnalyticsEvents;

namespace DCL.PerformanceAndDiagnostics.Analytics
{
public class AuthenticationScreenAnalytics : IDisposable
{
private const string STAGE_KEY = "state";
private const string STATE_KEY = "state";

private readonly IAnalyticsController analytics;
private readonly AuthenticationScreenController authenticationController;
Expand All @@ -26,12 +28,35 @@ public void Dispose()
authenticationController.CurrentState.OnUpdate -= OnAuthenticationScreenStateChanged;
}

private void OnAuthenticationScreenStateChanged(AuthenticationScreenController.AuthenticationStatus state)
private void OnAuthenticationScreenStateChanged(AuthenticationStatus state)
{
analytics.Track(AnalyticsEvents.General.INITIAL_LOADING, new JsonObject
analytics.Track(General.INITIAL_LOADING, new JsonObject
{
{ STAGE_KEY, $"7.0.{++stepsCounter} - authentication state: {state.ToString()}" },
{ STATE_KEY, $"7.0.{++stepsCounter} - authentication state: {state.ToString()}" },
});

switch (state)
{
// Triggers when the user is already logged in
case AuthenticationStatus.LoggedInCached:
analytics.Track(Authentication.LOGGED_IN_CACHED); break;

// Triggers when the user is not logged in (login is requested)
// TODO: We should also track the auth Request UUID here to link the explorer_v2 event with the auth page view and login events.
case AuthenticationStatus.Login:
analytics.Track(Authentication.LOGIN_REQUESTED); break;

// Triggered when the user tries to log in and is redirected to the authentication site
case AuthenticationStatus.VerificationInProgress:
analytics.Track(Authentication.VERIFICATION_REQUESTED, new JsonObject
{
{ "requestID", authenticationController.CurrentRequestID },
}); break;

// Triggered when the user is logged in
case AuthenticationStatus.LoggedIn:
analytics.Track(Authentication.LOGGED_IN); break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async UniTask<IWeb3Identity> LoginAsync(CancellationToken ct)

await UniTask.SwitchToMainThread(ct);

loginVerificationCallback?.Invoke(authenticationResponse.code, signatureExpiration);
loginVerificationCallback?.Invoke(authenticationResponse.code, signatureExpiration, authenticationResponse.requestId);

LoginResponse response = await RequestWalletConfirmationAsync<LoginResponse>(authenticationResponse.requestId,
signatureExpiration, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace DCL.Web3.Authenticators
{
public interface IWeb3VerifiedAuthenticator : IWeb3Authenticator
{
public delegate void VerificationDelegate(int code, DateTime expiration);
public delegate void VerificationDelegate(int code, DateTime expiration, string requestID);

void SetVerificationListener(VerificationDelegate? callback);
}
Expand Down
Loading