Push Notifications

Urban Airship's SDK provides a simple interface for managing web push notifications.

User Registration

A user is registered when they opt in to receiving notifications via the system dialog, which varies slightly from browser to browser. This is an example Chrome browser registration dialog:


The dialog is presented when the page invokes the sdk.register function. As a best practice, we discourage calling this function on page load, before the user has had a chance to assess the potential usefulness of notifications from your site. See Registration UI for a simple, sample UI element that registers a user.

In any case, this moment when a user decides whether to allow or block notifications is when we will either register a channel for them with an opt-in status, or not.

The SDK returns this registration event to Urban Airship, along with the user's registration status and certain metadata, namely device property tags. When you send a push notification to a web user, their registration status is returned to Urban Airship via the push service.

Registration Status

Note

Analytics must be enabled to determine registration status. See: Analytics and Reporting.

A user's registration status is one of:

  • Opted-in: Allowed notifications and has not subsequently disallowed them, either via browser settings or by calling the optOut() method.
  • Opted-out: Initially allowed notifications but subsequently disabled them.
  • Uninstalled: A user is considered to be Uninstalled if they have both:

    1. Opted out via the browser settings, AND
    2. Not returned to the website.


A user can change their opt in/out status in two places:

  1. The browser's settings.
  2. The website's registration UI.

Registration UI

You are responsible for providing a UI to register a user. While it is possible to call the registration on page load, we strongly discourage this behavior. If a user is immediately presented with a notification permission dialog without knowing what notifications to expect, chances are higher that they will decline, making it difficult to reengage with them in the future.

Consider requesting permission during a workflow that is germane to notifications, and, when possible, providing a utility to opt out (and back in) that doesn't involve digging into the browser settings.

Sample Registration UI
<button id="register">Sign up for notifications</button>
<script>
   document.getElementById('register').addEventListener('click', function(){
     UA.then(function(sdk) {
      sdk.register()
     })
   })
</script>