Skip to main content

@notifizz/vanilla SDK reference

@notifizz/vanilla is the framework-agnostic SDK for the Notifizz Notification Center widget. Use it from plain JavaScript, Vue, Svelte, server-rendered pages with islands, or any setup that isn’t already covered by @notifizz/react or @notifizz/angular.

TL;DR

  • createNotifizz(options) returns a NotifizzVanillaApi — call mount() to attach the bell to the DOM.
  • Three auth modes via authType: 'firebase', 'backendToken', 'none' (dev-only).
  • Subscribe to changes with onStateChange(cb); read state synchronously with getState().
  • Replace the default bell with setBellElement(el) — the SDK handles click + keeps a data-unread attribute in sync.
  • Web push opt-in is headless: webpushOptIn() / webpushOptOut() plus getWebPushStatus() let you own the button.

Installation

createNotifizz(options)

Creates a new Notifizz instance. This is the entry point for the SDK.

Options

ReturnsNotifizzVanillaApi, the instance API described below.

authType: "none" example (dev only)

authType: "none" ships unauthenticated widget access — anyone with the apiKey can read any user’s inbox. Use it for local development only. Production must use firebase or backendToken.

Instance methods

mount(element?)

Mounts the widget to the DOM. If no element is provided, creates a <div> and appends it to document.body.
ReturnsHTMLElement, the mounted element.

getState()

Synchronous snapshot of the current widget state.
ReturnsNotifizzState:

onReady(callback)

Registers a callback that fires when the widget is ready. If the widget is already ready, the callback fires immediately.
Returns() => void, an unsubscribe function.

onStateChange(callback)

Registers a callback that fires on every state change.
Returns() => void, an unsubscribe function.

onBellUpdate(callback)

Registers a callback that fires when the bell context updates (unread count, open state).
The callback receives a NotifizzBellContext: Returns() => void, an unsubscribe function.

open() / close() / toggle()

Drive the dropdown programmatically.

Web push opt-in

Closed beta. Web push is enabled per organisation and is off by default. Until it is switched on for yours, no campaign can take a push step — so an opt-in collected here would have nothing to deliver. Ask your Notifizz contact to switch it on. Campaigns that already carry a push step keep sending either way.
Three members drive the browser subscription without any Notifizz UI — you own the button and its timing.
The status starts at unavailable and settles once the widget has booted web push for the signed-in user, so read it from onStateChange (or onBellUpdate) rather than once at mount time. Full channel behaviour is in web push.

setBellElement(element)

Sets a custom HTML element as the bell. The SDK adds a click listener that toggles the dropdown and keeps a data-unread attribute in sync with the current count.

destroy()

Removes the widget from the DOM and cleans up all event listeners.
destroy() is one-way — you cannot reuse the instance afterwards. Call createNotifizz(...) again for a fresh instance.

Full example

Exported types

FAQ

Yes — the vanilla SDK is framework-agnostic by design. Mount the widget in the framework’s lifecycle hook (onMounted, onMount, useEffect-equivalent) and destroy() in the teardown. The state callbacks plug into any reactive store.
Three things to check: (1) mount() was called and returned a non-null element; (2) the page hasn’t hidden the mount point with global CSS (#notifizz-notifications { display: none }); (3) state.isReady === true — the bell renders only after auth succeeds, and a failure flips hasError instead.
Expected — createNotifizz() doesn’t load the script synchronously. Call mount() first, then either await onReady() or check state.isReady in onStateChange.
setBellElement(el) overrides the default bell. If you registered your own click handler before calling it, the SDK still adds its listener — but your handler may stop the event with preventDefault / stopPropagation. Either rely on the SDK’s click handler, or attach yours after setBellElement and don’t stop propagation.
The widget posts state changes via the notifizz:state window event. The SDK subscribes to that event once and fans out to your callbacks — there is no polling. State changes happen on the client, off the real-time stream listener.
Call destroy() on the current instance, then createNotifizz(...) with the new userId + token, then mount(). The widget caches real-time state per session, so without destroy the new mount briefly shows the previous user’s notifications.

See also

Notification Center overview

Lifecycle, state model, positioning, custom bell.

Authentication overview

Pick the right widget auth mode.

Frontend quickstart

Get the widget rendering in under five minutes.

Backend quickstart

Send the events the widget will display.