From 16fa216b9064a01745a9555eeb1f9b61407752aa Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 10:23:18 +0530 Subject: [PATCH 1/6] Add Failure enum with XMLRPC error case. --- .../Analytics/AuthenticatorAnalyticsTracker.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift b/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift index e4cd18c39..c0398ae35 100644 --- a/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift +++ b/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift @@ -264,6 +264,12 @@ public class AuthenticatorAnalyticsTracker { case loginWithAccountPassword = "login_with_password" } + public enum Failure: String { + /// Failure to guess XMLRPC URL + /// + case loginFailedToGuessXMLRPC = "login_failed_to_guess_xmlrpc_url" + } + /// Shared Instance. /// public static var shared: AuthenticatorAnalyticsTracker = { From 0a7a92712604dba8b2371afc7e9aa3a6bca2be97 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 10:23:41 +0530 Subject: [PATCH 2/6] Add a way to track Failure enum. --- .../Analytics/AuthenticatorAnalyticsTracker.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift b/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift index c0398ae35..fc2b179dc 100644 --- a/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift +++ b/WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift @@ -360,6 +360,12 @@ public class AuthenticatorAnalyticsTracker { track(event(click: click)) } + /// Track a predefined failure enum. + /// + public func track(failure: Failure) { + track(failure: failure.rawValue) + } + /// Track a failure. /// public func track(failure: String) { From bebe59b7ca69c2a2a7645c0cd749e146b5d5f607 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 10:28:34 +0530 Subject: [PATCH 3/6] Add tracking when guessing XMLRPC fails. --- .../Site Address/SiteAddressViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift b/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift index 1400e0c7c..82f7cf2f9 100644 --- a/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift +++ b/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift @@ -493,9 +493,9 @@ private extension SiteAddressViewController { // It's not guaranteed to be included in the error object depending on the error. DDLogInfo("Error attempting to connect to site address: \(self.loginFields.siteAddress)") DDLogError(error.localizedDescription) - // TODO: - Tracks. - // WordPressAuthenticator.track(.loginFailedToGuessXMLRPC, error: error) - // WordPressAuthenticator.track(.loginFailed, error: error) + + self.tracker.track(failure: .loginFailedToGuessXMLRPC) + self.configureViewLoading(false) guard self.isSiteDiscovery == false else { From ec4db6608de6d983ea051cd6e3f6c486083e866c Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 10:41:37 +0530 Subject: [PATCH 4/6] Update changelog. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfaa68979..390e492a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ _None._ _None._ -### New Features +- New tracking event for XMLRPC related failure. by @selanthiraiyan [#701] _None._ From c169358f383aa0bcbfb383dfa03ae983d543b266 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 10:45:00 +0530 Subject: [PATCH 5/6] Bump pod spec version. --- WordPressAuthenticator.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressAuthenticator.podspec b/WordPressAuthenticator.podspec index 26975e579..6d0d206f1 100644 --- a/WordPressAuthenticator.podspec +++ b/WordPressAuthenticator.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'WordPressAuthenticator' - s.version = '4.1.1' + s.version = '4.2.0-beta.1' s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.' s.description = <<-DESC From f2ad89e43f769ac144dcb19df89bb5c78efa7c2a Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 9 Nov 2022 15:19:38 +0530 Subject: [PATCH 6/6] Track error message even if the error has been handled by the host app. --- .../SiteAddressViewController.swift | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift b/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift index 82f7cf2f9..eba2b3f89 100644 --- a/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift +++ b/WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift @@ -505,27 +505,41 @@ private extension SiteAddressViewController { let err = self.originalErrorOrError(error: error as NSError) + let errorMessage: String? = { + if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError { + return xmlrpcValidatorError.localizedDescription + } else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) || + (err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) { + // NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered. + let msg = NSLocalizedString( + "The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.", + comment: "Error message shown a URL does not point to an existing site.") + return msg + } else { + return nil + } + }() + /// Check if the host app wants to provide custom UI to handle the error. /// If it does, insert the custom UI provided by the host app and exit early if self.authenticationDelegate.shouldHandleError(err) { + + // Send the error to the host app self.authenticationDelegate.handleError(err) { customUI in self.pushCustomUI(customUI) } + // Track error message as failure + if let message = errorMessage { + self.tracker.track(failure: message) + } + + // Return as the error has been handled by the host app. return } - if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError { - self.displayError(message: xmlrpcValidatorError.localizedDescription, moveVoiceOverFocus: true) - - } else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) || - (err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) { - // NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered. - let msg = NSLocalizedString( - "The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.", - comment: "Error message shown a URL does not point to an existing site.") - self.displayError(message: msg, moveVoiceOverFocus: true) - + if let message = errorMessage { + self.displayError(message: message, moveVoiceOverFocus: true) } else { self.displayError(error as NSError, sourceTag: self.sourceTag) }