# Push Notifications for the Web SDK

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.
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](#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 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 Airship via the push service.

### Registration Status

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()](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.Channel.html#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**
   1. Not returned to the website.

<!--
The definition above is also in dashboard/engage-reports.md#web-browsers. If you change it here, change it there.
-->

> **Note:** Analytics must be enabled to determine registration status. See:
> [Analytics and Reporting](https://www.airship.com/docs/developer/sdk-integration/web/analytics-and-reporting/).


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

1. The browser's settings.
1. The website's [registration UI](#registration-ui).


### Registration UI {#registration-ui}

If a user is immediately presented with a notification permission dialog without knowing what sort of notifications to expect from your site, chances are higher that they will decline,
making it difficult to re-engage with them in the future.

It is a best practice to explain the value of your notifications before displaying the system notification opt-in prompt.

We provide [plugins](https://www.airship.com/docs/developer/sdk-integration/web/plugins/) in the SDK to help you customize this initial prompt, however Web [Scenes](https://www.airship.com/docs/reference/glossary/#scene) are the preferred method for opt-in prompting.

> **Note:** Most web browsers require a notification opt-in to occur in response to a user
> action, meaning calling the SDK's `register()` method outside of an interaction
> handler will result in the request being rejected without a dialog being
> presented to the user.

