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] #408 - Amplitude 설치 #462

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import Foundation

public enum AmplitudeEventType: String {
// 푸시 이벤트
case receivedPush = "received_push"
case clickPush = "click_push"
// 클릭 이벤트
case clickAlarm = "click_alarm"
case clickMyPage = "click_mypage"
Expand All @@ -24,6 +27,9 @@ public enum AmplitudeEventType: String {
case clickFaq = "click_faq"
case clickPlaygroundCommunity = "click_playground_community"
case clickHotboard = "click_hotboard"
case clickShortcutButton = "click_link.btn"
case clickReadAllButton = "click_allread.btn"
case clickNotificationItem = "click_notification_item"

// 콕 찌르기 클릭 이벤트
case clickPoke = "click_poke"
Expand All @@ -47,6 +53,8 @@ public enum AmplitudeEventType: String {
// 뷰 이벤트
case viewAppHome = "view_apphome"
case viewPokeOnboarding = "view_poke_onboarding"
case viewNotificationDetail = "view_notification_detail"
case viewNotificationList = "view_notification_list"

// 콕 찌르기 뷰 이벤트
case viewPokeMain = "view_poke_main"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ final class NotificationCoordinator: DefaultNotificationCoordinator {
let url = link.url

let destination: NotificationCoordinatorDestination = link.isDeepLink ? .deepLink(url: url) : .webLink(url: url)
AmplitudeInstance.shared.track(eventType: .viewNotificationDetail, eventProperties: [
"notification_id": notificationId,
"open_method": link.isDeepLink ? "푸시알림" : "알림센터",
"contain_deeplink": link.isDeepLink
])

self?.requestCoordinating?(destination)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extension NotificationDetailViewModel {
.sink { owner, _ in
guard let shortCutLink = owner.makeShortCutLink() else { return }
owner.onShortCutButtonTap?(shortCutLink)
owner.trackAmplitudeShortcutButtonTapped(with: owner.notificationId)
}.store(in: cancelBag)

return output
Expand Down Expand Up @@ -119,4 +120,8 @@ extension NotificationDetailViewModel {
let calendar = Calendar.current
return calendar.isDateInToday(date)
}

private func trackAmplitudeShortcutButtonTapped(with notificationId: String) {
AmplitudeInstance.shared.track(eventType: .clickShortcutButton, eventProperties: ["notification_id": notificationId])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extension NotificationListViewModel {
.withUnretained(self)
.sink { owner, _ in
output.filterList.send(owner.filterList)
AmplitudeInstance.shared.track(eventType: .viewNotificationList)
}.store(in: cancelBag)

input.requestNotifications
Expand All @@ -91,13 +92,22 @@ extension NotificationListViewModel {
owner.onNotificationTap?(notification.notificationId)
owner.read(index: index)
output.notificationList.send(self.notifications)
AmplitudeInstance.shared.track(eventType: .clickNotificationItem,
eventProperties: [
"notification_id": notification.notificationId,
"send_timestamp": notification.createdAt,
"contents": notification.content ?? "",
"admin_category": notification.category ?? "",
"title": notification.title
])
}.store(in: cancelBag)

input.readAllButtonTapped
.throttle(for: 1, scheduler: DispatchQueue.main, latest: true)
.withUnretained(self)
.sink { owner, _ in
owner.useCase.readAllNotifications()
AmplitudeInstance.shared.track(eventType: .clickReadAllButton)
}.store(in: cancelBag)

input.categoryCellTapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,25 @@ public final class NotificationHandler: NSObject, UNUserNotificationCenterDelega
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
let userInfo = notification.request.content.userInfo
print("APNs 푸시 알림 페이로드: \(userInfo)")
AmplitudeInstance.shared.track(eventType: .receivedPush, eventProperties: ["notificationId": payload.id,
"send_timeStamp": payload.sendAt,
"title": payload.title,
"contents": payload.content,
"admin_category": payload.category ?? "없음"])
return([.badge, .banner, .list, .sound])
}

@MainActor
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
let userInfo = response.notification.request.content.userInfo
print("APNs 푸시 알림 페이로드: \(userInfo)")

guard let payload = NotificationPayload(dictionary: userInfo) else { return }

AmplitudeInstance.shared.track(eventType: .clickPush, eventProperties: ["notificationId": payload.id,
"send_timeStamp": payload.sendAt,
"leadtime": "",
"contain_deeplink": payload.hasDeepLink,
"deeplink_url": payload.deepLink ?? "없음"])
guard payload.hasLink else {
self.deepLink.send(makeComponentsForEmptyLink(notificationId: payload.id))
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import Sentry
public struct NotificationPayload: Codable {
public let aps: APS
public let id: String
public let title: String
public let content: String
public let sendAt: String
public let category: String?
public let deepLink: String?
public let webLink: String?
Expand Down