Skip to content

Commit

Permalink
Set new candidates date when autologging is off
Browse files Browse the repository at this point in the history
Summary:
During testing, we noticed an edge case where if the app has autologging turned off and then re-enables it, all of a user's transaction history will be logged, which would likely result in over reporting of events. We should assume that these transactions have already been handled and only consider the transactions that occur after the advertiser enables autologging. To achieve this, we set the new candidates date to ```now``` whenever we observe that autologging is turned off. In doing this, we will only consider transactions that have occurred after this date.

This diff implements this functionality.

Reviewed By: jjiang10

Differential Revision: D66309371

fbshipit-source-id: b578b5782e8b4ead3bc58569a3bc3d9c17b1762e
  • Loading branch information
ryantobinmeta authored and facebook-github-bot committed Dec 3, 2024
1 parent 6726451 commit 232533d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ - (void)fetchServerConfiguration:(FBSDKCodeBlock)callback
}
}];
} else {
[self.iapTransactionCache setNewCandidatesDate:[NSDate date]];
[self.iapDedupeProcessor disable];
[self.paymentObserver stopObservingTransactions];
[self.transactionObserver stopObserving];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extension IAPTransactionCache: _IAPTransactionCaching {
return
}
guard let newValue else {
dependencies.dataStore.fb_removeObject(forKey: IAPConstants.newCandidatesDateCacheKey)
return
}
dependencies.dataStore.fb_setObject(newValue, forKey: IAPConstants.newCandidatesDateCacheKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ final class AppEventsTests: XCTestCase {
iapDedupeProcessor = nil

resetTestHelpers()

IAPTransactionCache.shared.reset()
super.tearDown()
}

Expand Down Expand Up @@ -1797,6 +1797,7 @@ final class AppEventsTests: XCTestCase {
}

func testFetchingConfigurationStopPaymentObservingIfAutoLogAppEventsDisabled() {
let now = Date()
settings.isAutoLogAppEventsEnabled = false
let serverConfiguration = ServerConfigurationFixtures.configuration(
withDictionary: ["implicitPurchaseLoggingEnabled": true]
Expand All @@ -1820,6 +1821,11 @@ final class AppEventsTests: XCTestCase {
transactionObserver.didStopObserving,
"Fetching a configuration should stop transaction observing if auto log app events is disabled"
)
guard let newCandidatesDate = IAPTransactionCache.shared.newCandidatesDate else {
XCTFail("newCandidatesDate should have been set")
return
}
XCTAssertTrue(newCandidatesDate > now)
}

func testEnablingIAPDedupeShouldEnableIAPDedupe() {
Expand Down Expand Up @@ -1883,6 +1889,7 @@ final class AppEventsTests: XCTestCase {
}

func testEnablingIAPDedupeShouldNotEnableIAPDedupeWhenImplicitPurchaseIsDiabled() {
let now = Date()
settings.isAutoLogAppEventsEnabled = true
let serverConfiguration = ServerConfigurationFixtures.configuration(
withDictionary: ["implicitPurchaseLoggingEnabled": 0]
Expand All @@ -1895,6 +1902,11 @@ final class AppEventsTests: XCTestCase {

XCTAssertFalse(iapDedupeProcessor.enableWasCalled)
XCTAssertTrue(iapDedupeProcessor.disableWasCalled)
guard let newCandidatesDate = IAPTransactionCache.shared.newCandidatesDate else {
XCTFail("newCandidatesDate should have been set")
return
}
XCTAssertTrue(newCandidatesDate > now)
}

func testFetchingConfigurationIncludingSKAdNetworkIfSKAdNetworkReportEnabled() {
Expand Down

0 comments on commit 232533d

Please sign in to comment.