OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
623 stars 213 forks source link

[question]: when i register a user in my backend, how do i retain OneSignal user and ID in a Flutter app? #966

Open jaanusStagnation opened 4 weeks ago

jaanusStagnation commented 4 weeks ago

How can we help?

We have a Flutter app

We use OneSignal with RevenueCat in our system. When we initialize the app both SDKs create anonymous accounts for the user. When a user is logged in, it switches the context to the specific externalID we provide. What we assumed would happen is that the OneSignal ID from the Flutter SDK to RevenuCat, would upon registering a new user in our database and using the login(externalID) method on both SDKs, they would retain the anonymous users and upgrade them to actual accounts. However what i have tested - RevenueCat retains the user and adds the external ID to the existing account. OneSignal instead decides to delete the User and subscription from its system and creates a new one (the OneSignal ID generated on initialization is removed entirely). This means that all data collected before login(...) is erased and RevenueCat needs to be updated along with the new ID and i would need to copy tags before login and paste after login to retain at least some data.

Is it possible to retain the OneSignal anonymous user the SDK generates if logged out of OneSignal and somehow append the externalID to the existing OneSignal user?

Code of Conduct

jaanusStagnation commented 3 weeks ago

i noticed the SDK reference document shows that it should keep the anonymous user ID if the external ID does not exist. However this is not true, atleast for the flutter SDK image we register the oneSignalID to RC at the start up of the app (this is confirmed to pass the ID since it generates this on initialization) final oneSignalId = await OneSignal.User.getOnesignalId(); await Purchases.setAttributes({'\$onesignalUserId': oneSignalId});

however after the below step, the temporary user is erased from OneSignal user list and a new one is generated in its place await OneSignal.login(user.id); await OneSignal.User.addEmail(user.email); await OneSignal.User.addTagWithKey('full_name', user.name);

the external ID provided does not exist on the OneSignal account so why is the temporary user deleted?