Skip to content

Commit

Permalink
[Feat] sopt-makers#354 - PokeMyFriendsList 뷰의 이벤트 트래킹
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Jan 21, 2024
1 parent 129660f commit 0ef13a2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ public class AmplitudeEventPropertyBuilder<Value: AmplitudeEventPropertyValueCon
return self
}

public func add(key: AmplitudeEventPropertyKey, value: Optional<Any>) -> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PokeAmplitudeEventPropertyValue>()
.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<PokeAmplitudeEventPropertyValue>()
.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<PokeAmplitudeEventPropertyValue>()
.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<PokeAmplitudeEventPropertyValue>()
.addViewType()
.add(key: .clickViewType, value: clickView)
.add(key: .viewProfile, value: playgroundId)
.removeOptional()
.build()

AmplitudeInstance.shared.track(eventType: .clickMemberProfile, eventProperties: properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0ef13a2

Please sign in to comment.