Fix issue with missing subscriber attributes if set after login but before login callback#2313
Conversation
…efore login callback
NachoSoto
left a comment
There was a problem hiding this comment.
Nice 👍🏻
Just a few small things
| case adservices_token_post_succeeded | ||
| case adservices_token_unavailable_in_simulator | ||
| case latest_attribution_sent_user_defaults_invalid(networkKey: String) | ||
| case copying_attributes_from_to_user(oldAppUserID: String, newAppUserID: String) |
There was a problem hiding this comment.
The swift way of naming this would be:
| case copying_attributes_from_to_user(oldAppUserID: String, newAppUserID: String) | |
| case copying_attributes(from oldAppUserID: String, to newAppUserID: String) |
There was a problem hiding this comment.
Hmm when I try that, I get Enum case cannot have keyword arguments. Looking around, I don't think it's supported on enums? Going to rename it to copying_attributes(oldAppUserID: String, newAppUserID: String) though, since that's probably clearer.
There was a problem hiding this comment.
Oh yes sorry, that works
| userDefaults.setValue(groupedSubscriberAttributes, forKey: .subscriberAttributes) | ||
| } | ||
|
|
||
| static func deleteAllAttributes( |
There was a problem hiding this comment.
Nice refactor extracting these 2.
|
Ah backend tests are failing due to verification needing an update. Will hold this until then. |
|
Yeah they deployed that a few days ago with no working. They're already failing in Hopefully I can finish #2309 today to fix them. |
…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.
Description
Deals with SDK-2817
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
logIncall but BEFORE thelogInoperation 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.