Remove external user ID from OneSignal

If you would like to remove the external user ID from a user profile in OneSignal you can trigger the nativeFunctions.onesignalRemoveExternalUserId() function.

This can be helpful in case you don’t want users that are not logged in to receive push notifications, for example.

If that is the case, whenever you log a user out of his account you would also call the nativeFunctions.onesignalRemoveExternalUserId() function, as follows:

<script type="text/javascript">
    // Listen to events
    window.addEventListener("message", (event) => {
        runNativeFunctions(event);
    }, false);

    // Set the user ID
    var userId = "1"

    // Function that runs when the event is triggered
    function runNativeFunctions(event) {
        try {

            // Check if the native functions are ready to be used
            if (event.data && event.data == 'nativeFunctionsLoaded') {
                // Native function can be called here
                nativeFunctions.onesignalRemoveExternalUserId($userId);
            }

        } catch (ex) {
            // Log any error messages for easier debugging
            console.log(ex.message;);
        }
    }
</script>

Convert your website into a mobile app

Get custom mobile apps for iOS and Android that update
automatically with your site and works with your entire tech stack.
Rainbow Shops logo.Bestseller's logo.John Varvatos logo.
Thank you! We'll be in touch within 48 hours :)
Oops! Something went wrong while submitting the form.
Chat icon.