Skip to content

PostReceiptOperation: added ability to also post AdServices token#2549

Merged
NachoSoto merged 1 commit into
release/4.19.0from
nacho/sdk-3151-post-search-ads-token-on-post-receipt
May 26, 2023
Merged

PostReceiptOperation: added ability to also post AdServices token#2549
NachoSoto merged 1 commit into
release/4.19.0from
nacho/sdk-3151-post-search-ads-token-on-post-receipt

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

Changes:

  • Added aadAttributionToken to PostReceiptDataOperation
  • Exposed AttributionPoster.adServicesTokenToPostIfNeeded
  • Added snapshot test to verify it's sent
  • Added PurchasesOrchestrator tests (SK1/SK2) for sending the attribution token
  • Added missing PurchasesOrchestrator tests for sending attributes
  • Added log when marking AdServices token as synced
  • Exposed Purchases.attribution for custom entitlement computation framework (and added to API tester)
  • Exposed Purchases.enableAdServicesAttributionTokenCollection for custom entitlement computation framework (and added to API tester)

@NachoSoto NachoSoto requested a review from a team May 25, 2023 20:10
@NachoSoto NachoSoto changed the title PostReceiptOperation: added ability to also post AdServices token PostReceiptOperation: added ability to also post AdServices token May 25, 2023
@NachoSoto NachoSoto force-pushed the nacho/sdk-3151-post-search-ads-token-on-post-receipt branch 3 times, most recently from ed50d30 to bf57b6a Compare May 25, 2023 20:34

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks great! Left a couple of small comments

Comment on lines 180 to 181

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

feels odd for subs attributes manager to be in charge for this - there's no subs attribute involved, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realize that this is piping through deviceCache anyway, but I feel like going directly might be more appropriate in this case - there's no subs attribute involved, but if I were reading this code with no context, I'd assume that the token is stored as a subs attribute

If we want to share the code, I think this could be either a part of DeviceCache itself or its own object, it just feels arbitrary to add it to subs attributes manager since it's not really related

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm I agree. That's what I had originally, I think I moved this so I could mock it, let me see.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's mainly because we don't mock AttributionPoster, and I wanted to verify this is called, but I'll see if I can do it in another way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread Tests/StoreKitUnitTests/PurchasesOrchestratorTests.swift Outdated

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks great! Left a couple of small comments

@NachoSoto NachoSoto force-pushed the nacho/sdk-3151-post-search-ads-token-on-post-receipt branch from bf57b6a to 25f59d7 Compare May 25, 2023 21:28
@NachoSoto NachoSoto deleted the branch release/4.19.0 May 25, 2023 21:49
@NachoSoto NachoSoto closed this May 25, 2023
@NachoSoto NachoSoto reopened this May 25, 2023
- Added `aadAttributionToken` to `PostReceiptDataOperation`
- Exposed `AttributionPoster.adServicesTokenToPostIfNeeded`
- Added snapshot test to verify it's sent
- Added `PurchasesOrchestrator` tests (SK1/SK2) for sending the attribution token
- Added missing `PurchasesOrchestrator` tests for sending attributes
- Added log when marking `AdServices` token as synced
- Exposed `Purchases.attribution` for custom entitlement computation framework (and added to API tester)
- Exposed `Purchases.enableAdServicesAttributionTokenCollection`  for custom entitlement computation framework (and added to API tester)
@NachoSoto NachoSoto force-pushed the nacho/sdk-3151-post-search-ads-token-on-post-receipt branch from 25f59d7 to 530dc1b Compare May 25, 2023 21:51
@NachoSoto NachoSoto requested a review from a team May 25, 2023 21:51
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Updated this to point to release/4.19.0. Will merge there and then make 4.19.1.

@codecov

codecov Bot commented May 25, 2023

Copy link
Copy Markdown

Codecov Report

Merging #2549 (530dc1b) into release/4.19.0 (f5d45ee) will increase coverage by 0.07%.
The diff coverage is 98.66%.

@@                Coverage Diff                 @@
##           release/4.19.0    #2549      +/-   ##
==================================================
+ Coverage           87.70%   87.77%   +0.07%     
==================================================
  Files                 197      197              
  Lines               13278    13332      +54     
==================================================
+ Hits                11645    11702      +57     
+ Misses               1633     1630       -3     
Impacted Files Coverage Δ
Sources/Attribution/AttributionPoster.swift 93.29% <96.15%> (+0.07%) ⬆️
Sources/Logging/Strings/AttributionStrings.swift 86.73% <100.00%> (+0.41%) ⬆️
Sources/Networking/Backend.swift 88.63% <100.00%> (+0.13%) ⬆️
Sources/Networking/CustomerAPI.swift 100.00% <100.00%> (ø)
...tworking/Operations/PostReceiptDataOperation.swift 90.35% <100.00%> (+0.17%) ⬆️
Sources/Purchasing/Purchases/Attribution.swift 93.44% <100.00%> (+5.82%) ⬆️
Sources/Purchasing/Purchases/Purchases.swift 76.59% <100.00%> (-0.04%) ⬇️
...s/Purchasing/Purchases/PurchasesOrchestrator.swift 86.57% <100.00%> (+0.20%) ⬆️

... and 1 file with indirect coverage changes

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but will leave it to @aboedo to give the final approval since I'm not completely familiar with the requirements here.


guard let attributionToken = attributionFetcher.adServicesToken else {
return
guard self.latestNetworkIdAndAdvertisingIdentifierSent(network: .adServices) == nil else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've not been involved in the specs so this might be correct, but with this, only the first purchase for a user will send the token right? As in, if a user unsubscribes, the purchase expires and then resubscribes, the second time it won't be sent. Not sure if this token can change, so it might be ok to just send it the first time, but I thought I would mention it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, that should be fine. That's the same behavior we have for adservices in other places.
And in practice, attribution tokens expire quickly, and a user will only be attributed once

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the fast work here!

@NachoSoto NachoSoto merged commit 4a97912 into release/4.19.0 May 26, 2023
@NachoSoto NachoSoto deleted the nacho/sdk-3151-post-search-ads-token-on-post-receipt branch May 26, 2023 14:04
NachoSoto added a commit that referenced this pull request May 26, 2023
…2551)

Because `AAAttribution.attributionToken()` isn't available on
simulators, we currently had no coverage for this entire part of the
codebase.
By mocking the token (on simulator + debug + integration tests only), we
can verify posting to the server works correctly.

As a follow-up, we can also verify that posting it as part of the
receipt with #2549 works correctly as well.
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Post-refactor version: #2566.

NachoSoto added a commit that referenced this pull request May 31, 2023
…#2566)

Cherry-picked #2549 post refactors (#2540 and #2542). This becomes a lot
simpler since #2542, thanks to the fact that we can put this new
parameter in `PurchasedTransactionData`.

### Changes:
- Added `aadAttributionToken` to `PurchasedTransactionData`
- Exposed `AttributionPoster.adServicesTokenToPostIfNeeded`
- Added snapshot test to verify it's sent
- Added `PurchasesOrchestrator` tests (SK1/SK2) for sending the
attribution token
- Added missing `PurchasesOrchestrator` tests for sending attributes
- Added log when marking `AdServices` token as synced
- Exposed `Purchases.attribution` for custom entitlement computation
framework (and added to API tester)
- Exposed `Purchases.enableAdServicesAttributionTokenCollection` for
custom entitlement computation framework (and added to API tester)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants