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();
isConfigurationNeeded to check if configuration is needed or not.
Returns the current state of the API
the current API state.
isInitialized for a simpler check
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.
getApiState for the full state
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.
Registers an event listener for the given event.
Note If the API is already deinitializing, this listener will be called directly.
The deinitializing event
The listener to be called.
Registers an event listener for the given event.
Note If the API is already deinitialized, this listener will be called directly.
The deinitialized event
The listener to be called.
Registers an event listener for the given event.
The state event
The listener to be called.
Static
Readonly
DEINITIALIZEDEvent emitted as soon as the API is completely de-initialized.
It usually makes sense to use this event to clean up resources and/or unregistering of listeners to no try to use the API again until it is initialized again.
deinitialized
on for listener registration
Static
Readonly
DEINITIALIZINGEvent emitted as soon as the API is going to get de-initialized.
It usually makes sense to use this event to clean up resources and/or unregistering of listeners to no try to use the API again until it is initialized again.
deinitializing
on for listener registration
Static
Readonly
ERROREvent 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
}
error
on for listener registration
Static
Readonly
READYEvent 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
Note: that this event will be triggered again after each initialization.
ready
on for listener registration
Static
Readonly
STATEEvent emitted whenever the API state changes
state
on for listener registration
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: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: