Preinitialize the widget JavaScript object
Calling Invero's JavaScript functions, and listening to Invero events, requires
that the the global Invero object is initialized. Preinitialization lets you
call functions and listen to events immediately, regardless of the lifecycle
state of the Invero object. Calls invoked before the Invero object has loaded
are queued, and execute as soon as Invero has completed initialization.
Setup
To preinitialize the window.Invero object, copy and paste the JavaScript
snippet below inside a <script> tag on every page where you are currently
rendering the Website Widget.
(function () {
let k = window.Invero;
if (!k) {
let i = function () {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
window.Invero = i;
}
})();
We recommend putting this script as early as possible in the DOM, such as
within the page's <head> element:
<head>
<script>
(function () {
let k = window.Invero;
if (!k) {
let i = function () {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
window.Invero = i;
}
})();
</script>
</head>
Usage
The syntax for calling functions against a preinitialized Invero object is
slightly different to the regular function calls. For example, the regular
syntax for calling the open() function to open the Website Widget looks like
this:
window.Invero.open({ query: "how to get started" });
Whereas with a preinitialized object, you would call the function as follows:
window.Invero("open", { query: "how to get started" });