init() & destroy()
Initialize Inline AI in programmatic mode with your publisher ID, and tear it down cleanly with destroy() when you need to reinitialize or navigate away.
Call init() to activate programmatic mode: the SDK skips auto-rendering and waits for you to mount() placements explicitly. After a successful call, the SDK emits the ready event and is ready to accept mount() calls. You can tear down the entire SDK at any time with destroy(), which unmounts all placements and resets state so you can call init() again if needed.
init(config)
init(config: SDKConfig): voidInitializes the SDK in programmatic mode. The SDK creates an API client, loads your publisher configuration, and emits 'ready' when setup is complete.
Parameters
configSDKConfigRequiredConfiguration object for the SDK.
Error behavior
init() never throws to your code. All internal errors are caught, logged to the console, and execution stops gracefully. Check the browser console for [SDK]-prefixed messages if initialization does not behave as expected.
Examples
window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
window.InlineAI.on('ready', function() {
window.InlineAI.mount(window.InlineAI.Placement.SearchEmbed, 'header-search');
window.InlineAI.mount(window.InlineAI.Placement.Widget);
});destroy()
destroy(): voidTears down the SDK: unmounts all SDK-controlled placements, removes internal event listeners, and resets the initialized state. After calling destroy(), you can call init() again to start fresh.
In hybrid mode (where auto mode initialized the widget), destroy() only removes placements and listeners that were added through the SDK API. It does not tear down the shared auto-mode registry or affect placements rendered automatically by the widget.
When to use destroy()
- Single-page applications: call
destroy()when navigating to a new route, theninit()again with updated configuration. - Reinitializing with different options: you cannot call
init()twice in a row; calldestroy()first. - Cleanup on page unload: remove all Inline AI UI before the page tears down.
Example
// Initialize and mount
window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
window.InlineAI.on('ready', function() {
window.InlineAI.mount(window.InlineAI.Placement.SearchEmbed, 'search-box');
});
// Later: tear down and reinitialize
window.InlineAI.destroy();
window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
window.InlineAI.on('ready', function() {
window.InlineAI.mount(window.InlineAI.Placement.BasicEmbed, 'new-container');
});