5

I'm using onesignal for first time in my project. I have to send notification to specific users (wherever user is logged in either on chrome or android device) on some events like whatsapp sends notification on mobile as well as website too and only if user is logged in. I have successfully sent notification to all users. After some R&D on OneSignal, I come to know that I have to send notifications to specific playerId for this purpose. But here are some my questions/doubts.

  • I think player Id is device id. If I'm right, what if current user logged out and another user gets logged in on same device. How can I come to know that I have not to send notification on this player Id as user is changed.
  • Will be there multiple playerIds for single user? One for chrome, one for iOS device, one for Android etc?
  • How I will get playerId of user to store in my database. Because I have to use server rest API to send notifications.

If anyone can explain the points and also describe work flow to store playerid (when and how) in my database, it will be appreciated.

Akshay Vaghasiya
  • 1,597
  • 9
  • 36
  • 60

3 Answers3

4

Just store playerIds into database with login activity. when they logout just fire a query related to remove playerIds from database.

Kishan
  • 465
  • 4
  • 13
3

I developed an android app not too long ago which used OneSignal for it's notifications. This was developed in C# however may be useful to you.

I hope these answers help:

-The Player ID is generated by the OneSignal class, and as such need to be retrieved using callback function, such as the code seen below:

void CheckPushRegistration(){
    OneSignal.GetIdsAvailable(IdsAvailable); //Passes the 'callback'

}

private void IdsAvailable(string userID, string pushToken) {
    player_id = userID;
    player_token = pushToken;

    //Make a request to my server to store this information along with device id
    //For easy reference
}

Note: In the code above, I call the function 'CheckPushRegistration' right at the start of the app run. Once it is run it will send the information to the 'IdsAvailable' function. After this I make a quick web request to my server to store the unique player ID, device ID, and token.

-The Player ID, at least in android is based on the devices linked Google Play account if I am not mistaken. Meaning if a user switches accounts it will count/act as a different Player ID (However I could be wrong here)

I assume OneSignal has some way of determining the Player ID or User ID on browsers/other devices. However it is safe to assume they will always be unique and do not carry through based on the user account.

-As mentioned earlier you store it into your database by making a simple web request to your REST API, store only the Device ID, Player ID, and Token information. Perhaps add a check to see if the device ID is not already in the system. I would recommend using the Device ID to identify a user.

You also asked how you would know if a notification was sent correctly, or if it was safe to send. Unfortunately the OneSignal API will only be able to report back on a notification status.

When you do send the notification, you will receive a notification ID back from the server. You can use this at a later stage to checked if a notification was delivered, if it was viewed, and if it was tapped.

I hope this helps to shed some light on the OneSignal system?

Dylan Auty
  • 360
  • 2
  • 6
  • What will be userId value if another user logged in in same application? Will it change or be same? – Akshay Vaghasiya Mar 10 '17 at 06:11
  • To my understanding the User ID will change when the Player Account is changed. Meaning that if a user does login to a different account from the same device, it will count as a separate User ID. – Dylan Auty Mar 10 '17 at 06:12
  • I therefore suggest also tracking the device ID so that you can send notifications to all Player ID's of the same device. (This is what I did) – Dylan Auty Mar 10 '17 at 06:13
  • But how onesignal will come to know that this is another user on same device? We are not sending any user data. Right? – Akshay Vaghasiya Mar 10 '17 at 06:18
  • Well the device ID would be used as an identifier, if that makes sense? – Dylan Auty Mar 10 '17 at 07:43
  • 1
    It remains the same playerid because it is related to device not A User or account. – Emil Nov 08 '17 at 10:52
2

Player Id is not a device Id, it is a UUID (Unique Universal Identifier) that OneSignal gives

Managing Multiple Users On One Device To manage multiple users that share a device, you will need to detect when User A is on the device and only send them their notifications when they are on the device, otherwise User B will get them.

Method A: Tagging One way to handle this is to tag the user when they sign in to the app, then you can target them by the tag and they will get the notification if the tag is set. Once they log out of the app, you can remove the tag.

So if User B is using the device, then they will get their own tag and will not get User A's notification. So the users will only get the notifications when they are logged into the app.

Method B: CRM or Database The other option is to store on your server the Player IDs of the devices the user is currently logged in with, and then use our API to send notifications using the "include_player_ids" API targeting parameter. for more detail check this One signal player id

prashant kute
  • 333
  • 4
  • 9