on() & off()
Subscribe to SDK lifecycle, placement, and user interaction events with on(), and remove handlers with off() or the unsubscribe function returned by on().
The event subscription API lets you react to what happens inside the Inline AI SDK: when the SDK initializes, when placements mount or unmount, and when users open or close the search overlay or widget. on() registers a handler for any named event and returns a function that unsubscribes it. off() provides an alternative way to unsubscribe using the original handler reference.
Both methods work before init() is called, making them safe to use in hybrid mode or in the command queue before the SDK has fully loaded.
on(event, handler)
on(event: SDKEventName, handler: (...args: unknown[]) => void): () => voidSubscribes to a named SDK event. When the event fires, handler is called with event-specific payload data. The method returns an unsubscribe function; call it to stop listening without needing to keep a reference to the original handler.
Parameters
eventSDKEventNameRequiredThe event name to subscribe to. You can use raw string literals or constants from the Events enum; both are equivalent. See the events reference for the full catalog, payload shapes, and per-event examples.
handlerfunctionRequiredThe callback function to invoke when the event fires. The argument shape depends on the event; see the table above for each event's payload.
Return value
unsubscribe() => voidA function that, when called, removes this specific subscription. Equivalent to calling off(event, handler) with the same handler reference.
off(event, handler)
off(event: SDKEventName, handler: (...args: unknown[]) => void): voidUnsubscribes a previously registered handler. You must pass the same function reference that was passed to on(). Anonymous functions cannot be unsubscribed with off(), which is why on() also returns an unsubscribe function as a convenient alternative.
Parameters
eventSDKEventNameRequiredThe event name the handler was subscribed to.
handlerfunctionRequiredThe exact function reference that was passed to on(). If the reference does not match any registered handler, the call is silently ignored.
Examples
var unsubscribe = window.InlineAI.on('search:open', function(data) {
console.log(data.query);
});
// Stop listening later
unsubscribe();