Skip to content

Commit

Permalink
chore: log push notification status (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir authored and rnr committed Jan 16, 2025
1 parent 315433f commit b1aacf0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Core/Core/Analytics/CoreAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public enum AnalyticsEvent: String {
case discussionFollowToggle = "Dicussion:Post Follow Toggle"
case discussionLikeToggle = "Discussion:Like Toggle"
case discussionReportToggle = "Discussion:Report Toggle"
case notificationSettingPermissionStatus = "Notification:Setting Permission Status"
}

public enum EventBIValue: String {
Expand Down Expand Up @@ -253,6 +254,7 @@ public enum EventBIValue: String {
case discussionFollowToggle = "edx.bi.app.discussion.follow_toggle"
case discussionLikeToggle = "edx.bi.app.discussion.like_toggle"
case discussionReportToggle = "edx.bi.app.discussion.report_toggle"
case notificationSettingPermissionStatus = "edx.bi.app.notification.setting_permission.status"
}

public struct EventParamKey {
Expand Down Expand Up @@ -308,6 +310,7 @@ public struct EventParamKey {
public static let like = "like"
public static let report = "report"
public static let discussionType = "discussion_type"
public static let status = "status"
}

public struct EventCategory {
Expand Down
10 changes: 10 additions & 0 deletions OpenEdX/Managers/AnalyticsManager/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ class AnalyticsManager: AuthorizationAnalytics,
trackScreenEvent(.mainDashboardProgramsClicked, biValue: .mainDashboardProgramsClicked)
}

public func notificationPermissionStatus(status: String) {
trackEvent(
.notificationSettingPermissionStatus,
biValue: .notificationSettingPermissionStatus,
parameters: [
EventParamKey.status: status
]
)
}

// MARK: Discovery

public func discoverySearchBarClicked() {
Expand Down
2 changes: 2 additions & 0 deletions OpenEdX/Managers/AnalyticsManager/MainScreenAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public protocol MainScreenAnalytics {
func mainProgramsTabClicked()
func mainCoursesClicked()
func mainProgramsClicked()
func notificationPermissionStatus(status: String)
}

#if DEBUG
Expand All @@ -25,5 +26,6 @@ public class MainScreenAnalyticsMock: MainScreenAnalytics {
public func mainProgramsTabClicked() {}
public func mainProgramsClicked() {}
public func mainCoursesClicked() {}
public func notificationPermissionStatus(status: String) {}
}
#endif
14 changes: 14 additions & 0 deletions OpenEdX/View/MainScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Course
import Swinject
import Combine
import Authorization
import UserNotifications

public enum MainTab {
case discovery
Expand Down Expand Up @@ -69,6 +70,19 @@ final class MainScreenViewModel: ObservableObject {
}
}
.store(in: &cancellables)
trackSettingPermissionStatus()
}

private func trackSettingPermissionStatus() {
UNUserNotificationCenter.current().getNotificationSettings(completionHandler: { [weak self] (settings) in
if settings.authorizationStatus == .notDetermined {
self?.analytics.notificationPermissionStatus(status: "not_determined")
} else if settings.authorizationStatus == .denied {
self?.analytics.notificationPermissionStatus(status: "denied")
} else if settings.authorizationStatus == .authorized {
self?.analytics.notificationPermissionStatus(status: "authorized")
}
})
}

public func select(tab: MainTab) {
Expand Down

0 comments on commit b1aacf0

Please sign in to comment.