OneSignal / OneSignal-Website-SDK

OneSignal is a push notification service for web and mobile apps. This SDK makes it easy to integrate your website with OneSignal Push Notifications. https://onesignal.com
Other
389 stars 115 forks source link

[Bug]: subscriptions' languages get overwritten when logging in with same user on multiple devices (160001) #1096

Closed lmeurs closed 2 weeks ago

lmeurs commented 1 year ago

What happened?

During out tests we logged in with the same user on different devices. When logging in for the first time on a new device, languages of all subscriptions get reset to en.

Possibly related: https://github.com/OneSignal/OneSignal-Website-SDK/issues/1094

What browsers are you seeing the problem on?

Chrome (Chromium)

What operating system are you running?

W11, Android 13

Steps to reproduce?

1. Implement OneSignal SDK with button calling `OneSignal.User.PushSubscription.optIn()` on click
2. Add `permissionChange` event handler for `OneSignal.Notifications` which calls `OneSignal.login(123456789)` when a user grants permission
3. Log in on device A
4. Set language to eg. _fr_ using the API
5. Check the user's language in the OneSignal dashboard
6. Log in on device B
7. Check the user's language in the OneSignal dashboard

What did you expect to happen?

I expected the originally set language to remain in tact

Relevant log output

No response

jkasten2 commented 1 year ago

@lmeurs Thanks for reporting.

Language is a User level property, it will be the most recent language set for the User.

List of properties and where they are now stored with User Model: image

Full documentation: https://documentation.onesignal.com/docs/user-model-migration-guide

lmeurs commented 1 year ago

@jkasten2: thank you for your reply. It's clear that language is a user level property. As explained at https://github.com/OneSignal/OneSignal-Website-SDK/issues/1094#issuecomment-1684403605 we set the user language server side through API PATCH requests to https://onesignal.com/api/v1/users/by/custom_alias/123456.

In case of a new subscription, it seems like the user's language property automatically gets overwritten by the browser's default language. Is this correct? If so, is this expected behavior? The POC is for a website in 10 languages, we need control over the stored language, so we can apply custom lanuage fallback.

jkasten2 commented 1 year ago

Thanks for the details here, that makes things very clear to me now.

I am guessing you login in the user first, authenticating with your backend, then call OneSignal.login()? If so would you be able to to give the OneSignal SDK their language preference just before calling OneSignal.login()? Example something like this:

// setLanguage doesn't exist, just a suggestion for demonstration
OneSignal.User.setLanguage(languagePreference);
OneSignal.login(myID);

If not, let me know what would ideal for you.

lmeurs commented 1 year ago

The flow you describe is correct, not sure how setting a custom value client side (like we currently do server side) could solve this issue.

I guess the problem is that language is a property that can be set to a custom value through the API, but automatically gets overwritten when a new subscriptions is created. I understand you have to set the initial language and all you (currently) have is the browser's preferred languages. I also understand the language getting updated in certain occasions, but maybe language should be decoupled from the browser's preferred language after once it has been set to a custom value?

sherwinski commented 2 weeks ago

Closing this due to lack of activity. If this remains an issue, please open a new report with updated information and we will investigate. Thanks