Skip to content

[Question]: How can I set the externalId when subscribing a new user. #1268

Open
@PWRM

Description

@PWRM

How can we help?

How can I set the externalId when subscribing to a new user? According to some research I did, I have to install an Eventhandler. In the handler I can get the userID and attach my own externalId, and set it. If I cannot set the externalId, that's fine, but then I need to know the OneSignal_ID, so I can send future Push messages to a single user. Seems to me the OneSignal_ID should be provided by the change Event.

Tried many setups, with await and without, but the event is never called. According to the documentation this should be the initialisation:

<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
  window.OneSignalDeferred = window.OneSignalDeferred || [];
  OneSignalDeferred.push(async function(OneSignal) {
    await OneSignal.init({
      appId: <MYAPPID>,
            notifyButton: {
                enable: true
            }
    });
  });
OneSignalDeferred.push(function() {
  OneSignal.User.addEventListener('change', function (event) {
    console.log('change', { event });
  });
});

</script>

Why is the change Event not called?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions