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: Firebase Crashlytics 모듈 추가 및 내부 이벤트 반영 코드 추가 #727

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion 14th-team5-iOS/App/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import UIKit
import AuthenticationServices
import Firebase
import FirebaseCore
import FirebaseAnalytics
import FirebaseMessaging
import KakaoSDKAuth
import RxKakaoSDKAuth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ final class CameraDisplayNavigator: CameraDisplayNavigatorProtocol {
func showErrorAlert() {
let confirmHandler: BBAlertActionHandler = { [weak self] alert in
self?.toCamera()
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickCameraButton(entry: .failedAlertConfirm))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘네는 analytics에 넣는 이유가 몬가요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해 보니깐 에러 발생했는데 analytics로 이벤트 트래킹 처리할 필요는 없을 것 같네요 :)

alert?.close()
}
let cancelHandler: BBAlertActionHandler = { [weak self] alert in
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickCameraButton(entry: .failedAlertCancle))
self?.toHome()
alert?.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class CameraNavigator: CameraNavigatorProtocol {
func showErrorAlert(_ type: UploadLocation) {
let confirmHandler: BBAlertActionHandler = makeConfirmHandler(for: type)
let cancelHandler: BBAlertActionHandler = { [weak self] alert in
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickCameraButton(entry: .failedAlertCancle))
self?.toHome()
alert?.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
profileButton.rx.tap
.throttle(RxConst.milliseconds300Interval, scheduler: MainScheduler.instance)
.withUnretained(self)
.do { _ in BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .profileNickNameEdit))}
.bind(onNext: { $0.0.createAlertController(owner: $0.0) })
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public final class MonthlyCalendarViewController: BBNavigationViewController<Mon
.disposed(by: disposeBag)
}

public override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .calendar))
}

public override func setupUI() {
super.setupUI()
view.addSubviews(collectionView)
Expand Down Expand Up @@ -90,6 +95,7 @@ public final class MonthlyCalendarViewController: BBNavigationViewController<Mon

collectionView.layoutIfNeeded()
collectionView.scroll(to: IndexPath(item: reactor!.currentState.pageDatasource.first!.items.count - 1, section: 0)) // 다시 리팩토링하기
BBLogManager.sendError(message: "Monthly CalendarView Index out of bounds")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay

public override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .cameraDetail))
}

//MARK: Configure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public final class CameraViewController: BaseViewController<CameraViewReactor> {

public override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .camera))
setupCameraPermission()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ final class JoinFamilyViewController: BaseViewController<JoinFamilyReactor> {

private func bindInput(reactor: JoinFamilyReactor) {
makeFamilyButton.rx.tap
.do(onNext: { MPEvent.Account.creatGroup.track(with: nil) })
.do(onNext: {
MPEvent.Account.creatGroup.track(with: nil)
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickFamilyButton(entry: .createFamilyGroup))
})
.throttle(RxConst.milliseconds300Interval, scheduler: MainScheduler.instance)
.withUnretained(self)
.bind(onNext: { $0.0.newGroupAlertController()})
.disposed(by: disposeBag)

joinFamilyButton.rx.tap
.do { _ in BBLogManager.analytics(logType: BBEventAnalyticsLog.clickFamilyButton(entry: .inviteFamily)) }
.map { Reactor.Action.joinFamily }
.bind(to: reactor.action)
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class MainViewController: BBNavigationViewController<MainViewReactor>, UIC

override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .main))
}

override func bind(reactor: MainViewReactor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ final class FamilyNameSettingViewController: BBNavigationViewController<FamilyNa
private let groupEditerView: JoinFamilyGroupEdtiorView = JoinFamilyGroupEdtiorView()


override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .familyGroupNameSetting))
}

//MARK: Configures
override func setupUI() {
super.setupUI()
Expand Down Expand Up @@ -147,6 +152,7 @@ final class FamilyNameSettingViewController: BBNavigationViewController<FamilyNa

groupConfirmButton.rx
.tap
.do { _ in BBLogManager.analytics(logType: BBEventAnalyticsLog.clickFamilyButton(entry: .familyNameSetting))}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘네들 viewcontroller에서 do로 받아서 처리하는 것보다 뷰모델에 넣는게 낫지 않을까여?🫨

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅇㅎ 화긴염 💯

.throttle(RxInterval._100milliseconds, scheduler: RxScheduler.main)
.map { Reactor.Action.didTapUpdateFamilyGroupNickname(.update) }
.bind(to: reactor.action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public final class ManagementViewController: BBNavigationViewController<Manageme
prepareDatasource()
}()

public override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .familyManagement))
}


// MARK: - Helpers

public override func bind(reactor: ManagementReactor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class PostViewController: BaseViewController<PostReactor> {

override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .postDetail))
self.navigationController?.navigationBar.isHidden = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class PrivacyViewController: BaseViewController<PrivacyViewReactor>
//MARK: Configure
public override func setupUI() {
super.setupUI()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .setting))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거는 왜 뷰디드로드에 안넣구...?!여기에 잇져?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오우 쉿 테스트 용으로 한거 안지웠나봐용

view.addSubviews(inquiryBannerView, privacyTableView, privacyIndicatorView)
}

Expand Down Expand Up @@ -222,6 +223,7 @@ extension PrivacyViewController {

let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self]_ in
guard let self else { return }
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .logout))
self.reactor?.action.onNext(.didTapLogoutButton)
}

Expand All @@ -242,6 +244,7 @@ extension PrivacyViewController {
let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self ]_ in
guard let self else { return }
self.reactor?.action.onNext(.didTapFamilyUserResign)
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .familyResign))
}

[cancelAction, confirmAction].forEach(resignAlertController.addAction(_:))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ extension ProfileFeedPageViewController: ReactorKit.View {
extension ProfileFeedPageViewController: UIPageViewControllerDelegate, UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let index = feedViewControllers.firstIndex(of: viewController),
index - 1 >= 0 else { return nil }
index - 1 >= 0 else {
BBLogManager.sendError(error: BBCrashError.indexOutBounds)
return nil
}
return feedViewControllers[index - 1]
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let index = feedViewControllers.firstIndex(of: viewController),
index + 1 != feedViewControllers.count else { return nil }
index + 1 != feedViewControllers.count else {
BBLogManager.sendError(error: BBCrashError.indexOutBounds)
return nil
}

return feedViewControllers[index + 1]
}
Expand All @@ -99,7 +105,10 @@ extension ProfileFeedPageViewController: UIPageViewControllerDelegate, UIPageVie
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {

guard let currentViewController = pageViewController.viewControllers?.first,
let currentIndex = feedViewControllers.firstIndex(of: currentViewController) else { return }
let currentIndex = feedViewControllers.firstIndex(of: currentViewController) else {
BBLogManager.sendError(error: BBCrashError.indexOutBounds)
return
}
reactor?.action.onNext(.updatePageViewController(currentIndex))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class ProfileViewController: BaseViewController<ProfileViewReactor>

public override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .profile))
}

public override func setupUI() {
Expand Down Expand Up @@ -131,6 +132,7 @@ public final class ProfileViewController: BaseViewController<ProfileViewReactor>

profileView.circleButton
.rx.tap
.do { _ in BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .profileImageEdit))}
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.withUnretained(self)
.bind(onNext: {$0.0.createAlertController()})
Expand Down Expand Up @@ -173,6 +175,7 @@ public final class ProfileViewController: BaseViewController<ProfileViewReactor>
.rx.tap
.withLatestFrom(reactor.state.compactMap { $0.profileMemberEntity?.memberId })
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.do { _ in BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .profileNickNameEdit))}
.map { Reactor.Action.didTappedProfileEditButton($0)}
.bind(to: reactor.action)
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class AccountResignViewController: BaseViewController<AccountResignViewRea

override func viewDidLoad() {
super.viewDidLoad()
BBLogManager.analytics(logType: BBEventAnalyticsLog.viewPage(pageName: .resign))
}

override func setupUI() {
Expand Down Expand Up @@ -175,6 +176,7 @@ extension AccountResignViewController {

let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in
guard let self else { return }
BBLogManager.analytics(logType: BBEventAnalyticsLog.clickAccountButton(entry: .resign))
self.reactor?.action.onNext(.didTapResignButton)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,28 @@ extension BBUploadError: LocalizedError {
}
}
}


/// Firebase Crashlytics에 사용하는 Error Type입니다.
public enum BBCrashError: Error {
/// 범위에 벗어나는 모든 경우에 발생하는 에러를 의미합니다.
case indexOutBounds
/// 강제 언래핑 실패할 경우에 발생하는 에러를 의미합니다.
case forceUnwrapFailed
/// 알 수 없는 에러일 경우 해당 에러를 사용합니다.
case unknown
}


extension BBCrashError: LocalizedError {
public var errorDescription: String? {
switch self {
case .indexOutBounds:
return "Index Out of Bounds Error"
case .forceUnwrapFailed:
return "Unexpectedly found nil while unwrapping an Optional value"
case .unknown:
return "Unknown Error"
}
}
}
36 changes: 36 additions & 0 deletions 14th-team5-iOS/Core/Sources/Extensions/String+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ extension String {
}

extension String {
public func toSnakeCase() -> String {
var result = ""
var previousStringWasCapitalized = false
var previousStringWasNumber = false

for (index, string) in self.enumerated() {
var mutableString = String(string)

if !mutableString.isAlphabet {
if index != 0,
!previousStringWasNumber {
mutableString = "_" + mutableString
}
previousStringWasNumber = true
} else if mutableString == mutableString.uppercased() {
mutableString = mutableString.lowercased()

if index != 0,
!previousStringWasCapitalized {
mutableString = "_" + mutableString
}
previousStringWasCapitalized = true
} else {
previousStringWasCapitalized = false
previousStringWasNumber = false
}
result += mutableString
}
return result
}

public var isAlphabet: Bool {
let alphabetSet = CharacterSet.uppercaseLetters.union(.lowercaseLetters).union(.whitespacesAndNewlines)
return self.rangeOfCharacter(from: alphabetSet.inverted) == nil
}

public func toDate(with format: String = "yyyy-MM-dd") -> Date {
let dateFormatter = DateFormatter.withFormat(format)
guard let date = dateFormatter.date(from: self) else { return .now }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BBAnalyticsLogParametable.swift
// Core
//
// Created by 김도현 on 12/19/24.
//

import Foundation

public protocol BBAnalyticsLogParametable: RawRepresentable, CustomStringConvertible where RawValue == String { }

public extension BBAnalyticsLogParametable {
var description: String {
self.rawValue
}
}
38 changes: 38 additions & 0 deletions 14th-team5-iOS/Core/Sources/Utils/Logger/BBAnalyticsLogType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// BBAnalyticsLogType.swift
// Core
//
// Created by 김도현 on 12/19/24.
//

import Foundation

public protocol BBAnalyticsLogType {
var name: String { get }
var params: [String: Any] { get }
}

public extension BBAnalyticsLogType {
var name: String {
Mirror(reflecting: self)
.children
.first?
.label?
.toSnakeCase() ?? String(describing: self).toSnakeCase()
}

var params: [String: Any] {
var dict: [String: Any] = [:]

let enumMirror = Mirror(reflecting: self)

guard let associated = enumMirror.children.first else { return dict }

for enumParams in Mirror(reflecting: associated.value).children {
guard let label = enumParams.label?.toSnakeCase() else { continue }
dict[label] = enumParams.value
}

return dict
}
}
Loading