UaSDK

UaSDK

The main Web Notify SDK object. It can not be instantiated manually. It is returned by the async loader.

Constructor

new UaSDK()

Properties:
Name Type Attributes Description
sdk.channel UaSDK.Channel <nullable>

The channel object for the current browser if registered.

sdk.CustomEvent CustomEvent

The constructor to make custom events.

sdk.canRegister boolean

This is true if the browser isSupported and the page is secure and Notifications have not been blocked at the browser level

sdk.isSupported boolean

This is true if the browser has web push abilities.

sdk.permission string <nullable>

The browser permission state to display notifications.

Secure contexts return 'granted', 'denied', or 'default'.

Insecure contexts always return undefined.

Example
// You will always use this through the async loader
UA.then(function(sdk) {// use the sdk here})

Classes

Channel

Members

disableAnalytics :Promise

Disables analytics for this browser. Resolves to a boolean that is true if analytics are disabled.

Type:
  • Promise
Example
sdk.disableAnalytics = true
sdk.disableAnalytics.then(disabled => disabled === true)

Methods

register() → {Promise}

Register the current browser with Urban Airship

  • Fetch the browser's subscription object, prompting the user for permission if necessary.
  • Collect browser information for out of the box tag segmentation.
  • Register with Urban Airship and resolve the returned channel object.
  • Will opt a channel back in to push if it has opted out.

Resolves an error that can be caught if there is an error while registering or the browser is not a secure context. See sdk.canRegister

You are responsible for providing a UI to register a user.

<button id="register">Sign up for notifications</button>
<script>
  UA.then(function(sdk) {
    document.getElementByID('register').addEventListener('click', function () {
      sdk.register()
    })
  })
</script>
Fires:
Returns:
Type:
Promise

Resolves to UaSDK.Channel

Events

channel

The main SDK object fires a channel event when a channel is registered, loaded or changed.

Properties:
Name Type Description
ev.channel Channel

the channel that changed

Example
sdk.addEventListener('channel', ev => {
    ev.channel === sdk.channel
  })

push

If you are on an https page that is in-scope of your push-worker.js: The main SDK object fires a push event when the browser receives a push.

Properties:
Name Type Description
ev.push object

the push payload

Example
sdk.addEventListener('push', ev => {
    // ev.push is the push payload object
  })

tags

The main SDK object fires a tags event any time the tags change.

Properties:
Name Type Description
ev.tags TagList

the channel that changed

Example
sdk.addEventListener('tags', ev => {
    ev.tags === sdk.channel.tags.list
  })