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 committed Dec 5, 2024
1 parent 0758741 commit 995de7a
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 @@ -331,6 +331,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"

}

Expand Down Expand Up @@ -443,6 +444,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 @@ -501,6 +503,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 @@ -210,6 +210,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 @@ -10,6 +10,7 @@ import Core
import Profile
import Combine
import Authorization
import UserNotifications

final class MainScreenViewModel: ObservableObject {

Expand All @@ -35,6 +36,19 @@ final class MainScreenViewModel: ObservableObject {
self.profileInteractor = profileInteractor
self.sourceScreen = sourceScreen
addObservers()
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")
}
})
}

private func addObservers() {
Expand Down

0 comments on commit 995de7a

Please sign in to comment.