Skip to main content

Web Push - Implementing Device Registration

In this guide we will dive deeper into how you should handle the device registration. When you launch() Notificare, the device will be registered as a non-push device.

When a successful device registration takes place, we will emit an event. You can listen to those registrations like the following.

import { onDeviceRegistered } from 'notificare-web/core';

onDeviceRegistered((device) => {
// more code ...
});

You can also check the details of the currently registered device.

import { getCurrentDevice } from 'notificare-web/core';

const device = getCurrentDevice();

The onReady() event will be fired when all Notificare modules has been launched, including a successful device registration.

Additionally, you can verify whether Notificare is ready at any point by calling isReady() or listen to the onReady() event anywhere in your code as described below.

import { isReady, onReady } from 'notificare-web/core';

onReady((application) => {
// more code ...
});

Assign a user to the device

By default, a device is registered as an anonymous user. However, to fully use push notifications in your Actito omni-channel strategy, simply registering an anonymous device is not what you want. You will therefore need to tell the library you want to register as a specific user.

import { registerDevice } from 'notificare-web/core';

await registerDevice({
userId: '7f42bedc-d74b-4c64-a5cf-76bcc5130b05',
userName: 'John Doe',
});

After that, the device will remain registered with that userId / userName until you explicitly register it as anonymous. Depending on the way you authenticate users, you might want to check the logged in state on launch (in the onReady) and change it if necessary. Forcing registration as anonymous can be best achieved by setting userId and userName to null.

tip

Only the userId will be used to match devices to profiles in your Actito DB.
The userName is only used to provided additional information.

import { registerDevice } from 'notificare-web/core';

await registerDevice({
userId: null,
userName: null,
});

To choose the proper user ID:

  • The data must be available as a key in Actito thanks to the data synchronization between your system and Actito.
  • The data must be available on your website (through logging into a client space).

Please use an attribute which is already defined as unique on your Actito profile table.

info

If you need to add a new unique attribute, this is possible, but be careful because it could have impacts on your data synchronization process between your system and Actito. Ask your Integration Data Expert if necessary.

Override Device Language

By default, we will automatically collect the language and region of a device based on the Locale of the device. For most cases this will be enough but for those cases where you would like to override the device language and region combination to a strict selection of languages, you can do so by invoking the following method:

import { updatePreferredLanguage } from 'notificare-web/core';

await updatePreferredLanguage('en-US');

Eventually, you can always retrieve the preferred language by calling the following method:

import { getPreferredLanguage } from 'notificare-web/core';

const preferredLanguage = getPreferredLanguage();