Skip to content

Fix issue with missing subscriber attributes if set after login but before login callback#809

Merged
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-2816-fix-issue-with-missing-subscriber
Mar 2, 2023
Merged

Fix issue with missing subscriber attributes if set after login but before login callback#809
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-2816-fix-issue-with-missing-subscriber

Conversation

@tonidero

@tonidero tonidero commented Feb 21, 2023

Copy link
Copy Markdown
Contributor

Description

Deals with SDK-2816

There was an issue where subscriber attributes could be delayed to be synced to the backend. This happened when setting a subscriber attribute AFTER the logIn call but BEFORE the logIn operation was completed.

This issue happens because we start syncing subscriber attributes immediately when calling logIn, but if we set any after that but before the login is complete, they will be assigned to the old user id. We would sync those the next time the app is backgrounded/foregrounded but might be missed if there is a purchase in between since when there is a purchase, we only sync the current user's unsynced attributes.

This PR copies all unsynced attributes from the old user id to the new one upon a successful login. This way, the unsynced attributes will be sent if the user tries to purchase.

Note that we only copy these attributes when the old user id was anonymous. This is because there is a possible edge case of copying attributes from a user to a different user if the sync request fails and remains unsynced when changing between user ids.

@tonidero tonidero added the pr:fix A bug fix label Feb 21, 2023
}
infoLog(AttributionStrings.COPYING_ATTRIBUTES_FROM_TO_USER.format(originalAppUserId, newAppUserID))
deviceCache.setAttributes(newAppUserID, unsyncedAttributesPreviousUser)
deviceCache.clearAllSubscriberAttributesFromUser(originalAppUserId)

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.

Note how we are deleting the unsynced attributes from the old user id after we set them for the new user id so there should be no chance of losing them.

@tonidero tonidero requested a review from a team February 21, 2023 12:30
@tonidero tonidero marked this pull request as ready for review February 21, 2023 12:30
@codecov

codecov Bot commented Feb 21, 2023

Copy link
Copy Markdown

Codecov Report

Merging #809 (de15605) into main (833994a) will increase coverage by 0.04%.
The diff coverage is 92.85%.

❗ Current head de15605 differs from pull request most recent head faa6267. Consider uploading reports for the commit faa6267 to get more accurate results

@@            Coverage Diff             @@
##             main     #809      +/-   ##
==========================================
+ Coverage   81.54%   81.58%   +0.04%     
==========================================
  Files         121      121              
  Lines        3999     4008       +9     
  Branches      512      514       +2     
==========================================
+ Hits         3261     3270       +9     
  Misses        535      535              
  Partials      203      203              
