# Web Integrate the Airship SDK into your website or web application. # Getting Started > This is a developer's guide for setting up Airship web push notifications and Scenes.Set up your project to register users for [Web Push Notifications](https://www.airship.com/docs/reference/glossary/#web_push_notification) and Web [Scenes](https://www.airship.com/docs/reference/glossary/#scene). Both are referred to generally as "notifications" and "web notifications" on this page. Airship supports web push notifications and Scenes on:
Also be sure to select the **My Certificates** category in the sidebar. If **My Certificates** is not highlighted, you will not be able to export the certificate as a .p12 file. 1.  Save the file in the Personal Information Exchange (.p12) format.
You will be prompted to create a certificate password, which you will enter when you upload the .p12 file in the Airship dashboard. Now you can upload the .p12 file and provide the password when [configuring the Web channel in the Airship dashboard](#airship-setup). # Implementing Web SDK v2 > Implement version 2 of the Airship Web SDK.The v2 Web SDK supports features not included in v1: * Web [Scenes](https://www.airship.com/docs/reference/glossary/#scene), including survey questions and Story format * Registering browsers without Push Notification Opt-in ## 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: * [Airship Setup](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#airship-setup) * [Add JavaScript Snippet to Web Pages](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#add-javascript-snippet-to-web-pages) * [Place Service Worker](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#place-service-worker) Then proceed to [Channel Registration](#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: * [Airship Setup](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#airship-setup) * [Add JavaScript Snippet to Web Pages](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#add-javascript-snippet-to-web-pages) * [Place Service Worker](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#place-service-worker) Also follow our [Developer Migration Guide](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/tutorial-v1-to-v2-migration.html) , 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](https://www.airship.com/docs/reference/billing/#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](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#create) — Create a channel without prompting for notification opt-in. * [UaSDK.register](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#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** ```js 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** ```js 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](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/index.html) . 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](https://www.airship.com/docs/developer/sdk-integration/web/in-app-experiences/#instrumenting-your-application) in the *In-App Experiences* documentation. ## Custom Domain Proxy If you intend to use Web [Scenes](https://www.airship.com/docs/reference/glossary/#scene), you should send Airship traffic through your own domain in order to provide a consistent brand experience and avoid blocked content. See [Custom Domain Proxy](https://www.airship.com/docs/guides/getting-started/developers/custom-domain-proxy/). # In-App Experiences > Instrument your website or web application for in-app experiences. {{< badge_sdk_min web="2+" >}}The Airship Web SDK v2 supports [Scenes](https://www.airship.com/docs/reference/glossary/#scene), including [Embedded Content](https://www.airship.com/docs/developer/sdk-integration/web/embedded/). See also [Implementing Web SDK v2 ](https://www.airship.com/docs/developer/sdk-integration/web/v2-sdk/). ## Instrumenting your Application In order for Scenes to function, you must [Create a channel](https://www.airship.com/docs/developer/sdk-integration/web/getting-started/#creating-a-channel). This will count the current browser toward your [Monthly Unique Visitors](https://www.airship.com/docs/reference/billing/#monthly-unique-visitors). To get the most out of Scenes, instrument your website or web application to emit events for triggering and event segmentation. The following sections describe the events and provide code samples. See also: * [In-App Experience Triggers](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/triggers/) * [Event segmentation](https://www.airship.com/docs/developer/rest-api/ua/schemas/event-segmentation/) in our API reference ### Custom Events [Custom Events](https://www.airship.com/docs/reference/glossary/#custom_event) can be used to track any interaction you wish, for example a purchase or a product view. **Sending a Custom Event** ```js const sdk = await UA const evt = new sdk.CustomEvent('purchase', 34.5, {productId: 1337}) await evt.track() ``` ### Screen View Events Tracking App Screens can make it easy to trigger a Scene or to ensure a Scene is only displayed when currently on a given screen. You must [define App Screens](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/app-screens/) in the Airship dashboard. In the context of a website or web application, you can think of a "screen" as a page with a general purpose. For example, `home`, `product_listing`, and `product_detail` are good generic screen names, whereas `product_id_18957` is too specific and unlikely to be generally useful for reporting or targeting. **Tracking a Screen View** ```js const sdk = await UA await sdk.analytics.trackScreen('home') ``` ### Feature Flag Interactions When using [Feature Flags](https://www.airship.com/docs/reference/glossary/#feature_flag), you should track when a user has interacted with the feature the flag controls. The interaction event is included in Feature Flag reporting and can also be used for triggering: **Tracking Interaction with a Flagged Feature** ```js const sdk = await UA const flag = await sdk.components.featureFlags.get('new_product_pages') // later, when the user interacts with the new product pages await sdk.components.featureFlags.trackInteraction(flag) ``` ### App Version Updates If you version your web app and wish to be able to target users who may have seen an earlier version of the app, when initializing the SDK, use the `appVersion` property set to your app's version number. This will be passed in your snippet as well as your push worker: **Setting your App Version** ```js ``` ## Controlling Scenes If Scenes are enabled for your project, they will display according to their trigger and conditions settings. You can control their display programmatically or disable them completely, if desired. ### Screen Sizes and Breakpoints When creating Scene [view styles](https://www.airship.com/docs/guides/features/messaging/scenes/scenes/#view-styles) in your project's default settings, you can [define alternative settings that apply to a Scene based on a device's screen size](https://www.airship.com/docs/guides/features/messaging/scenes/conditional-design-overrides/). These sizes are defined by screen width breakpoints in the SDK: * Small: Less than 1024px * Medium: Greater or equal to 1024px and less than 1920px * Large: 1920px and greater You can override the values by setting custom breakpoints that better match your web application. Pass the following options in your SDK initialization snippet: **Setting Screen Sizes** ```js components: { inAppAutomation: { displayBreakpoints: { // the size at which a screen will be considered "medium", in pixels; inclusive medium: 800, // the size at which a screen will be considered "large", in pixels; inclusive large: 1024 } } } ``` Anything smaller than "medium" is considered to be a "small" screen, so no value needs to be set for that breakpoint. If you set custom breakpoints, also add them to your project settings for more accurate device previews when creating Scenes. Follow the steps for [Setting Scene defaults](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/defaults/#scene-defaults) in *In-App Experience Defaults* and set Breakpoint values in a view style's Background settings. ### Disabling To permanently disable Scenes in the current browser, pass the following options in your SDK initialization snippet: **Disabling Scenes** ```js components: { inAppAutomation: { enabled: false } } ``` ### Pausing and Resuming Display You can choose to pause and resume Scene display. For example, you might wish to only disable showing new Scenes when opening a modal on your site or during a checkout flow. **Pausing and Resuming Scenes** ```js const sdk = await UA // pause display of scenes await sdk.components.inAppAutomation.setPaused(true) // get the paused status; resolves to a boolean value await sdk.components.inAppAutomation.isPaused() // resume display await sdk.components.inAppAutomation.setPaused(false) ``` By default, displays are not paused. If you'd like to start in a paused state so that you can manually unpause at a time of your choosing, pass the following configuration in your SDK initialization snippet: **Starting Scenes in Paused State** ```js components: { inAppAutomation: { startInPausedState: true } } ``` ### Display Interval The display interval controls the amount of time to wait before the manager can display the next triggered Scene. The default value is set to 0 milliseconds and can be adjusted to any amount of time in milliseconds. **Setting the Display Interval Programmatically** ```js await sdk.components.inAppAutomation.setDisplayInterval(30000) // 30 seconds ``` You can also set the display interval via your SDK initialization snippet: **Setting the Display Interval via Config** ```js components: { inAppAutomation: { displayIntervalMs: 30000 // 30 seconds } } ``` ### Delegating Display You can choose to implement your own display delegate, which can control if a Scene is allowed to be displayed. It can also be notified when a Scene is displayed or has finished displaying. Your display delegate must implement the `[InAppDisplayDelegate](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/InAppDisplayDelegate.html) ` interface. All methods are optional. > **Note:** When using a display delegate, we recommended that you [start display in a paused state](#pausing-and-resuming-display) and then unpause after setting your delegate. > Otherwise, it is not guaranteed your delegate will be registered before displays > occur. **Controlling Display using a Delegate** ```js const delegate = { isMessageReadyToDisplay: (message) => { if (myApp.canDisplayMessage(message)) { return true } return false } } await sdk.components.inAppAutomation.setDisplayDelegate(delegate) await sdk.components.inAppAutomation.setPaused(false) ``` If you need to pass additional information to your application, you can use [Custom Keys](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/optional-features/#custom-keys) when composing your Scene. They will be available on the `extras` property of the `[InAppAutomationDetails](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/global.html#InAppAutomationDetails) ` that are passed to your delegate. ### Dark Mode By default, Scenes follow the browser preferences for dark mode. This behavior can be disabled by a configuration value. When disabled, all displayed content will use the colors configured for light mode. **Disabling Automatic Dark Mode** ```js components: { inAppAutomation: { matchBrowserDarkMode: false } } ``` ## Custom Views A *Custom View* is a native view from your mobile or web application embedded into a Scene. Custom Views can display any native content your app exposes, so you can reuse that existing content within any screen in a Scene. For a web page, this means embedding an HTML view into a Scene. > **Note:** When using Custom Views, you should initialize In-App Experiences in a paused > state. If you do not, there's no guarantee that your Custom View delegate will > be registered by the time a Scene displays, and the Custom View would not be > shown. See the section on [Pausing and Resuming > Display](#pausing-and-resuming-display) for further information. ### Implementation To display Custom Views, you must implement the `[InAppCustomViewDelegate](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/InAppCustomViewDelegate.html) ` interface and register it using the `[setCustomViewDelegate](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/InAppAutomationManager.html#setCustomViewDelegate) ` method of the `[InAppAutomationManager](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/InAppAutomationManager.html) `. Only one delegate may be registered at a time. When it's time for a Custom View to be displayed, your delegate's `onCustomViewShown` method will be called with the following parameters: * `name` — The name of the Custom View, which is referenced when adding it to a Scene * `element` — The HTML element into which your Custom View should render * `properties` — Any additional properties set for your Custom View as a key/value object; all keys and values will be strings When called, your `onCustomViewShown` method must return an object that fulfills the `[InAppCustomViewHandler](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/InAppCustomViewHandler.html) ` interface. This will contain the `destroy` method, which will be called with no parameters when your view is to be removed. > **Important:** Your delegate should render synchronously into the provided `element`. If it > does not, you may cause the Scene's layout to shift after rendering. ### Example Custom View The following example shows a Custom View that renders an embedded [Google Map](https://developers.google.com/maps/documentation/embed/embedding-map) when called to render a Custom View named `map`. This example assumes that you have started In-App Experiences in a paused state, as recommended above. In our example, we pass `properties` to the view to determine the location the map should show. `q` is the query to pass to the map view. **Example Custom View rendering a map** ```js // a React Function Component for rendering an embedded Google Map const Map = ({ q }) => { return (