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: implementation / enhancements of analytics #348

Merged
merged 8 commits into from
Mar 21, 2024
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 @@ -14,39 +14,45 @@ public enum AuthMethod: Equatable {
public var analyticsValue: String {
switch self {
case .password:
"Password"
"password"
case .socailAuth(let socialAuthMethod):
socialAuthMethod.rawValue
}
}
}

public enum SocialAuthMethod: String {
case facebook = "Facebook"
case google = "Google"
case microsoft = "Microsoft"
case apple = "Apple"
case facebook = "facebook"
case google = "google"
case microsoft = "microsoft"
case apple = "apple"
}

//sourcery: AutoMockable
public protocol AuthorizationAnalytics {
func identify(id: String, username: String, email: String)
func userLogin(method: AuthMethod)
func signUpClicked()
func registerClicked()
func signInClicked()
func userSignInClicked()
func createAccountClicked()
func registrationSuccess()
func registrationSuccess(method: String)
func forgotPasswordClicked()
func resetPasswordClicked(success: Bool)
func resetPasswordClicked()
func resetPassword(success: Bool)
}

#if DEBUG
class AuthorizationAnalyticsMock: AuthorizationAnalytics {
func identify(id: String, username: String, email: String) {}
public func userLogin(method: AuthMethod) {}
public func signUpClicked() {}
public func registerClicked() {}
public func signInClicked() {}
public func userSignInClicked() {}
public func createAccountClicked() {}
public func registrationSuccess() {}
public func registrationSuccess(method: String) {}
public func forgotPasswordClicked() {}
public func resetPasswordClicked(success: Bool) {}
public func resetPasswordClicked() {}
public func resetPassword(success: Bool) {}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class SignInViewModel: ObservableObject {
errorMessage = AuthLocalization.Error.invalidPasswordLenght
return
}

analytics.userSignInClicked()
isShowProgress = true
do {
let user = try await interactor.login(username: username, password: password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public struct SignUpView: View {
StyledButton(AuthLocalization.SignUp.createAccountBtn) {
viewModel.thirdPartyAuthSuccess = false
Task {
await viewModel.registerUser()
await viewModel.registerUser(authMetod: viewModel.authMethod)
}
viewModel.trackCreateAccountClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class SignUpViewModel: ObservableObject {
private let interactor: AuthInteractorProtocol
private let analytics: AuthorizationAnalytics
private let validator: Validator
var authMethod: AuthMethod = .password

public init(
interactor: AuthInteractorProtocol,
Expand Down Expand Up @@ -121,7 +122,7 @@ public class SignUpViewModel: ObservableObject {
private var backend: String?

@MainActor
func registerUser() async {
func registerUser(authMetod: AuthMethod = .password) async {
do {
let validateFields = configureFields()
let errors = try await interactor.validateRegistrationFields(fields: validateFields)
Expand All @@ -132,7 +133,7 @@ public class SignUpViewModel: ObservableObject {
isSocial: externalToken != nil
)
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.registrationSuccess()
analytics.registrationSuccess(method: authMetod.analyticsValue)
isShowProgress = false
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)

Expand Down Expand Up @@ -198,7 +199,8 @@ public class SignUpViewModel: ObservableObject {
self.backend = backend
thirdPartyAuthSuccess = true
isShowProgress = false
await registerUser()
self.authMethod = authMethod
await registerUser(authMetod: authMethod)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ public class ResetPasswordViewModel: ObservableObject {
return
}
isShowProgress = true
analytics.resetPasswordClicked()
do {
_ = try await interactor.resetPassword(email: email).responseText.hideHtmlTagsAndUrls()
isRecovered.wrappedValue.toggle()
analytics.resetPasswordClicked(success: true)
analytics.resetPassword(success: true)
isShowProgress = false
} catch {
isShowProgress = false
analytics.resetPasswordClicked(success: false)
analytics.resetPassword(success: false)
if let validationError = error.validationError,
let value = validationError.data?["value"] as? String {
errorMessage = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public struct StartupView: View {
struct StartupView_Previews: PreviewProvider {
static var previews: some View {
let vm = StartupViewModel(
router: AuthorizationRouterMock()
router: AuthorizationRouterMock(),
analytics: CoreAnalyticsMock()
)

StartupView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@ import Core

public class StartupViewModel: ObservableObject {
let router: AuthorizationRouter
let analytics: CoreAnalytics

@Published var searchQuery: String?

public init(
router: AuthorizationRouter
router: AuthorizationRouter,
analytics: CoreAnalytics
) {
self.router = router
self.analytics = analytics
}

func logAnalytics(searchQuery: String?) {
if let searchQuery {
analytics.trackEvent(
.logistrationCoursesSearch,
biValue: .logistrationCoursesSearch,
parameters: [EventParamKey.searchQuery: searchQuery]
)
} else {
analytics.trackEvent(.logistrationExploreAllCourses, biValue: .logistrationExploreAllCourses)
}
}
}
Loading
Loading