How to: Use Advanced OneSignal Features

Posted on 15. November 2023 by Jan Bunk


Do you want to use advanced features of OneSignal? Many of those might require you to associate an external ID with OneSignal users so you can take advantage of OneSignal's REST API.

Enabling the feature

Make sure you have enabled OneSignal in your push notification settings. OneSignal also needs to be fully activated which usually involves an app update.

Available JavaScript Functions

You might want to check out the executeWhenAppReady() function of our app helper script. It ensures that your website doesn't try to interact with the app before it's ready or when your website is loaded using a regular browser (ReferenceError, function is not defined).

oneSignalLogin

Use this function to associate an external ID (that you use to identify the user on your website) to a OneSignal user. See the documentation for OneSignal.login for more information.


<script>
    try {
        oneSignalLogin("abc123");
    }
    catch (e) {
        // Can occur if:
        // - the app couldn't connect to the native code. Should be very unlikely.
        // - push notifications are not included in your current plan
        console.log(e);
    }
</script>
    

oneSignalLogout

Use this function to remove an external ID from a OneSignal user. See the documentation for OneSignal.logout for more information.


<script>
    try {
        oneSignalLogout();
    }
    catch (e) {
        // Can occur if:
        // - the app couldn't connect to the native code. Should be very unlikely.
        // - push notifications are not included in your current plan
        console.log(e);
    }
</script>