Skip to content

Commit 89e8d77

Browse files
authored
Merge pull request #5909 from woocommerce/fix/5330-in-app-review-notification
Fix in-app review notification and track viewing in-app notifications
2 parents 6e1b975 + aa13c34 commit 89e8d77

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public enum WooAnalyticsStat: String {
288288
case pushNotificationOSAlertAllowed = "push_notification_os_alert_allowed"
289289
case pushNotificationOSAlertDenied = "push_notification_os_alert_denied"
290290
case pushNotificationOSAlertShown = "push_notification_os_alert_shown"
291+
case viewInAppPushNotificationPressed = "view_in_app_push_notification_pressed"
291292

292293
// MARK: Notification View Events
293294
//

WooCommerce/Classes/Notifications/PushNotificationsManager.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class PushNotificationsManager: PushNotesManager {
2929
/// in the foreground.
3030
///
3131
var foregroundNotificationsToView: AnyPublisher<PushNotification, Never> {
32-
foregroundNotificationsSubject.eraseToAnyPublisher()
32+
foregroundNotificationsToViewSubject.eraseToAnyPublisher()
3333
}
3434

3535
/// Mutable reference to `foregroundNotificationsToView`.
@@ -371,6 +371,7 @@ private extension PushNotificationsManager {
371371
guard let self = self else { return }
372372
self.presentDetails(for: foregroundNotification)
373373
self.foregroundNotificationsToViewSubject.send(foregroundNotification)
374+
ServiceLocator.analytics.track(.viewInAppPushNotificationPressed, withProperties: [AnalyticKey.type: foregroundNotification.kind.rawValue])
374375
}
375376

376377
foregroundNotificationsSubject.send(foregroundNotification)
@@ -523,8 +524,13 @@ private extension PushNotificationsManager {
523524
properties[AnalyticKey.fromSelectedSite] = siteID == notificationSiteID
524525
}
525526

526-
let event: WooAnalyticsStat = (applicationState == .background) ? .pushNotificationReceived : .pushNotificationAlertPressed
527-
ServiceLocator.analytics.track(event, withProperties: properties)
527+
switch applicationState {
528+
case .inactive:
529+
ServiceLocator.analytics.track(.pushNotificationAlertPressed, withProperties: properties)
530+
default:
531+
properties[AnalyticKey.appState] = applicationState.rawValue
532+
ServiceLocator.analytics.track(.pushNotificationReceived, withProperties: properties)
533+
}
528534
}
529535
}
530536

@@ -604,6 +610,7 @@ private enum AnalyticKey {
604610
static let type = "push_notification_type"
605611
static let token = "push_notification_token"
606612
static let fromSelectedSite = "is_from_selected_site"
613+
static let appState = "app_state"
607614
}
608615

609616
private enum PushType {

0 commit comments

Comments
 (0)