diff --git a/WordPress/Classes/System/WordPressAppDelegate.swift b/WordPress/Classes/System/WordPressAppDelegate.swift index a1923cc5a3cd..c61340bc3811 100644 --- a/WordPress/Classes/System/WordPressAppDelegate.swift +++ b/WordPress/Classes/System/WordPressAppDelegate.swift @@ -385,9 +385,11 @@ extension WordPressAppDelegate { func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { DDLogInfo("\(self) \(#function)") - - PushNotificationsManager.shared.handleNotification(userInfo as NSDictionary, - completionHandler: completionHandler) + PushNotificationsManager.shared.application( + application, + didReceiveRemoteNotification: userInfo, + fetchCompletionHandler: completionHandler + ) } } diff --git a/WordPress/Classes/Utility/InteractiveNotificationsManager.swift b/WordPress/Classes/Utility/InteractiveNotificationsManager.swift index 62e3a0095870..815cf15041fd 100644 --- a/WordPress/Classes/Utility/InteractiveNotificationsManager.swift +++ b/WordPress/Classes/Utility/InteractiveNotificationsManager.swift @@ -640,7 +640,7 @@ extension InteractiveNotificationsManager: UNUserNotificationCenterDelegate { let textInputResponse = response as? UNTextInputNotificationResponse // Analytics - PushNotificationsManager.shared.trackNotification(with: userInfo) + PushNotificationsManager.shared.trackNotification(with: userInfo, response: response) if handleAction(with: response.actionIdentifier, category: response.notification.request.content.categoryIdentifier, diff --git a/WordPress/Classes/Utility/PushNotificationsManager.swift b/WordPress/Classes/Utility/PushNotificationsManager.swift index ba582adc3e19..71319bed19ba 100644 --- a/WordPress/Classes/Utility/PushNotificationsManager.swift +++ b/WordPress/Classes/Utility/PushNotificationsManager.swift @@ -186,9 +186,6 @@ final public class PushNotificationsManager: NSObject { return } - // Analytics - trackNotification(with: userInfo) - // Handling! let handlers = [handleSupportNotification, handleAuthenticationNotification, @@ -207,7 +204,18 @@ final public class PushNotificationsManager: NSObject { /// /// - Parameter userInfo: The Notification's Payload /// - func trackNotification(with userInfo: NSDictionary) { + func trackNotification(with userInfo: NSDictionary, response: UNNotificationResponse? = nil) { + let event: WPAnalyticsStat? = { + if let response { + return response.actionIdentifier == UNNotificationDefaultActionIdentifier ? .pushNotificationAlertPressed : nil + } + return .pushNotificationReceived + }() + + guard let event else { + return + } + var properties = [String: String]() if let noteId = userInfo.number(forKey: Notification.identifierKey) { @@ -222,7 +230,6 @@ final public class PushNotificationsManager: NSObject { properties[Tracking.tokenKey] = theToken } - let event: WPAnalyticsStat = (applicationState == .background) ? .pushNotificationReceived : .pushNotificationAlertPressed WPAnalytics.track(event, withProperties: properties) } @@ -391,6 +398,17 @@ extension PushNotificationsManager { } } +// MARK: - Application Delegate + +extension PushNotificationsManager: UIApplicationDelegate { + + public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + let dictionary = userInfo as NSDictionary + self.trackNotification(with: dictionary) + self.handleNotification(dictionary, completionHandler: completionHandler) + } +} + // MARK: - Nested Types // extension PushNotificationsManager { diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index cadcce50255d..5c09c9c59dbf 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -10979,7 +10979,7 @@ path = Classes; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA = { + 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( 3F20FDF3276BF21000DA3CAD /* Packages */, @@ -19403,7 +19403,7 @@ bg, sk, ); - mainGroup = 29B97314FDCFA39411CA2CEA; + mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; packageReferences = ( 3FF1442E266F3C2400138163 /* XCRemoteSwiftPackageReference "ScreenObject" */, 3FC2C33B26C4CF0A00C6D98F /* XCRemoteSwiftPackageReference "XCUITestHelpers" */, @@ -21004,11 +21004,11 @@ files = ( ); inputPaths = ( - "$SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.inputs.xcfilelist", + $SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.inputs.xcfilelist, ); name = "Copy Gutenberg JS"; outputFileListPaths = ( - "$SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.outputs.xcfilelist", + $SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.outputs.xcfilelist, ); outputPaths = ( "", @@ -21203,13 +21203,13 @@ files = ( ); inputFileListPaths = ( - "$SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.inputs.xcfilelist", + $SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.inputs.xcfilelist, ); inputPaths = ( ); name = "Copy Gutenberg JS"; outputFileListPaths = ( - "$SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.outputs.xcfilelist", + $SRCROOT/../Scripts/BuildPhases/CopyGutenbergJS.outputs.xcfilelist, ); outputPaths = ( ); @@ -29754,6 +29754,7 @@ CURRENT_PROJECT_VERSION = "${VERSION_LONG}"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = PZYM8XX95Q; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = PZYM8XX95Q; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_OPTIMIZATION_LEVEL = 0; @@ -29799,6 +29800,7 @@ PRODUCT_MODULE_NAME = WordPress; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "Jetpack iOS Development"; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Jetpack iOS Development"; SWIFT_OBJC_BRIDGING_HEADER = "Classes/System/WordPress-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift-XcodeGenerated.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";