Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit fb0f2c0

Browse files
Merge pull request #701 from wordpress-mobile/wcios/trackXmlrpcError
New tracking event for XMLRPC error
2 parents 964b007 + f2ad89e commit fb0f2c0

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ _None._
3636

3737
_None._
3838

39-
### New Features
39+
- New tracking event for XMLRPC related failure. by @selanthiraiyan [#701]
4040

4141
_None._
4242

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressAuthenticator'
5-
s.version = '4.1.1'
5+
s.version = '4.2.0-beta.1'
66

77
s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
88
s.description = <<-DESC

WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ public class AuthenticatorAnalyticsTracker {
264264
case loginWithAccountPassword = "login_with_password"
265265
}
266266

267+
public enum Failure: String {
268+
/// Failure to guess XMLRPC URL
269+
///
270+
case loginFailedToGuessXMLRPC = "login_failed_to_guess_xmlrpc_url"
271+
}
272+
267273
/// Shared Instance.
268274
///
269275
public static var shared: AuthenticatorAnalyticsTracker = {
@@ -354,6 +360,12 @@ public class AuthenticatorAnalyticsTracker {
354360
track(event(click: click))
355361
}
356362

363+
/// Track a predefined failure enum.
364+
///
365+
public func track(failure: Failure) {
366+
track(failure: failure.rawValue)
367+
}
368+
357369
/// Track a failure.
358370
///
359371
public func track(failure: String) {

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ private extension SiteAddressViewController {
493493
// It's not guaranteed to be included in the error object depending on the error.
494494
DDLogInfo("Error attempting to connect to site address: \(self.loginFields.siteAddress)")
495495
DDLogError(error.localizedDescription)
496-
// TODO: - Tracks.
497-
// WordPressAuthenticator.track(.loginFailedToGuessXMLRPC, error: error)
498-
// WordPressAuthenticator.track(.loginFailed, error: error)
496+
497+
self.tracker.track(failure: .loginFailedToGuessXMLRPC)
498+
499499
self.configureViewLoading(false)
500500

501501
guard self.isSiteDiscovery == false else {
@@ -505,27 +505,41 @@ private extension SiteAddressViewController {
505505

506506
let err = self.originalErrorOrError(error: error as NSError)
507507

508+
let errorMessage: String? = {
509+
if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
510+
return xmlrpcValidatorError.localizedDescription
511+
} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
512+
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
513+
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
514+
let msg = NSLocalizedString(
515+
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
516+
comment: "Error message shown a URL does not point to an existing site.")
517+
return msg
518+
} else {
519+
return nil
520+
}
521+
}()
522+
508523
/// Check if the host app wants to provide custom UI to handle the error.
509524
/// If it does, insert the custom UI provided by the host app and exit early
510525
if self.authenticationDelegate.shouldHandleError(err) {
526+
527+
// Send the error to the host app
511528
self.authenticationDelegate.handleError(err) { customUI in
512529
self.pushCustomUI(customUI)
513530
}
514531

532+
// Track error message as failure
533+
if let message = errorMessage {
534+
self.tracker.track(failure: message)
535+
}
536+
537+
// Return as the error has been handled by the host app.
515538
return
516539
}
517540

518-
if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
519-
self.displayError(message: xmlrpcValidatorError.localizedDescription, moveVoiceOverFocus: true)
520-
521-
} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
522-
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
523-
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
524-
let msg = NSLocalizedString(
525-
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
526-
comment: "Error message shown a URL does not point to an existing site.")
527-
self.displayError(message: msg, moveVoiceOverFocus: true)
528-
541+
if let message = errorMessage {
542+
self.displayError(message: message, moveVoiceOverFocus: true)
529543
} else {
530544
self.displayError(error as NSError, sourceTag: self.sourceTag)
531545
}

0 commit comments

Comments
 (0)