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">
// Get the user agent and convert it to lowercase for case-insensitive comparison
var userAgent = navigator.userAgent.toLowerCase();
// Set the user ID
var userId = "1";
try {
// Check if the user agent contains the string "canvas"
if (userAgent.indexOf('canvas') > -1) {
// Native function can be called here
nativeFunctions.onesignalRemoveExternalUserId(userId);
}
} catch (ex) {
// Log any error messages for easier debugging
console.log(ex.message);
}
</script>