diff --git a/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventPropertyBuilder.swift b/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventPropertyBuilder.swift index 540fe549..9a89e0c4 100644 --- a/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventPropertyBuilder.swift +++ b/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventPropertyBuilder.swift @@ -32,11 +32,21 @@ public class AmplitudeEventPropertyBuilder) -> Self { + self.eventProperties[key.rawValue] = value + return self + } + public func add(key: AmplitudeEventPropertyKey, value: Value) -> Self { self.eventProperties[key.rawValue] = value.toString() return self } + public func removeOptional() -> Self { + self.eventProperties = self.eventProperties.compactMapValues { $0 } + return self + } + public func build() -> [String: Any] { return eventProperties } diff --git a/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventType.swift b/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventType.swift index 34a9752f..d2ce7b5b 100644 --- a/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventType.swift +++ b/SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeEventType.swift @@ -35,4 +35,5 @@ public enum AmplitudeEventType: String { case viewPokeMain = "view_poke_main" case viewPokeAlarmDetail = "view_poke_alarm_detail" case viewPokeFriend = "view_poke_friend" + case viewPokeFriendDetail = "view_poke_friend_detail" } diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Interface/Sources/Enum/PokeRelation.swift b/SOPT-iOS/Projects/Features/PokeFeature/Interface/Sources/Enum/PokeRelation.swift index 6690a753..c202e649 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Interface/Sources/Enum/PokeRelation.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Interface/Sources/Enum/PokeRelation.swift @@ -15,4 +15,17 @@ public enum PokeRelation: String { case soulmate = "천생연분" } - +extension PokeRelation { + public var toEnglishName: String { + switch self { + case .nonFriend: + return "nonFriend" + case .newFriend: + return "newFriend" + case .bestFriend: + return "bestFriend" + case .soulmate: + return "soulmate" + } + } +} diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Amplitude/PokeEventTracker.swift b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Amplitude/PokeEventTracker.swift index ac966bac..0557f6a2 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Amplitude/PokeEventTracker.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Amplitude/PokeEventTracker.swift @@ -8,45 +8,39 @@ import Foundation import Core +import PokeFeatureInterface struct PokeEventTracker { func trackViewEvent(with viewEvent: AmplitudeEventType) { AmplitudeInstance.shared.trackWithUserType(event: viewEvent) } - func trackClickPokeEvent(clickView: PokeAmplitudeEventPropertyValue) { + func trackViewFriendsListEvent(friendType: PokeRelation) { let properties = AmplitudeEventPropertyBuilder() .addViewType() - .add(key: .clickViewType, value: clickView) + .add(key: .friendType, value: friendType.toEnglishName) .build() - AmplitudeInstance.shared.track(eventType: .clickPokeIcon, eventProperties: properties) + AmplitudeInstance.shared.track(eventType: .viewPokeFriendDetail, eventProperties: properties) } - - func trackClickPokeEvent(clickView: PokeAmplitudeEventPropertyValue, playgroundId: Int) { + + func trackClickPokeEvent(clickView: PokeAmplitudeEventPropertyValue, playgroundId: Int? = nil) { let properties = AmplitudeEventPropertyBuilder() .addViewType() .add(key: .clickViewType, value: clickView) .add(key: .viewProfile, value: playgroundId) + .removeOptional() .build() AmplitudeInstance.shared.track(eventType: .clickPokeIcon, eventProperties: properties) } - - func trackClickMemberProfileEvent(clickView: PokeAmplitudeEventPropertyValue) { - let properties = AmplitudeEventPropertyBuilder() - .addViewType() - .add(key: .clickViewType, value: clickView) - .build() - - AmplitudeInstance.shared.track(eventType: .clickMemberProfile, eventProperties: properties) - } - - func trackClickMemberProfileEvent(clickView: PokeAmplitudeEventPropertyValue, playgroundId: Int) { + + func trackClickMemberProfileEvent(clickView: PokeAmplitudeEventPropertyValue, playgroundId: Int? = nil) { let properties = AmplitudeEventPropertyBuilder() .addViewType() .add(key: .clickViewType, value: clickView) .add(key: .viewProfile, value: playgroundId) + .removeOptional() .build() AmplitudeInstance.shared.track(eventType: .clickMemberProfile, eventProperties: properties) diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMyFriendsListScene/ViewModel/PokeMyFriendsListViewModel.swift b/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMyFriendsListScene/ViewModel/PokeMyFriendsListViewModel.swift index 81a6afd1..af1a855e 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMyFriendsListScene/ViewModel/PokeMyFriendsListViewModel.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMyFriendsListScene/ViewModel/PokeMyFriendsListViewModel.swift @@ -26,6 +26,7 @@ public class PokeMyFriendsListViewModel: private let useCase: PokeMyFriendsUseCase private var cancelBag = CancelBag() + private let eventTracker = PokeEventTracker() public let relation: PokeRelation var friends = [PokeUserModel]() @@ -64,6 +65,12 @@ extension PokeMyFriendsListViewModel { let output = Output() self.bindOutput(output: output, cancelBag: cancelBag) + input.viewDidLoad + .sink { [weak self] _ in + guard let self = self else { return } + self.eventTracker.trackViewFriendsListEvent(friendType: self.relation) + }.store(in: cancelBag) + input.viewDidLoad .merge(with: input.reachToBottom) .withUnretained(self)