window.Kelu exists only once the widget script has loaded, and the script loads async. Code that runs earlier, such as analytics setup in your <head>, finds nothing to call.
A preinitialization stub fixes this. It defines window.Kelu as a function that queues every call. When the widget loads, it replaces the stub and runs the queue.
Setup
Put this on every page that has the widget, as early as possible, ideally in<head> before the widget’s own tag:
window.Kapa stub with the name changed. The widget reads only window.Kelu.
Usage
Call functions by name, with the argument after it:window.Kelu.open(), works only after.
When queued calls run
| Queued call | Runs |
|---|---|
Event subscriptions, such as Kelu("onModalOpen", fn) | As soon as the script loads, so no event is missed |
Functions: open, close, render, unmount, setSourceGroupIDs, getSourceGroupIDs | In the order you queued them, once the widget is configured: by the script tag’s attributes, or by your first KeluWidget.init() call |
- A queued
openwaits until the widget is on the page. - A queued
getSourceGroupIDshas nowhere to return its value. Call it after the script loads. - Any other name logs a warning.
window.KeluWidgetis not queued; it exists only after the script loads.
With See Widget lifecycle.
data-render-on-load="false", a queued open on its own does nothing, because nothing is on the page yet. Queue render with open in its onRender instead: