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

[Diagnostics] Add apple_purchase_attempt event #4253

Merged
merged 9 commits into from
Sep 25, 2024
Merged

[Diagnostics] Add apple_purchase_attempt event #4253

merged 9 commits into from
Sep 25, 2024

Conversation

vegaro
Copy link
Contributor

@vegaro vegaro commented Sep 9, 2024

Create a new applePurchaseAttempt

Still as draft as it is missing tests and backend

@vegaro vegaro added the pr:feat A new feature label Sep 9, 2024
@vegaro vegaro changed the title [Diagnostics] Add apple_products_attempt event [Diagnostics] Add apple_purchase_attempt event Sep 11, 2024
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

Looks great!

if #available(iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5, visionOS 1.0, *) {
return "not_entitled"
} else {
return "unknown"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm is it possible to get here? Seems weird to branch by version here...

.storeKitVersion: AnyEncodable("store_kit_\(storeKitVersion.debugDescription)"),
.errorMessageKey: AnyEncodable(errorMessage),
.errorCodeKey: AnyEncodable(errorCode),
.skErrorDescriptionKey: AnyEncodable(storeKitErrorDescription)
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ I think this could be useful! We probably should add it to the event I added in #4253 if we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! I think it will be super useful. I thought about using an int code, but SK2 errors don't have an int representation. So I decided to go with the name of the event. It will make it easier to analyse as well.

@vegaro vegaro marked this pull request as ready for review September 18, 2024 10:44
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

LGTM!

case .overlayPresentedInBackgroundScene:
return "overlay_presented_in_background_scene"
@unknown default:
return "unknown_future_error"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe unknown_store_kit_error?

return "unknown"
}
@unknown default:
return "unknown_future_error"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

storeKitErrorDescription = storeKitError.trackingDescription
} else {
storeKitErrorDescription = nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like this to be a function we can use from other places, but not really sure where to move it to? It would be an extension on Dictionary, which feels weird? Maybe we can just leave it here. cc: @tonidero

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm maybe some kind of StoreKitErrorHelper class to abstract this logic? I think it would be ok even if this is a static method... Wdyt?

I think this will very likely be used in other diagnostics events, so it would be ideal to avoid duplication.

@vegaro
Copy link
Contributor Author

vegaro commented Sep 20, 2024

@RCGitBot please test

1 similar comment
@vegaro
Copy link
Contributor Author

vegaro commented Sep 23, 2024

@RCGitBot please test

@@ -413,8 +421,11 @@ final class PurchasesOrchestrator {

let addPayment: Bool = self.addPurchaseCompletedCallback(
productIdentifier: productIdentifier,
completion: { transaction, customerInfo, error, cancelled in
completion: { [weak self] transaction, customerInfo, error, cancelled in
guard let self = self else { return }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without this, we were leaking PurchasesOrchestator and DeviceCache

cc: @tonidero

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm interesting... I'm not sure I understand the reason... I think this should be mostly safe, except maybe we're not ensuring the completion blocks to be called if changing the purchases orchestrator instance for any reason... Which should normally be ok I think.

In any case, would it be possible to do this inside the trackPurchaseEventIfNeeded if that was the reason for the leak to avoid changing any other code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well the reason is that the completion block holds a reference to self, and we are adding the completion block to the purchaseCompletedCallbacks, which I think are not getting triggered when testing, so even if I add it to trackPurchaseEventIfNeeded, we still need to call self. trackPurchaseEventIfNeeded, and the completion would still be holding the reference to self. Am I misunderstanding something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh ok right. Make sense. Thanks for the explanation!

@vegaro
Copy link
Contributor Author

vegaro commented Sep 23, 2024

@RCGitBot please test

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -413,8 +421,11 @@ final class PurchasesOrchestrator {

let addPayment: Bool = self.addPurchaseCompletedCallback(
productIdentifier: productIdentifier,
completion: { transaction, customerInfo, error, cancelled in
completion: { [weak self] transaction, customerInfo, error, cancelled in
guard let self = self else { return }
Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh ok right. Make sense. Thanks for the explanation!

@vegaro vegaro enabled auto-merge (squash) September 25, 2024 14:04
@vegaro vegaro merged commit 93e3f3f into main Sep 25, 2024
5 checks passed
@vegaro vegaro deleted the track-purchases branch September 25, 2024 14:41
This was referenced Sep 25, 2024
nyeu pushed a commit that referenced this pull request Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants