Event emitted if the API initialization fails.
It usually makes sense to use this event if there is some general action that has to be triggered when the API initialization fails, but there are several places in the integration code that may trigger the initialization.
In most cases however, it is better to use
unblu.api.initialize().catch(error=> { //handle error here });
or
try{
let api = await unblu.api.initialize();
}catch(e){
// handle error here
}
Event emitted as soon as the API is initialized.
It usually makes sense to use this event if there is some general action that has to be triggered when the API is initialized, but there are several places in the integration code that may trigger the initialization.
In most cases however, it is better to use
unblu.api.initialize().then(api => { //use api here });
or
let api = await unblu.api.initialize();
// use api here
Configures the way that Unblu should be initialized.
The configuration of the Unblu API is needed when, and only when no Unblu snippet is already present in the website.
Note:
The configuration to be set.
an instance of this
allowing chaining like unblu.api.configure({...}).initialize();
Returns the current state of the API
the current API state.
Initializes the API and resolves to the fully initialized API.
If the API has already been initialized or is already in the initializing process, the existing API will be returned. There is only ever one instance of the API which will be returned by any call of this method which makes it safe to call this multiple times.
The initialization may fail with a UnbluApiError for the following reasons
Checks whether the API has to be configured or not.
true
if a configuration is needed to initialize the API, false
otherwise.
Checks whether the API is initialized or not.
true
if the API is initialized, false
for any other state.
Removes a previously registered listener.
The event unregister.
The listener to be removed.
true
if the listener was removed, false
otherwise.
Registers an event listener for the given event.
Note If the API is already initialized, this listener will be called directly.
The ready event
The listener to be called.
Registers an event listener for the given event.
Note If the API has already failed, this listener will be called directly.
The error event
The listener to be called.
The central entry point that allows to configure an initialize the Unblu Visitor JS API.
The static Unblu API works without actually loading the rest of Unblu. It can do some general checks and load Unblu or connect the API to a loaded version of Unblu. The JS API is an optional add-on to the Unblu visitor site integration.
Depending on how Unblu is integrated into the local website the API has to be initialized differently.
a.) API-only integration If no unblu-snippet is loaded into the page, Unblu can be fully initialized with the API. In this case, both the
configure
and theinitialize
methods have to be called. Example:const api = await unblu.api // configure the unblu server .configure({ apiKey: "<your-api-key>", serverUrl: "<unblu-server-url>" }) // initialize the api. .initialize();
This implementation will load the Unblu snippet and initialize both Unblu and the JS API.
b.) Snippet and JS API integration If the Unblu snippet is already present in the local website, Unblu doesn't have to be loaded and only the API has to be initialized. Example:
// directly initialize the api without configuring. const api = await unblu.api.initialize();