Impacted Files Coverage Δ
...revenuecat/purchases/strings/AttributionStrings.kt 0.00% <ø> (ø)
...m/revenuecat/purchases/identity/IdentityManager.kt 96.77% <83.33%> (+0.16%) ⬆️
...ubscriberattributes/SubscriberAttributesManager.kt 89.69% <100.00%> (+0.56%) ⬆️
...berattributes/caching/SubscriberAttributesCache.kt 98.03% <100.00%> (+0.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

tonidero added a commit to RevenueCat/purchases-ios that referenced this pull request Feb 23, 2023
…efore login callback (#2313)

### Description
Deals with
[SDK-2817](https://linear.app/revenuecat/issue/SDK-2817/fix-issue-with-missing-subscriber-attributes-on-purchases-[ios])
This is the iOS counterpart to
RevenueCat/purchases-android#809

There was an issue where subscriber attributes could be delayed to be
synced to the backend. This happened when setting a subscriber attribute
AFTER the `logIn` call but BEFORE the `logIn` operation was completed.

This issue happens because we start syncing subscriber attributes
immediately when calling `logIn`, but if we set any after that but
before the login is complete, they will be assigned to the old user id.
We would sync those the next time the app is backgrounded/foregrounded
but might be missed if there is a purchase before that happens. When
there is a purchase, we only sync the current user's unsynced
attributes, but not attributes of other users.

This PR copies all unsynced attributes from the old user id to the new
one upon a successful login. This way, the unsynced attributes will be
sent if the user tries to purchase.

Note that we only copy these attributes when the old user id was
anonymous. This is because there is a possible edge case of copying
attributes from a user to a different user if the sync request fails and
remains unsynced when changing between user ids.
user to list.map {
it.key.backendKey to it
}.toMap()
user to list.associateBy {

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.

Nice

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.

Suggested by Android Studio, pretty nice yup 😄

@tonidero tonidero enabled auto-merge (squash) March 2, 2023 10:31
@tonidero tonidero merged commit 86fa0fc into main Mar 2, 2023
@tonidero tonidero deleted the toniricodiez/sdk-2816-fix-issue-with-missing-subscriber branch March 2, 2023 10:53
tonidero pushed a commit that referenced this pull request Mar 9, 2023
**This is an automatic release.**

### Bugfixes
* Fix docs deployment (#836) via Toni Rico (@tonidero)
* Fix issue with missing subscriber attributes if set after login but
before login callback (#809) via Toni Rico (@tonidero)
### Other Changes
* Fix SDKMAN issues (#822) via Toni Rico (@tonidero)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
tonidero added a commit that referenced this pull request Mar 9, 2023
## 5.8.2

⚠️ ⚠️ ⚠️ ⚠️ 

Android SDK versions 5.8.0 and 5.8.1 have a major bug that prevents
sending purchase tokens to RevenueCat. Users will get charged but won't
receive entitlements. An automatic refund will occur after 72 hours
unless an unaffected SDK version is used. Downgrade to 5.7.1 or upgrade
to 5.8.2 or later to avoid this bug.
Users who got charged while using 5.8.0 and 5.8.1 will be able to access
their purchases automatically upon opening an app that uses 5.7.1 or
lower, or 5.8.2 or higher.

⚠️ ⚠️ ⚠️ ⚠️

### Other changes in 5.8.0 and 5.8.1
### New Features
* Diagnostics (#811) via Toni Rico (@tonidero)
### Bugfixes
* Fix issue with missing subscriber attributes if set after login but
before login callback (#809) via Toni Rico (@tonidero)
### Dependency Updates
* Bump fastlane from 2.212.0 to 2.212.1 (#821) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane from 2.211.0 to 2.212.0 (#808) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-versioning_android from 0.1.0 to 0.1.1 (#798) via
dependabot[bot] (@dependabot[bot])
* Bump danger from 8.6.1 to 9.2.0 (#778) via dependabot[bot]
(@dependabot[bot])
### Other Changes
* Fix docs deployment (#836) via Toni Rico (@tonidero)
* Fix SDKMAN issues (#822) via Toni Rico (@tonidero)
* Fix bundle install on CircleCI (#827) via Cesar de la Vega (@vegaro)
* Update README.md to include minimum Kotlin version (#786) via Cesar de
la Vega (@vegaro)
* Remove `tag_release_with_latest_if_needed` fastlane lane (#781) via
Cesar de la Vega (@vegaro)
* Adds docs for timeouts when closing and releasing (#759) via Cesar de
la Vega (@vegaro)
* Add Amazon App tester package to purchase tester queries (#789) via
Stefan Wehner (@tonidero)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
NachoSoto pushed a commit to RevenueCat/purchases-ios that referenced this pull request Mar 16, 2023
…efore login callback (#2313)

### Description
Deals with
[SDK-2817](https://linear.app/revenuecat/issue/SDK-2817/fix-issue-with-missing-subscriber-attributes-on-purchases-[ios])
This is the iOS counterpart to
RevenueCat/purchases-android#809

There was an issue where subscriber attributes could be delayed to be
synced to the backend. This happened when setting a subscriber attribute
AFTER the `logIn` call but BEFORE the `logIn` operation was completed.

This issue happens because we start syncing subscriber attributes
immediately when calling `logIn`, but if we set any after that but
before the login is complete, they will be assigned to the old user id.
We would sync those the next time the app is backgrounded/foregrounded
but might be missed if there is a purchase before that happens. When
there is a purchase, we only sync the current user's unsynced
attributes, but not attributes of other users.

This PR copies all unsynced attributes from the old user id to the new
one upon a successful login. This way, the unsynced attributes will be
sent if the user tries to purchase.

Note that we only copy these attributes when the old user id was
anonymous. This is because there is a possible edge case of copying
attributes from a user to a different user if the sync request fails and
remains unsynced when changing between user ids.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants