Widget

How to integrate and customize the IKIbrain widget on your site.

Basic Embed

To add the IKIbrain chat widget to your website, paste the embed code before the closing </body> tag. You can find the embed code in the bot dashboard.

<script>
(function(){
  d=document;s=d.createElement("script");
  s.src="https://cdn.ikibrain.ai/widget/yourbotname.js";
  s.async=1;
  d.getElementsByTagName("head")[0].appendChild(s);
})();
</script>

The widget loads automatically and shows a floating chat icon in the corner of the page. Users click it to open the chat window.

Hide Launcher

If you want to control when and how the chat opens (e.g. only from custom buttons), you can hide the default floating icon.

Add the IKIbrainConfig object before the embed script:

<script>
window.IKIbrainConfig = { hideLauncher: true };
</script>
<!-- embed code here -->

When the launcher is hidden, the chat can only be opened programmatically via the JavaScript API described below.

Multilingual Sites

If the bot is configured for multiple languages, the widget normally shows a language selection screen when the user opens it. On a multilingual website, you already know which language the user is browsing in — you can skip that screen by passing lang in IKIbrainConfig:

<script>
window.IKIbrainConfig = { lang: 'it' };
</script>
<!-- embed code here -->

The widget will open directly in the specified language, skipping the selection panel entirely.

How to set the language dynamically

On a site where the language comes from a PHP variable, a data- attribute, or a JS constant, pass it inline:

<!-- PHP example -->
<script>
window.IKIbrainConfig = { lang: '<?= htmlspecialchars($currentLang) ?>' };
</script>

<!-- JavaScript example -->
<script>
window.IKIbrainConfig = { lang: document.documentElement.lang || 'en' };
</script>

Supported language codes

CodeLanguage
itItalian
enEnglish
deGerman
frFrench
esSpanish
ptPortuguese
nlDutch
zhChinese
jaJapanese
arArabic
If the code passed is not among the languages enabled for that bot, the parameter is ignored and the language selection screen is shown normally.

Open / Close

You can open or close the chat window programmatically:

// Open the chat window
IKIbrainWidget.openChat();

// Close the chat window
IKIbrainWidget.closeChat();

Example with a custom button:

<button onclick="IKIbrainWidget.openChat()">
  Chat with us
</button>

Auto Open

By default the widget loads closed and the user clicks the launcher to open the chat. With autoOpen you can show the chat already open when the page loads. Like the other options, it must be defined in IKIbrainConfig before the embed script:

<script>
window.IKIbrainConfig = { autoOpen: true };
</script>
<!-- embed code here -->

On mobile the open chat takes over the full screen, which can feel intrusive on first load. If you prefer auto-opening on desktop only, use the 'desktop' value:

<script>
window.IKIbrainConfig = { autoOpen: 'desktop' };
</script>
<!-- embed code here -->

Supported values

ValueBehavior
trueThe chat opens automatically on all devices.
'desktop'The chat opens automatically only on viewports wider than 480px; on mobile it stays closed.
Auto-open respects the user's choice: if the user closes the chat, the widget stays closed on subsequent pages and is not reopened. Opening goes through the normal widget flow (privacy notice, language selection, OTP for private bots, pre-chat form), exactly like a manual open.

Chat Position

By default the chat window opens at the bottom of the page (right, left or — with the bar launcher — centered, depending on the bot configuration). If you hid the launcher to use your own icon somewhere else on the page, chatPosition lets you open the panel next to it:

<script>
window.IKIbrainConfig = {
  hideLauncher: true,
  chatPosition: { bottom: '96px', left: '24px' }
};
</script>
<!-- embed code here -->

Supported properties

PropertyDescription
top / bottomDistance from the top or bottom edge of the window. Use only one of the two.
left / rightDistance from the left or right edge of the window. Use only one of the two.

Values accept the most common CSS units (px, %, rem, em, vh, vw) or plain numbers, interpreted as pixels. Invalid values are ignored. If you specify only one axis, the other keeps its default.

The opening animation adapts automatically to the chosen position: with a bottom anchor the panel slides up from below, with top it slides down from above, and the effect origin follows the side (left or right) it is anchored to.

On mobile (viewports up to 480px) the chat always opens full-screen: chatPosition is ignored. The panel is anchored to the browser window (position: fixed), so pick offsets consistent with a floating icon.

Page Context

Page context lets the bot know which page the user is on and what that page is about. It is a global context: once enabled, it is inherited automatically by every message in the session, so you don't have to repeat it on each button.

Enabling it

Page context is not active by default: this means the bot doesn't know which page the user is on. To turn it on you have to enable it explicitly, by defining window.IKIbrainConfig with a pageContext key before the embed script:

<script>
  window.IKIbrainConfig = { pageContext: {} };   // ← this is the line that turns it on
</script>
<!-- embed code here -->
Even an empty pageContext ({}) is enough to turn on the feature: the widget auto-populates url and title from the current page.

Supported values

You can also set the pageContext fields manually:

FieldDescription
urlOptional. If omitted, window.location.href is used automatically.
titleOptional. If omitted, document.title is used automatically.
descriptionDescription of the page content (product name, service, category, etc.). The most useful field to tell the bot what the user is actually looking at.
<script>
  window.IKIbrainConfig = {
    pageContext: {
      url: 'https://www.example.com/chairs/xr-500',
      title: 'Ergonomic Chair XR-500',
      description: 'Ergonomic Chair XR-500 - Office Seating, adjustable backrest, 5-year warranty'
    }
  };
</script>
<!-- embed code here -->

In most cases description is all you need: url and title are detected automatically from the current page.

This data helps the bot answer better in two ways:

  1. it helps interpret the user's contextual questions — e.g. "what material is it made of?" — which without context would have no clear subject;
  2. it lets the bot know which page the user is looking at and, when needed, tailor its answer accordingly.

Updating the context on SPA sites

SPA stands for Single Page Application: a type of site (typically built with React, Vue, Angular, Next.js, Svelte, etc.) where navigation between pages happens without a browser reload. The URL changes and the content is swapped via JavaScript, but the widget script stays loaded for the whole visit.

This means the pageContext defined in IKIbrainConfig is read only once, when the site opens, and does not automatically update on route changes. To update the context when the user navigates, call IKIbrainWidget.setPageContext():

// On route change
router.afterEach(function (to) {
  IKIbrainWidget.setPageContext({
    description: 'Page ' + to.meta.productName
  });
});

// To reset
IKIbrainWidget.setPageContext(null);

The new context applies to every subsequent message. url and title auto-populate from the current page if not passed explicitly.

API availability. The widget script loads asynchronously: IKIbrainWidget may not be available yet if you call a method too early. This is never a problem in onclick handlers, since the user clicks once the page has loaded. But for automatic calls such as router.afterEach — which can fire on the first render, before the script has run — it's best to wait until the API is ready:
function ikiReady(fn) {
  if (window.IKIbrainWidget) { fn(); }
  else { setTimeout(function () { ikiReady(fn); }, 100); }
}

router.afterEach(function (to) {
  ikiReady(function () {
    IKIbrainWidget.setPageContext({ description: 'Page ' + to.meta.productName });
  });
});

Open with Question

The most powerful feature: open the chat with a pre-defined question, leveraging the page context. The bot will answer as if the user had typed the question, with full awareness of what page the user is on.

IKIbrainWidget.openWithQuestion(question, context)
ParameterTypeDescription
questionstring (required)The question to send to the bot
contextstring (optional)Context specific to this question (product name, service, category, etc.). If omitted, the global pageContext is used.

Example:

<button onclick="IKIbrainWidget.openWithQuestion(
  'What material is this made of?',
  'Ergonomic Chair XR-500 - Office Category'
)">What material is this made of?</button>
The context is invisible to the user — the user only sees the question in the chat. The bot uses it internally to understand what the question refers to, find the most relevant knowledge base content and give a precise answer.

Multiple buttons, same context

When a page has multiple buttons sharing the same context (e.g. several questions about the same product), instead of repeating it in every call you can declare it once in the global page context: every button inherits it and you call openWithQuestion() with just the question.

<script>
window.IKIbrainConfig = {
  pageContext: {
    description: 'Ergonomic Chair XR-500 - Office Furniture'
  }
};
</script>
<!-- embed script here -->

<button onclick="IKIbrainWidget.openWithQuestion('What material is it made of?')">Materials</button>
<button onclick="IKIbrainWidget.openWithQuestion('Which sizes are available?')">Sizes</button>
<button onclick="IKIbrainWidget.openWithQuestion('What is the warranty?')">Warranty</button>

Precedence rule

The 2nd argument of openWithQuestion(question, context) always wins over the global context. If a button passes an explicit non-empty context, it overrides the global value; otherwise the global pageContext is used as fallback.

<!-- Global: "Ergonomic Chair XR-500" -->

<!-- Uses the global context -->
<button onclick="IKIbrainWidget.openWithQuestion('How much does it weigh?')">Weight</button>

<!-- Overrides with a specific context -->
<button onclick="IKIbrainWidget.openWithQuestion(
  'What is the return policy?',
  'Store-wide return policy'
)">Returns</button>

If neither a global context nor the context parameter is set, the question is sent without any page context: the bot only receives the question text and doesn't know which page the user is on. Contextual questions (e.g. "what material is it made of?") may then be ambiguous, since the reference to the product or page content is missing.

Example: E-commerce Product Page

On a product page, declare the context once and add contextual buttons that ask common questions about that product:

<script>
window.IKIbrainConfig = {
  hideLauncher: true,
  pageContext: {
    description: 'Ergonomic Chair XR-500 - Office Furniture'
  }
};
</script>

<!-- Product: Ergonomic Chair XR-500 -->
<div class="product-questions">
  <button onclick="IKIbrainWidget.openWithQuestion('What material is this made of?')">Materials</button>
  <button onclick="IKIbrainWidget.openWithQuestion('Is this available in other sizes?')">Sizes</button>
  <button onclick="IKIbrainWidget.openWithQuestion('What is the warranty on this product?')">Warranty</button>
</div>

Example: Real Estate Listing

<button onclick="IKIbrainWidget.openWithQuestion(
  'How much is the monthly rent?',
  '3-bedroom apartment, Via Roma 15, Milan - Ref. APT-2024-089'
)">Ask about rent</button>

<button onclick="IKIbrainWidget.openWithQuestion(
  'Is there a garage available?',
  '3-bedroom apartment, Via Roma 15, Milan - Ref. APT-2024-089'
)">Ask about parking</button>

Example: Service Page

<button onclick="IKIbrainWidget.openWithQuestion(
  'How much does this service cost?',
  'SEO Audit & Optimization - Digital Marketing Services'
)">Ask about pricing</button>

<button onclick="IKIbrainWidget.openWithQuestion(
  'How long does it take?',
  'SEO Audit & Optimization - Digital Marketing Services'
)">Timeline</button>

API Reference

MethodDescription
IKIbrainWidget.openChat() Opens the chat window. Does nothing if already open.
IKIbrainWidget.closeChat() Closes the chat window. Does nothing if already closed.
IKIbrainWidget.setPageContext(ctx) Updates the global page context at runtime. Accepts {url?, title?, description?}. Pass null to reset. Useful for SPA sites that change route without reloading.
IKIbrainWidget.openWithQuestion(question, context?) Opens the chat with a pre-defined question and optional page context. If context is empty or omitted, the global pageContext is used instead. If a session is already active, it resets to a new session.

Configuration Object

window.IKIbrainConfig = {
  hideLauncher: true,    // Hide the floating chat icon
  autoOpen: true,        // Open the chat on page load (true or 'desktop')
  chatPosition: {        // Chat panel position (default: bottom corner)
    bottom: '96px', left: '24px'
  },
  lang: 'it',           // Skip language selector (multilingual bots)
  pageContext: {         // Global page context (inherited by every message)
    description: 'Ergonomic Chair XR-500'
  },
  serviceContext: {...}  // External service context (advanced)
};

The IKIbrainConfig object must be defined before the embed script loads.

serviceContext (advanced)

If your site runs its own application — user accounts, carts, orders — the assistant can take session data from it so that its actions adapt to the current user or session (for example: enabling actions only for logged-in users, or cart-aware features).

This is an integration-level feature: the exact data passed and how it's used are configured together with us and depend on your setup. It is meant for powering actions, not for user authentication.

Building something like this? Get in touch and we'll share the integration details.

Behavior Details

Session Management

  • Each openWithQuestion() call starts a new, clean session
  • If the chat is already open, the current session is reset before starting the new one
  • The onboarding flow (privacy notice, language selector, OTP, pre-chat form) runs normally before the question is sent

Multiple Buttons

  • If the user clicks multiple buttons quickly, only the last one wins
  • Each button can use different questions but share the same context, or vice versa

Context Tips

  • Be descriptive — include the product/service name, category, and any unique identifier
  • Keep it concise — aim for 10-50 words. This is not a full page description, just enough for the bot to identify what the user is looking at
  • Use consistent naming — match the terminology used in your knowledge base for best results

Compatibility

  • Works on all modern browsers (Chrome, Firefox, Safari, Edge)
  • The standard widget behavior is fully preserved when hideLauncher is not set
  • All existing features (multilingual, pre-chat forms, OTP for private bots) work normally

Need support?

The IKIweb team configures and maintains IKIbrain for you. Tell us about your project.

Get in touch