UaSDK

UaSDK

The main Web 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
Plugins

Members

dataCollectionEnabled :Promise.<boolean>

Enable data collection. Resolves to a boolean that is true when data collection is enabled.

Type:
  • Promise.<boolean>
Example
sdk.dataCollectionEnabled = true // setter
sdk.dataCollectionEnabled.then(enabled => enabled === true) // getter is asynchronous

disableAnalytics :Promise.<boolean>

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

Type:
  • Promise.<boolean>
Example
sdk.disableAnalytics = true // setter
sdk.disableAnalytics.then(disabled => disabled === true) // getter is asynchronous

Methods

getChannel()

Return the channel for the current user as soon as it is created (new registration) or loaded (existing registration).

Example
UA.then(sdk => {
 sdk.getChannel().then(channel => {
   console.log("Channel ID: %s", channel.id)
 })
})

(async) register() → {Promise.<UaSDK.Channel>}

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>
document.getElementByID('register').addEventListener('click', function () {
  return UA.then(sdk => sdk.register())
})
</script>
Fires:
Returns:
Type:
Promise.<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.detail Channel

The channel that changed

ev.channel Channel

The channel that changed (Deprecated, please use ev.detail)

Example
// NOTE: if you intend to set attributes, tags, named user, or anything that could modify
// the channel within your event listener, make sure to set the `once` option to `true` 
// in order to prevent an infinite loop.

  sdk.addEventListener('channel', ev => {
    ev.detail === sdk.channel
  }, { once: true })

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.detail TagList

The channel's tags list

ev.tags TagList

The channel's tags list (Deprecated, please use ev.detail)

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