OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

[Bug]: Cannot set tags and external id to the user sometimes

Open bundleberk opened this issue 1 year ago • 2 comments

What happened?

When I try to call OneSignal.Login and addTags methods I get this error for the operation named "login-user" on the logs sometimes:

POST - STATUS: 400 - Body: {"errors":[{"code":"user-3","title":"Creating a User requires at least one Alias or Subscription"}]}

when I check the subscription with the subscription id on onesignal panel, I see that there is a subscription with the state "never subscribed" and even if I allowed the notifications I see the "permission not granted" tag.

Screenshot 2024-12-16 at 23 59 34

also it seems that the subscription cannot be created after closing and reopening the app.

Steps to reproduce?

1- Run the app.
2- Call Onesignal.Login and addTags()

What did you expect to happen?

I expect to set the data tags and the external id successfully.

OneSignal Android SDK version

Release 5.1.15

Android version

15, 14, 13, 12, 11, 10

Specific Android models

No response

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

bundleberk avatar Dec 16 '24 21:12 bundleberk

Hello @bundleberk, this issue could be the result of a known bug in our 5.2.0-beta version if the OneSignal SDK version is set to [5.0.0, 5.99.99]. I recommend setting the version to [5.0.0, 5.1.99] to avoid an unintended upgrade to the beta version. Please let us know if the problem persists after making this change.

jinliu9508 avatar Jan 17 '25 21:01 jinliu9508

Hi @bundleberk were you able to resolve?

nan-li avatar Feb 13 '25 22:02 nan-li

Hi @bundleberk were you able to resolve?

Nope, the issue still persists on the version 5.1.15. Cannot set tags on some users and SDK never retries setTags itself.

I wrote a custom retry method on every app launch that gets user tags and if they don't exist sets them again. But that does not work either sometimes.

bundleberk avatar Jul 24 '25 15:07 bundleberk

Hi @bundleberk,

To confirm, you are still using the OneSignal Android SDK version 5.1.15?

Is this happening for an existing app install or new app install? An existing app install may be stuck in a bad state.

Can you share the logs from around the time you call login? The error STATUS: 400 - Body: {"errors":[{"code":"user-3","title":"Creating a User requires at least one Alias or Subscription"}]} is the main issue. Tags will not be added when login fails with a 400 error.

nan-li avatar Jul 24 '25 17:07 nan-li

hi @nan-li

yes i am still using the version 5.1.15. I am not sure if this error is the only reason. Maybe sometimes login and addTags kind of race when you call them together at the same time and setting the external id removes tags? I will send the logs if i can reproduce this again. it does not happen every time.

there is another case that i get 200 from the setTag requests (i see this in the logs) but I don't see the tag i set on the subscription later. so sometimes it still fails even when the setTags is successful.

bundleberk avatar Jul 25 '25 07:07 bundleberk

Maybe sometimes login and addTags kind of race when you call them together at the same time and setting the external id removes tags?

There is a detail that can help you understand how login and tags work together (or any user update for that matter).

The tags belong to the user in the SDK at the moment this method is called. If you call login after you call addTag, they may or may not end up on the user with that external ID:

  • If the external ID you are logging into is brand new to the OneSignal server, this external ID is simply attached to the current user who owns the tag. You will see in your dashboard that this user still has the same onesignal ID, but now has an additional external ID. In this case, the tags will show up on the user with this external ID.
  • However, if this external ID is not new, that means there is a user with this external ID already. In order to not mix up user data, the tags do not move over. No user data is transferred to the user with this external ID. The SDK does not want to assume the data added before login should go to the next user. In this case, you will not see those tags when you look up the user with this external ID.

nan-li avatar Jul 25 '25 16:07 nan-li

I will send the logs if i can reproduce this again. it does not happen every time.

If you can capture them, that would be great.

nan-li avatar Jul 25 '25 17:07 nan-li

This issue is related to issue #2344 which was also closed.

Feel free to open a new issue if after making the suggested changes in that issue doesn't work. If you make a new issue make sure to reference these for background.

jkasten2 avatar Aug 12 '25 19:08 jkasten2