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/v2/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',
  })
</script>

This adds a a UA object to the global scope. This object is a promise that resolves to the UaSDK object. If available in your environment, Airship recommends using async/await syntax:

const sdk = await UA
// now you may use the SDK as documented
await sdk.contact.editAttributes()
  .set('first_name', 'Guy')
  .apply()

NOTE: UA will only resolve 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. The promise will reject in cases that the SDK was unable to load due to 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.