Skip to Content
PlatformsWebAPI Reference

API Reference

Web ships two distinct API surfaces — see the SDK overview if you haven’t already. Signatures differ between them, most importantly on init, track, identify, and logout.

Loader (onesygnal-web-sdk, npm)

Source: packages/web-sdk/src/loader/index.ts.

MethodSignatureNotes
init(apiKey: string, options?) => voidReturns void, not a Promise. Injects the bundle <script> and queues calls until it’s ready.
track(eventName: string, properties?) => anyForwards the bundle’s return value once ready; undefined before that — nothing to forward yet.
identify(userId: string, attributes?) => anySame pre-ready caveat as track.
logout() => anySame pre-ready caveat.
setSurveysEnabled(enabled: boolean) => voidQueued if called before ready.
areSurveysEnabled() => boolean | undefinedA read, not a write — there’s no future moment to “apply” it against, so a pre-ready call returns undefined rather than being queued.
isInitialized() => booleanfalse until the bundle is loaded and ready.
on(event: string, callback: Function) => anyReturns a Registration once ready, undefined if called before then (the registration doesn’t exist yet to hand back).
off(event: string, callback: Function) => void
flush() => any
shutdown() => any

A pre-ready call is queued and replayed against the bundle once it loads — except reads (areSurveysEnabled), which have nothing to queue against and answer undefined immediately. This is the honest answer for “no bundle yet,” not a bug.

CDN bundle (https://sdk.1sygnal.app/js/onesygnal.js)

Source: packages/web-sdk/src/bundle/index.ts, src/bundle/core/sdk.ts.

MethodSignatureNotes
init(apiKey: string, options?: InitOptions) => Promise<void>Throws if apiKey or options.apiUrl is missing.
track(eventName: string, properties?) => Promise<void>Not boolean — the contract fixtures record returns: "bool" as cross-platform intent, not web’s actual signature.
identify(userId: string, attributes?) => Promise<void>
logout() => Promise<void>
setSurveysEnabled(enabled: boolean) => void
areSurveysEnabled() => boolean
isInitialized() => boolean
on(event: string, callback: (data) => void) => RegistrationRegistration.cancel() unsubscribes.
off(event: string, callback) => voidSecond unsubscribe mechanism — matches by callback reference, first-found.
flush() => Promise<void>Forces pending events/responses to send immediately. Web-only — Android/iOS expose no manual-flush hook (their periodic timers are internal).
shutdown() => voidFlushes pending events, tears down timers/listeners, marks uninitialized.

Not public

  • emit(event, data): void — internal dispatch primitive (@internal), never exposed via publicAPI or the loader. Forging SDK events isn’t a supported capability.
  • 8 get*() accessors (getStorage, getUserManager, getEventTracker, getConfigFetcher, getResponseFlusher, getErrorReporter, getOptions, getNativeTriggerCheck) and resetForTesting() — test/internal-only, not part of the integrator-facing surface.

See Platform Parity for what exists on every platform.