@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 aNotifizzVanillaApi— callmount()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 withgetState(). - Replace the default bell with
setBellElement(el)— the SDK handles click + keeps adata-unreadattribute in sync.
Installation
createNotifizz(options)
Creates a new Notifizz instance. This is the entry point for the SDK.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | yes | — | Your Front API Key. |
authType | 'firebase' | 'backendToken' | 'none' | yes | — | Authentication strategy. |
token | string | for firebase, backendToken | — | Auth token from your backend. |
userId | string | for backendToken, none | — | The user’s unique identifier. |
userEmail | string | for backendToken, none | — | The user’s email address. |
position | NotifizzPosition | no | — | Bell position. |
notificationCenterStyles | { marginTop?: string } | no | — | Notification center style overrides. |
bellStyles | { marginRight?: string; marginLeft?: string } | no | — | Bell style overrides. |
serverUrl | string | no | https://widget.notifizz.com | Widget server URL. |
apiUrl | string | no | https://eu.api.notifizz.com/v1 | API base URL. |
widgetPath | string | no | /v1/widget.js | Widget script path. |
mountId | string | no | notifizz-notifications | DOM id for the mount point. |
NotifizzVanillaApi, the instance API described below.
authType: "none" example (dev only)
Instance methods
mount(element?)
Mounts the widget to the DOM. If no element is provided, creates a <div> and appends it to document.body.
| Parameter | Type | Required | Description |
|---|---|---|---|
element | HTMLElement | no | Target DOM element. Created automatically if omitted. |
HTMLElement, the mounted element.
getState()
Synchronous snapshot of the current widget state.
NotifizzState:
| Property | Type | Description |
|---|---|---|
isReady | boolean | true once the widget has loaded and authenticated. |
isOpen | boolean | true when the dropdown is open. |
unreadCount | number | Current unread count. |
lastUpdated | number | Timestamp (ms) of the last state change. |
hasError | boolean? | true if the widget hit an auth or network error. |
errorCode | string? | Error identifier when hasError is true. |
onReady(callback)
Registers a callback that fires when the widget is ready. If the widget is already ready, the callback fires immediately.
() => void, an unsubscribe function.
onStateChange(callback)
Registers a callback that fires on every state change.
() => void, an unsubscribe function.
onBellUpdate(callback)
Registers a callback that fires when the bell context updates (unread count, open state).
NotifizzBellContext:
| Property | Type | Description |
|---|---|---|
unreadCount | number | Current unread count. |
isOpen | boolean | Whether the dropdown is open. |
isReady | boolean | Whether the widget is ready. |
toggle | () => void | Toggle the dropdown. |
open | () => void | Open the dropdown. |
close | () => void | Close the dropdown. |
() => void, an unsubscribe function.
open() / close() / toggle()
Drive the dropdown programmatically.
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.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | null | The custom bell element. Pass null to remove. |
destroy()
Removes the widget from the DOM and cleans up all event listeners.
Full example
Exported types
FAQ
Can I use this SDK from Vue / Svelte / Solid / etc?
Can I use this SDK from Vue / Svelte / Solid / etc?
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.The widget mounted but the bell is not visible.
The widget mounted but the bell is not visible.
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.`getState()` returns `isReady: false` immediately after `createNotifizz`.
`getState()` returns `isReady: false` immediately after `createNotifizz`.
Expected —
createNotifizz() doesn’t load the script synchronously. Call mount() first, then either await onReady() or check state.isReady in onStateChange.My custom bell click does nothing.
My custom bell click does nothing.
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.Where do `onStateChange` callbacks get called from?
Where do `onStateChange` callbacks get called from?
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.How do I switch user?
How do I switch user?
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.