Skip to content

Commit 0c2bf96

Browse files
authored
Merge pull request #355 from lsj8706/feat/#354-콕찌르기-Amplitude-트래킹
[Feat] #354 - 콕 찌르기 Amplitude 이벤트 트래킹
2 parents a038731 + 23dc252 commit 0c2bf96

File tree

21 files changed

+322
-82
lines changed

21 files changed

+322
-82
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// AmplitudeEventPropertyBuilder.swift
3+
// Core
4+
//
5+
// Created by sejin on 1/21/24.
6+
// Copyright © 2024 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class AmplitudeEventPropertyBuilder<Value: AmplitudeEventPropertyValueConvertible> {
12+
private var eventProperties = [String: Any]()
13+
14+
public init() {}
15+
16+
/// ViewType 은 UserType과 같다.
17+
public func addViewType() -> Self {
18+
let key: AmplitudeEventPropertyKey = .viewType
19+
let userType = UserDefaultKeyList.Auth.getUserType()
20+
let value = userType.rawValue.lowercased()
21+
self.eventProperties[key.rawValue] = value
22+
return self
23+
}
24+
25+
public func add(key: String, value: Any) -> Self {
26+
self.eventProperties[key] = value
27+
return self
28+
}
29+
30+
public func add(key: AmplitudeEventPropertyKey, value: Any) -> Self {
31+
self.eventProperties[key.rawValue] = value
32+
return self
33+
}
34+
35+
public func add(key: AmplitudeEventPropertyKey, value: Optional<Any>) -> Self {
36+
self.eventProperties[key.rawValue] = value
37+
return self
38+
}
39+
40+
public func add(key: AmplitudeEventPropertyKey, value: Value) -> Self {
41+
self.eventProperties[key.rawValue] = value.toString()
42+
return self
43+
}
44+
45+
public func removeOptional() -> Self {
46+
self.eventProperties = self.eventProperties.compactMapValues { $0 }
47+
return self
48+
}
49+
50+
public func build() -> [String: Any] {
51+
return eventProperties
52+
}
53+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// AmplitudeEventPropertyKey.swift
3+
// Core
4+
//
5+
// Created by sejin on 1/21/24.
6+
// Copyright © 2024 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum AmplitudeEventPropertyKey: String {
12+
case viewType = "view_type"
13+
case clickViewType = "click_view_type"
14+
15+
// 콕 찌르기 피쳐 관련 Key
16+
case viewProfile = "view_profile" // 멤버 프로필 id
17+
case friendType = "friend_type"
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// AmplitudeEventPropertyValueConvertible.swift
3+
// Core
4+
//
5+
// Created by sejin on 1/21/24.
6+
// Copyright © 2024 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol AmplitudeEventPropertyValueConvertible {
12+
func toString() -> String
13+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AmplitudeEventType.swift
3+
// Core
4+
//
5+
// Created by sejin on 2023/09/21.
6+
// Copyright © 2023 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum AmplitudeEventType: String {
12+
// 클릭 이벤트
13+
case clickAlarm = "click_alarm"
14+
case clickMyPage = "click_mypage"
15+
case clickAttendacne = "click_attendance"
16+
case clickGroup = "click_group"
17+
case clickProject = "click_project"
18+
case clickMember = "click_member"
19+
case clickOfficialHomepage = "click_homepage"
20+
case clickSoptamp = "click_soptamp"
21+
case clickInstagram = "click_instagram"
22+
case clickYoutube = "click_youtube"
23+
case clickReview = "click_review"
24+
case clickFaq = "click_faq"
25+
case clickPlaygroundCommunity = "click_playground_community"
26+
case clickPoke = "click_poke"
27+
case clickMemberProfile = "click_memberprofile"
28+
case clickPokeIcon = "click_poke_icon"
29+
case clickPokeAlarmDetail = "click_poke_alarm_detail"
30+
case clickPokeQuit = "click_poke_quit"
31+
32+
// 뷰 이벤트
33+
case viewAppHome = "view_apphome"
34+
case viewPokeOnboarding = "view_poke_onboarding"
35+
case viewPokeMain = "view_poke_main"
36+
case viewPokeAlarmDetail = "view_poke_alarm_detail"
37+
case viewPokeFriend = "view_poke_friend"
38+
case viewPokeFriendDetail = "view_poke_friend_detail"
39+
}

SOPT-iOS/Projects/Core/Sources/Amplitude/AmplitudeInstance.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ public struct AmplitudeInstance {
1616
}
1717

