Skip to content

Commit

Permalink
Dedup Optimization
Browse files Browse the repository at this point in the history
Summary: In the original dedup implementation, we only checked for implicit transactions at the beginning of the dedup window when a manual transaction was logged. However, based on testing, an implicit transaction could occur or be "finished" some elapsed time after the manual transaction occurs but still within the dedup window. Therefore, we update the implementation to recheck for implicit transactions again at the end of the dedup window so we don't miss this edge case.

Reviewed By: jjiang10

Differential Revision: D65046779

fbshipit-source-id: c2f180c3007929abb5a6cebe5884d7284ca4085f
  • Loading branch information
ryantobinmeta authored and facebook-github-bot committed Nov 11, 2024
1 parent bda4393 commit 3870e01
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ extension IAPDedupeProcessor {

extension IAPDedupeProcessor {
private func dedupTimerFired() {
if #available(iOS 15.0, *) {
Task {
await IAPTransactionObserver.shared.observeNewTransactions()
executeDedupTimerFired()
}
} else {
executeDedupTimerFired()
}
}

private func executeDedupTimerFired() {
timer?.invalidate()
timer = nil
var implicitEvents = synchronizedImplicitEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ extension IAPEventResolver {
eventName: AppEvents.Name
) -> IAPEvent? {
let transaction = iapTransaction?.transaction
var currency = transaction?.currencyCode
var currency: String?
if #available(iOS 16.0, *) {
currency = transaction?.currency?.identifier
} else {
currency = transaction?.currencyCode
}
let introOffer = product.subscription?.introductoryOffer
let hasIntroductoryOffer = introOffer != nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ extension IAPDedupeProcessorTests {
func testDedupWithDuplicatePurchaseEvents() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.nonConsumableProduct1.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
dedupeProcessor.processManualEvent(
.purchased,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
AppEvents.ParameterName.contentID: productID,
Expand Down Expand Up @@ -642,13 +642,13 @@ extension IAPDedupeProcessorTests {
func testDedupWithDuplicateSubscribeEvents() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.autoRenewingSubscription1.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
dedupeProcessor.processManualEvent(
.subscribe,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
AppEvents.ParameterName.contentID: productID,
Expand Down Expand Up @@ -676,13 +676,13 @@ extension IAPDedupeProcessorTests {
func testDedupWithDuplicateStartTrialEvents() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.autoRenewingSubscription2.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
dedupeProcessor.processManualEvent(
.startTrial,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
AppEvents.ParameterName.contentID: productID,
Expand Down Expand Up @@ -710,13 +710,13 @@ extension IAPDedupeProcessorTests {
func testDedupWithDuplicatePurchaseEventsTestDedupConfig() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.nonConsumableProduct1.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
dedupeProcessor.processManualEvent(
.purchased,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
AppEvents.ParameterName.contentID: productID,
Expand Down Expand Up @@ -745,13 +745,13 @@ extension IAPDedupeProcessorTests {
func testDedupWithNonDuplicatePurchaseEvents() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.nonConsumableProduct1.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
dedupeProcessor.processManualEvent(
.purchased,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
],
Expand All @@ -777,7 +777,7 @@ extension IAPDedupeProcessorTests {
func testSeveralManualAndImplicitEventsWithSomeDuplicatesAndSomeNonDuplicates() async {
dedupeProcessor.enable()
let productID = Self.ProductIdentifiers.nonConsumableProduct1.rawValue
guard let (iapTransaction, _) =
guard let (iapTransaction, product) =
await executeTransactionFor(productID) else {
return
}
Expand All @@ -788,7 +788,7 @@ extension IAPDedupeProcessorTests {
}
dedupeProcessor.processManualEvent(
.purchased,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? 0,
valueToSum: iapTransaction.transaction.price?.currencyNumber ?? product.price.currencyNumber,
parameters: [
AppEvents.ParameterName.currency: "USD",
AppEvents.ParameterName.contentID: productID,
Expand Down

0 comments on commit 3870e01

Please sign in to comment.