Skip to main content

Browser SDK API Reference

Auto-generated from TypeDoc annotations in @hoberhq/browser-sdk. All methods are available on the default Hober export.

Hober.init(options)

Initializes the SDK. Must be called before any other method.

Signature

Hober.init(options: HoberInitOptions): void

Parameters

ParameterTypeRequiredDescription
options.sdkKeystringYesYour Hober SDK key from the dashboard.
options.serviceWorkerPathstringNoPath to hober-sw.js. Defaults to "/hober-sw.js".
options.baseUrlstringNoOverride the Hober API base URL (e.g. for staging).

Returns: void

Throws: HoberError if sdkKey is empty or options is not provided.


Hober.requestPermission()

Requests the Notification permission from the browser. Returns Promise<boolean>.

Signature

Hober.requestPermission(): Promise<boolean>

Returns: Promise<boolean> — resolves to true if the user grants permission, false if denied or dismissed.

Throws: HoberError if the SDK has not been initialized.


Hober.identifySubscriber(subscriber)

Associates the current user with a Hober subscriber record by calling POST /v1/subscribers/upsert.

Signature

Hober.identifySubscriber(subscriber: HoberSubscriberOptions): Promise<void>

Parameters

ParameterTypeRequiredDescription
subscriber.externalIdstringYesYour application's user identifier.
subscriber.emailstringNoSubscriber email address.
subscriber.attributesRecord<string, string | number | boolean>NoAdditional subscriber attributes.

Returns: Promise<void>

Throws: HoberError if externalId is empty or the API returns a non-2xx response.


Hober.registerDevice()

Registers the current browser as a push-enabled device by subscribing to the Web Push service and calling POST /v1/devices.

Signature

Hober.registerDevice(): Promise<void>

Returns: Promise<void>

Throws: HoberError if the SDK has not been initialized, if the service worker is not registered, or the API returns a non-2xx response.


Types

HoberInitOptions

interface HoberInitOptions {
sdkKey: string;
serviceWorkerPath?: string;
baseUrl?: string;
}

HoberSubscriberOptions

interface HoberSubscriberOptions {
externalId: string;
email?: string;
attributes?: Record<string, string | number | boolean>;
}

HoberError

class HoberError extends Error {
code: string;
}

See Also