1818
public extension Amplitude {
19-
func track(event: AmplitudeEventType, userType: UserType, otherProperties: [String: Any]? = nil) {
20-
let eventType: String = event.rawValue
21-
var eventProperties: [String: Any] = ["view_type": userType.rawValue.lowercased()]
22-
23-
if let otherProperties = otherProperties {
24-
for (key, value) in otherProperties {
25-
eventProperties.updateValue(value, forKey: key)
26-
}
27-
}
19+
func track(eventType: AmplitudeEventType, eventProperties: [String: Any]? = nil) {
20+
let eventType: String = eventType.rawValue
2821

2922
AmplitudeInstance.shared.track(eventType: eventType, eventProperties: eventProperties, options: nil)
3023
}
3124

32-
func trackWithUserType(event: AmplitudeEventType) {
25+
func trackWithUserType(event: AmplitudeEventType, otherProperties: [String: Any]? = nil) {
3326
let eventType: String = event.rawValue
3427
let userType = UserDefaultKeyList.Auth.getUserType()
35-
var eventProperties: [String: Any] = ["view_type": userType.rawValue.lowercased()]
28+
let eventProperties: [String: Any] = [AmplitudeEventPropertyKey.viewType.rawValue: userType.rawValue.lowercased()]
3629

3730
AmplitudeInstance.shared.track(eventType: eventType, eventProperties: eventProperties, options: nil)
3831
}
32+
33+
func addPushNotificationAuthorizationIdentity(isAuthorized: Bool) {
34+
let identify = Identify()
35+
let key: AmplitudeUserPropertyKey = .stateOfPushNotification
36+
identify.set(property: key.rawValue, value: isAuthorized)
37+
38+
AmplitudeInstance.shared.identify(identify: identify)
39+
}
3940
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// AmplitudeUserPropertyKey.swift
3+
// Core
4+
//
5+
// Created by sejin on 1/21/24.
6+
// Copyright © 2024 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum AmplitudeUserPropertyKey: String {
12+
case stateOfPushNotification = "state_of_push_notification"
13+
}

SOPT-iOS/Projects/Core/Sources/Enum/AmplitudeEventType.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

SOPT-iOS/Projects/Core/Sources/Enum/ServiceTypeTransform.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ import Foundation
1111
public extension ServiceType {
1212
var toAmplitudeEventType: AmplitudeEventType {
1313
switch self {
14-
case .officialHomepage: return .officialHomepage
15-
case .review: return .review
16-
case .project: return .project
17-
case .faq: return .faq
18-
case .youtube: return .youtube
19-
case .attendance: return .attendacne
20-
case .member: return .member
21-
case .group: return .group
22-
case .instagram: return .instagram
23-
case .playgroundCommunity: return .playgroundCommunity
14+
case .officialHomepage: return .clickOfficialHomepage
15+
case .review: return .clickReview
16+
case .project: return .clickProject
17+
case .faq: return .clickFaq
18+
case .youtube: return .clickYoutube
19+
case .attendance: return .clickAttendacne
20+
case .member: return .clickMember
21+
case .group: return .clickGroup
22+
case .instagram: return .clickInstagram
23+
case .playgroundCommunity: return .clickPlaygroundCommunity
2424
}
2525
}
2626
}
2727

2828
public extension AppServiceType {
2929
var toAmplitudeEventType: AmplitudeEventType {
3030
switch self {
31-
case .soptamp: return .soptamp
32-
case .poke: return .poke
31+
case .soptamp: return .clickSoptamp
32+
case .poke: return .clickPoke
3333
}
3434
}
3535
}

SOPT-iOS/Projects/Core/Sources/Utils/trackAmplitudeEvent.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

SOPT-iOS/Projects/Demo/Sources/AppLifecycleAdapter/AppLifecycleAdapter.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension AppLifecycleAdapter {
3131
.receive(on: DispatchQueue.main)
3232
.sink(receiveValue: { [weak self] _ in
3333
self?.reissureTokens()
34+
self?.checkNotificationSetting()
3435
}).store(in: self.cancelBag)
3536
}
3637

@@ -44,4 +45,11 @@ extension AppLifecycleAdapter {
4445

4546
self.authService.reissuance { _ in }
4647
}
48+
49+
private func checkNotificationSetting() {
50+
UNUserNotificationCenter.current().getNotificationSettings { setting in
51+
let isNotificationAuthorized = setting.authorizationStatus == .authorized
52+
AmplitudeInstance.shared.addPushNotificationAuthorizationIdentity(isAuthorized: isNotificationAuthorized)
53+
}
54+
}
4755
}

0 commit comments

Comments
 (0)