Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Analytics Names #313

Merged
merged 8 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions Sources/CardPayments/CardClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public class CardClient: NSObject {
if result.status == "PAYER_ACTION_REQUIRED",
let urlString = result.links.first(where: { $0.rel == "approve" })?.href {
guard urlString.contains("helios"), let url = URL(string: urlString) else {
self.notifyVaultFailure(with: CardError.threeDSecureURLError, completion: completion)
self.notify3dsVaultFailure(with: CardError.threeDSecureURLError, completion: completion)
return
}
analyticsService?.sendEvent("card-payments:vault-wo-purchase:challenge-required")
analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge-required")
startVaultThreeDSecureChallenge(url: url, setupTokenID: vaultRequest.setupTokenID, completion: completion)
} else {
let vaultResult = CardVaultResult(setupTokenID: result.id, status: result.status, didAttemptThreeDSecureAuthentication: false)
Expand Down Expand Up @@ -99,7 +99,7 @@ public class CardClient: NSObject {
/// if it fails, `CardResult will be `nil` and `error` will describe the failure
public func approveOrder(request: CardRequest, completion: @escaping (CardResult?, CoreSDKError?) -> Void) {
analyticsService = AnalyticsService(coreConfig: config, orderID: request.orderID)
analyticsService?.sendEvent("card-payments:3ds:started")
analyticsService?.sendEvent("card-payments:approve-order:started")
Task {
do {
let result = try await checkoutOrdersAPI.confirmPaymentSource(cardRequest: request)
Expand All @@ -109,23 +109,19 @@ public class CardClient: NSObject {
guard getQueryStringParameter(url: url, param: "flow") == "3ds",
url.contains("helios"),
let url = URL(string: url) else {
self.notifyCheckoutFailure(with: CardError.threeDSecureURLError, completion: completion)
self.notify3dsCheckoutFailure(with: CardError.threeDSecureURLError, completion: completion)
return
}

analyticsService?.sendEvent("card-payments:3ds:confirm-payment-source:challenge-required")
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-required")
startThreeDSecureChallenge(url: url, orderId: result.id, completion: completion)
} else {
analyticsService?.sendEvent("card-payments:3ds:confirm-payment-source:succeeded")

let cardResult = CardResult(orderID: result.id, status: result.status, didAttemptThreeDSecureAuthentication: false)
notifyCheckoutSuccess(for: cardResult, completion: completion)
}
} catch let error as CoreSDKError {
analyticsService?.sendEvent("card-payments:3ds:confirm-payment-source:failed")
notifyCheckoutFailure(with: error, completion: completion)
} catch {
analyticsService?.sendEvent("card-payments:3ds:confirm-payment-source:failed")
notifyCheckoutFailure(with: CardError.unknownError, completion: completion)
}
}
Expand Down Expand Up @@ -161,25 +157,25 @@ public class CardClient: NSObject {
context: self,
sessionDidDisplay: { [weak self] didDisplay in
if didDisplay {
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:succeeded")
self?.analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-presentation:succeeded")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I know we went over this in our meeting, but it seems like this event has a different format than <module>:<function>:<event>. Should we rename this to fit the schema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth-challenge-presentation-succeeded/failed?

Copy link
Collaborator Author

@KunJeongPark KunJeongPark Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speaking of which, what do you think of end events for 3ds flows being auth-challenge:succeeded/failed/canceled as opposed to auth-challenge-succeeded/failed/canceled.
That way we can grab :succeeded, :failed, :canceled as final events
Let me check our original discussion about this but I personally like idea of :succeeded and :failed :canceled reserved for final events.

I guess that does make looking for events under <module>:<function> for example, messier.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if we could stick to <module>:<function>:<event> i'd prefer it because it's clean. I prefer auth-challenge-succeeded/failed/canceled. It's verbose but it fits the schema, which makes it regex friendly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what do you think about auth-challenge-presentation-succeeded/failed for your first point?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that works well. 👍 for auth-challenge-presentation-succeeded/failed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll run it by NN also and make changes on Confluence page.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey qq: if we keep this the way it is are we good to merge?

} else {
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:failed")
self?.analyticsService?.sendEvent("card-payments:approve-order:auth-challenge-presentation:failed")
}
},
sessionDidComplete: { _, error in
if let error = error {
switch error {
case ASWebAuthenticationSessionError.canceledLogin:
self.notifyCheckoutCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
self.notify3dsCheckoutCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
return
default:
self.notifyCheckoutFailure(with: CardError.threeDSecureError(error), completion: completion)
self.notify3dsCheckoutFailure(with: CardError.threeDSecureError(error), completion: completion)
return
}
}

let cardResult = CardResult(orderID: orderId, status: nil, didAttemptThreeDSecureAuthentication: true)
self.notifyCheckoutSuccess(for: cardResult, completion: completion)
self.notify3dsCheckoutSuccess(for: cardResult, completion: completion)
}
)
}
Expand All @@ -201,41 +197,51 @@ public class CardClient: NSObject {
sessionDidDisplay: { [weak self] didDisplay in
if didDisplay {
// TODO: analytics for card vault
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:succeeded")
self?.analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge-presentation:succeeded")
} else {
self?.analyticsService?.sendEvent("card-payments:3ds:challenge-presentation:failed")
self?.analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge-presentation:failed")
}
},
sessionDidComplete: { _, error in
if let error = error {
switch error {
case ASWebAuthenticationSessionError.canceledLogin:
self.notifyVaultCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
self.notify3dsVaultCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
return
default:
self.notifyVaultFailure(with: CardError.threeDSecureError(error), completion: completion)
self.notify3dsVaultFailure(with: CardError.threeDSecureError(error), completion: completion)
return
}
}

let cardVaultResult = CardVaultResult(setupTokenID: setupTokenID, status: nil, didAttemptThreeDSecureAuthentication: true)
self.notifyVaultSuccess(for: cardVaultResult, completion: completion)
self.notify3dsVaultSuccess(for: cardVaultResult, completion: completion)
}
)
}

private func notifyCheckoutSuccess(for result: CardResult, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:3ds:succeeded")
analyticsService?.sendEvent("card-payments:approve-order:succeeded")
completion(result, nil)
}

private func notify3dsCheckoutSuccess(for result: CardResult, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge:succeeded")
completion(result, nil)
}

private func notifyCheckoutFailure(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:3ds:failed")
analyticsService?.sendEvent("card-payments:approve-order:failed")
completion(nil, error)
}

private func notify3dsCheckoutFailure(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge:failed")
completion(nil, error)
}

private func notifyCheckoutCancelWithError(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:3ds:challenge:user-canceled")
private func notify3dsCheckoutCancelWithError(with error: CoreSDKError, completion: (CardResult?, CoreSDKError?) -> Void) {
KunJeongPark marked this conversation as resolved.
Show resolved Hide resolved
analyticsService?.sendEvent("card-payments:approve-order:auth-challenge:canceled")
completion(nil, error)
}

Expand All @@ -244,13 +250,23 @@ public class CardClient: NSObject {
completion(vaultResult, nil)
}

private func notify3dsVaultSuccess(for vaultResult: CardVaultResult, completion: (CardVaultResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge:succeeded")
completion(vaultResult, nil)
}

private func notifyVaultFailure(with vaultError: CoreSDKError, completion: (CardVaultResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:vault-wo-purchase:failed")
completion(nil, vaultError)
}

private func notifyVaultCancelWithError(with vaultError: CoreSDKError, completion: (CardVaultResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:vault-wo-purchase:challenge:canceled")
private func notify3dsVaultFailure(with vaultError: CoreSDKError, completion: (CardVaultResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge:failed")
completion(nil, vaultError)
}

private func notify3dsVaultCancelWithError(with vaultError: CoreSDKError, completion: (CardVaultResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("card-payments:vault-wo-purchase:auth-challenge:canceled")
completion(nil, vaultError)
}
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class PayPalWebCheckoutClient: NSObject {
/// if it fails, `PayPalWebCheckoutResult will be `nil` and `error` will describe the failure
public func start(request: PayPalWebCheckoutRequest, completion: @escaping (PayPalWebCheckoutResult?, CoreSDKError?) -> Void) {
analyticsService = AnalyticsService(coreConfig: config, orderID: request.orderID)
analyticsService?.sendEvent("paypal-web-payments:started")
analyticsService?.sendEvent("paypal-web-payments:checkout:started")

let baseURLString = config.environment.payPalBaseURL.absoluteString
let payPalCheckoutURLString =
"\(baseURLString)/checkoutnow?token=\(request.orderID)" +
Expand All @@ -54,9 +54,9 @@ public class PayPalWebCheckoutClient: NSObject {
context: self,
sessionDidDisplay: { [weak self] didDisplay in
if didDisplay {
self?.analyticsService?.sendEvent("paypal-web-payments:browser-presentation:succeeded")
self?.analyticsService?.sendEvent("paypal-web-payments:checkout:auth-challenge-presentation:succeeded")
} else {
self?.analyticsService?.sendEvent("paypal-web-payments:browser-presentation:failed")
self?.analyticsService?.sendEvent("paypal-web-payments:checkout:auth-challenge-presentation:failed")
}
},
sessionDidComplete: { url, error in
Expand Down Expand Up @@ -143,9 +143,9 @@ public class PayPalWebCheckoutClient: NSObject {
context: self,
sessionDidDisplay: { [weak self] didDisplay in
if didDisplay {
self?.analyticsService?.sendEvent("paypal-vault:browser-presentation:succeeded")
self?.analyticsService?.sendEvent("paypal-web-payments:vault-wo-purchase:auth-challenge-presentation:succeeded")
} else {
self?.analyticsService?.sendEvent("paypal-vault:browser-presentation:failed")
self?.analyticsService?.sendEvent("paypal-web-payments:vault-wo-purchase:auth-challenge-presentation:failed")
}
},
sessionDidComplete: { url, error in
Expand Down Expand Up @@ -203,17 +203,17 @@ public class PayPalWebCheckoutClient: NSObject {
}

private func notifyCheckoutSuccess(for result: PayPalWebCheckoutResult, completion: (PayPalWebCheckoutResult?, CoreSDKError?) -> Void) {
self.analyticsService?.sendEvent("paypal-web-payments:succeeded")
self.analyticsService?.sendEvent("paypal-web-payments:checkout:succeeded")
completion(result, nil)
}

private func notifyCheckoutFailure(with error: CoreSDKError, completion: (PayPalWebCheckoutResult?, CoreSDKError?) -> Void) {
self.analyticsService?.sendEvent("paypal-web-payments:failed")
self.analyticsService?.sendEvent("paypal-web-payments:checkout:failed")
completion(nil, error)
}

private func notifyCheckoutCancelWithError(with error: CoreSDKError, completion: (PayPalWebCheckoutResult?, CoreSDKError?) -> Void) {
analyticsService?.sendEvent("paypal-web-payments:browser-login:canceled")
analyticsService?.sendEvent("paypal-web-payments:checkout:canceled")
completion(nil, error)
}

Expand Down