Airship Web SDK

Resources

Installation

The SDK provides an asynchronous loading snippet that allows use of the SDK before it loads. You can get your snippet from the platform setup page for your project on Airship.

<script type="text/javascript">
!function(n,t,c,e,u){function r(n){try{f=n(u)}catch(t){return h=t,void i(p,t)}i(s,f)}function i(n,t){for(var c=0;c<n.length;c++)d(n[c],t);
}function o(n,t){return h?(d(t,h),l):f?(d(n,f),l):(n&&s.push(n),t&&p.push(t),l)}function a(n){return o(!1,n)}function d(t,c){
n.setTimeout(function(){t(c)},0)}var f,h,s=[],p=[],l={then:o,"catch":a,_setup:r};n[e]=l;var v=t.createElement("script");
v.src=c,v.async=!0,v.id="_uasdk",v.rel=e,t.head.appendChild(v)}(window,document,'https://aswpsdkus.com/notify/v1/ua-sdk.min.js',
  'UA', // This value can be changed to use a custom variable name.
  {
  appKey: 'YOUR-APP-KEY',
  vapidPublicKey: 'WEB-PUSH-KEY-FROM-UA',
  token: 'BEARERTOKEN-FROM-UA',

  // Has no effect on secure domains. Only needed if used on an insecure domain.
  secureIframeUrl: 'https://your.secure.domain/path/to/web-push-secure-bridge.html'
  })
</script>

This adds a a UA object to the global scope. This object provides promise-like then and catch functions. They can be called as many times as you'd like and can be chained like promises.

UA.then(cb) Takes a callback function that is called with sdk as its only argument. It is only called if the sdk loads successfully and the browser supports all features. All other features of the SDK can be used from here.

UA.catch(cb) Takes a callback function that is called with the error object as its only argument. It is only called if the SDK encounters an error while loading or the browser is unsupported.

UA.then(function(sdk) {
  console.log(sdk.channel.id)
}).catch(function(err) {
  console.log(err)
})

// Multiple calls have no additional expense.
UA.then(function(sdk) {
  $('#register').show()
  $('#register').click(function(ev) { sdk.register() })
})

NOTE: UA.then will only be called when the SDK has been loaded and if the browser supports the SDK's features. Do not rely on it being called in every browser. Because of this it is good practice to not enable UA SDK-specific parts of your UI until the SDK has loaded.

Unsupported browsers will call .catch(), which likewise will only be called if loading the SDK has an error.

Optional settings

Special case settings that can be added to both the snippet and the push-worker configuration if needed.

workerUrl: '/push-worker.js'

Has a default of /push-worker.js. It should always live at the root of your domain. It only needs to be specified if your worker lives at a different path.

disableAnalytics: false

Has a default of false. If true it will disable analytic reporting for your entire install. Features that depend on analytics being enabled may not work properly if it’s disabled.