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>
Thank you! We'll be in touch within 48 hours :)
Oops! Something went wrong while submitting the form.
Preview My App
Preview My App