Implementing Web SDK v2

Implement version 2 of the Airship Web SDK.

The v2 Web SDK supports additional features not included in v1:

Removed Support and Known Issues

Before continuing, confirm that you do not use or require the following features of the v1 SDK, as support for them has been removed:

  • HTTP setups — This is also referred to as “secure bridge.” The v2 SDK requires HTTPS on all pages. We removed the registration page plugin, as it was only needed for these setups.
  • Multi-domain setups — This is where a single registration was shared across multiple domains or subdomains.
  • Safari versions older than 16 (APNs Safari) — Apple started supporting VAPID push in Safari 16 on macOS 13 and above, which was released October 2022.
  • AMP — We will continue to support Web configurations that previously had Accelerated Mobile Pages (AMP) enabled, but AMP is not supported for new configurations.

Additionally, APNs Safari registrations are not automatically migrated to VAPID. They must be re-registered using the sdk.register() method.

Integration

Follow the below instructions depending on whether you are performing a new Installation or upgrade.

Setting Up a New Integration

If you have not previously integrated the Airship Web SDK, follow these steps in the Web Getting Started guide:

Then proceed to Channel Registration below.

Updating an Existing Integration

 Important

The v2 SDK has an updated API which is incompatible with the previous version. An upgrade must be performed in a single release, you cannot partially upgrade.

Airship has not thoroughly tested downgrading from v2 to v1. It should be assumed that a downgrade is not possible once you have updated your production site to v2.

Follow these steps in the Web Getting Started guide to redownload your SDK bundle and replace your existing JavaScript snippets and service worker with the bundle’s updated contents:

Also follow our Developer Migration Guide, which instructs you on migrating your integration to the updated API.

Then proceed to Channel Registration below.

Channel Registration

To use the new features of the v2 Web SDK, you will need to register a channel for browsers that visit your web site. Channel registration no longer requires push notification opt-in. When you choose to do this will be up to your integration, but Airship recommends registering a channel only once a visitor is considered relevant to you.

 Note

Any visitor you choose to register will count toward your Monthly Unique Visitors. If your billing plan does not include Monthly Unique Visitors, you will be contacted by your Account Manager to update your subscription.

The following methods are relevant to channel registration:

  • UaSDK.create —  Create a channel without prompting for notification opt-in.
  • UaSDK.register —  Create a channel prompting for notification opt-in. If the user denies notification permissions, has previously denied it, or if the browser is in an unsupported context this method will throw an error, and not register a channel. See the example below for details on how to approach a push notification registration.
Registering a channel without notification opt-in
const sdk = await UA
const {channelId} = await sdk.create()
console.debug('registered channel with id:', channelId)

You may decide to register that channel for push notifications at a later date using the register() method, as usual. Note that if you are calling register() you do not need to also call create():

Requesting push notification opt-in
const sdk = await UA
if (sdk.isWebPushSupported && sdk.isAllowedPushRegistrationContext) {
  // prompt the user to install to their home screen so notification
  // registration may be requested.
} else if (await sdk.canRegister()) {
  const {channelId} = await sdk.register()
  console.debug('opted in push notifications for channel with id:', channelId)
}

Using the v2 SDK and Instrumenting Your Application

For detailed v2 SDK usage information, see the API Documentation.

To get the most out of the v2 SDK, we recommend instrumenting your website or web application to emit events for triggering and event segmentation. See Instrument your Application in the In-App Experiences documentation.