Skip to main content

Browser SDK reference

A reference for the Browser SDK (window.sdk): how to offer a PWA install from the page, subscribe the visitor to push, send events, and what settings that needs. For a general introduction, see Browser SDK; to connect it to your own prelanding, see SDK on your prelanding.

The window.pwaConfig settings​

The SDK reads its settings from the window.pwaConfig object, which you set on the page before the script is connected. On a PWA storefront the object is filled in automatically. The server doesn't fill in this object on the pages of a website uploaded to Qubix: there the SDK takes the offer, the PWA and the campaign from the cookie the server sets on a campaign click. On your own prelanding you set the object yourself.

FieldPurpose
pwaIdThe PWA identifier. Required for install and for push
domainThe page's domain. Required for the manifest and for push
vapidKeyThe key for push. Usually inlined automatically when /sdk.js loads — no need to set it by hand
offerIdThe offer (if you need to pass it explicitly)
campaignIdThe campaign (if you need to pass it explicitly)
paramsExtra tracking tags
previewModePreview mode: events are not sent

The PWA identifier (pwaId) is taken from the app card in the PWA Apps section.

Subscribe to push​

sdk.subscribePush() asks the browser for notification permission and creates a subscription. You must call it explicitly — for example, on a button click. It does not fire on its own.

JavaScript
const subscription = await sdk.subscribePush()
if (subscription) {
// the visitor allowed notifications and is subscribed
}

What happens inside:

  1. The browser's permission prompt is shown.
  2. If the visitor allows it, a subscription is created and sent to Qubix.
  3. Repeat calls are safe: if the visitor is already subscribed, the prompt is not shown again.

Installing the app is not required for push — a visitor can subscribe on an ordinary page.

note

Push works only over a secure connection (HTTPS) and on a domain that is set up in Qubix. More on this in SDK on your prelanding.

Install the PWA​

If window.pwaConfig has a pwaId, the SDK exposes the sdk.pwa methods:

MethodWhat it does
sdk.pwa.init()Preparation: registers the service worker and attaches the app manifest
sdk.pwa.install()Shows the system app-install prompt
sdk.pwa.canInstall()Whether install is available right now
sdk.pwa.isInstalled()Whether the app is already installed
sdk.pwa.open()Open the installed app

init, install, and isInstalled are asynchronous — call them with await. canInstall and open return a value immediately.

JavaScript
if (sdk.pwa && sdk.pwa.canInstall()) {
await sdk.pwa.install()
}

The install prompt is shown by the browser itself, so its rules apply: HTTPS, an attached manifest (the SDK attaches it for you), and usually an action by the visitor on the page (a click, a scroll). That is why the install button is normally tied to an explicit tap.

Events​

The SDK reports key moments to analytics on its own — they are visible in reports and in the event stream:

EventWhen
campaign_visitA visit to the page — counted by itself on a PWA storefront and on a site uploaded to Qubix with the Track events switch on; on your own site call sdk.track()
interactionA click or a form step — when visits on the page are counted
push_prompt_shownThe push permission prompt was shown
push_allowThe visitor allowed push
push_denyThe visitor denied push
push_ignoredThe visitor ignored the prompt and made no choice
install_acceptedThe visitor agreed to install the app
install_rejectedThe visitor declined the install

You can send your own event manually:

JavaScript
sdk.sendEvent('my_button_click', { place: 'hero' })

Traffic data​

Helper methods to read the click context:

MethodReturns
sdk.getOffer()The current offer (id and URL)
sdk.getPwa()The current PWA
sdk.getPiuid()The visitor id
sdk.getTrackingParams()The tracker tags that came with the click
sdk.buildOfferUrl(url)Build an offer URL with the tags carried over
sdk.showStore()Go to the PWA store card

What the SDK does on its own​

The short answer: on a page Qubix serves, nothing that you'd have to trigger.

  • The visit (campaign_visit) is counted by itself on a PWA storefront and on a site uploaded to Qubix with the Track events switch on; on such a site clicks and forms (interaction) are counted too, and your own sdk.sendEvent('campaign_visit') on the page is absorbed rather than counted a second time.
  • On a website hosted elsewhere, connected with the code from the Connect the landing page block of its card, the data-site attribute of the tag does this by itself: a page opened not from another page of the same website counts a visit, the following pages continue it, and clicks and forms are counted on every page. The library sends the events to the domain it was loaded from — see Connecting a landing page hosted elsewhere.
  • On your own site call sdk.track() on the page visitors land on from an ad, once it has loaded: it counts the visit and starts counting clicks and forms on that page. Called on further pages, it counts each of them as a visit of its own. The library does not read field values or element texts; but a form sent with the GET method puts its values into the address of the page it opens, and a visit counted there carries that address.
  • Preparing the install (sdk.pwa.init()), the install itself, the push subscription, your own events — all start from explicit calls in your code.

What's next​