Register Visitors


Your website visitors need to be uniquely identified to receive push notifications.

Every visitor is assigned a unique device token that you can use to push it at any given time. Once the visitor has been assigned a device token, it should be stored in your application's backend database.

Device Registration

Add the following code to register the visitor's browser for push notifications, making sure to populate the appId variable with your Pushy App ID (Pushy Dashboard -> Click your app -> App Settings -> App ID):

// Register visitor's browser for push notifications
Pushy.register({ appId: 'your-app-id' }).then(function (deviceToken) {
    // Print device token to console
    console.log('Pushy device token: ' + deviceToken);

    // Send the token to your backend server via an HTTP GET request
    //fetch('https://your.api.hostname/register/device?token=' + deviceToken);

    // Succeeded, optionally do something to alert the user
}).catch(function (err) {
    // Handle registration errors
    console.error(err);
});

Note: Registration will fail if the user declines the Web Push permission dialog, in which case notification preferences for your hostname must be cleared in the browser settings for the dialog to be displayed again:

  • Firefox: Enter about:preferences#content in the address bar
  • Chrome: Enter chrome://settings/content/notifications in the address bar