I recently learnt how to use OneSignal. One of my clients needed a pop up notification when ever a message came through on their web app.
How to set up OneSignal:
- First you will need to sign up on OneSignal.
- Once your profile has been setup you can login in and create a new app/website.
- Then fill in your website name and select Web Push:
- Then select Custom Code and fill out the rest of the information for your site:
- Then Download the SDK files and save them in your main folder of your web app project.
- Then add this code to the <head> section on all pages of your site:
The above set up is for all browsers except for safari, if you need your notifications to also work on safari then under platform settings you can add safari and configure it with your same sites details.
How to use OneSignal in your web app:
- Add this code to automatically send a notification when a new user lands on your web app. This notification asks the user for permissions to send notifications.
- If you only want certain users to get notifications based on something that they have joined are their user roles you can use tags.
- First I will show you how to add and remove a tag/tags from your users:
- How to send a notification:
All set now your users will be receiving notifications!
</ Fun Coding! >