GenAI Widget Options

Reference for all GenAI Widget settings: script tag attributes (data-api-key, data-hide-widget), programmatic config (apiKey, onReady), server-side theme and content options, control events, and public methods.

Script Tag Attributes

When you load the widget via a <script> tag, you can set these attributes on the script element.

data-api-key

Type: String
Required: Yes
Default: none

Your GenAI API key for authentication. The widget will not initialize without it.

<script
  src="%SCRIPT_URL%/genai-embeddable-widget.js"
  data-api-key="%API_KEY%"
></script>

data-hide-widget

Type: String
Required: No
Default: "false"

Set to "true" to hide the floating chat button. Use this when you want to open the widget only via your own UI (e.g. a custom button) by dispatching the genai-widget:open event.

<script
  src="%SCRIPT_URL%/genai-embeddable-widget.js"
  data-api-key="%API_KEY%"
  data-hide-widget="true"
></script>

Programmatic Options (WidgetInitConfig)

When you initialize the widget with new GenAIEmbeddableWidget(config), pass an object with these properties.

apiKey

Type: String
Required: Yes
Default: none

Your GenAI API key.

var widget = new GenAIEmbeddableWidget({
  apiKey: '%API_KEY%',
});

onReady

Type: Function
Required: No
Default: null

Callback invoked when the widget has finished initializing (styles injected, button and iframe created, config loaded).

var widget = new GenAIEmbeddableWidget({
  apiKey: '%API_KEY%',
  onReady: function() {
    console.log('Widget ready');
  },
});

Theme Configuration (Server-Side)

Theme options are managed in the Preferabli dashboard and fetched by the widget at runtime. They are not passed in the client-side script. The following defaults apply when not overridden in the dashboard.

OptionTypeDefaultDescription
primaryColorString"#1E3264"Primary brand color (button background, etc.)
secondaryColorString"#1E3264"Secondary color
userDialogBackgroundColorString"#89ED96"Background color for user message bubbles
systemDialogBackgroundColorString"#1E3264"Background color for system/assistant message bubbles
textColorString"#051024"Primary text color
secondaryTextColorString"#1E3264"Secondary text color
buttonTextColorString"#ffffff"Text color on the floating chat button
buttonPositionString"bottom-right"Position of the floating button. Options: top-left, top-right, bottom-left, bottom-right
buttonIconString(default star SVG)URL to an image or inline SVG for the button icon
buttonRadiusString"99999px"Border radius of the button (e.g. "8px" or "99999px" for pill)
logoUrlStringPreferabli logo URLLogo displayed in the chat UI
systemProfilePictureUrlStringPreferabli icon URLAvatar for the assistant in the chat

Content Configuration (Server-Side)

Welcome screen content is also managed in the Preferabli dashboard. These defaults apply when not overridden.

OptionTypeDefaultDescription
welcomeTitleString"Hi there!"Title on the welcome screen
welcomeMessageString"How can I help you today?"Short message below the title
welcomeBulletPointsArray of Strings["Explore our products", "Food pairings", "Check availability"]Bullet points shown on the welcome screen
welcomeButtonTextString"Let's begin!"Label of the button that starts the chat

Widget Control Events

You can open, close, or toggle the chat by dispatching custom events on window. This works whether you initialized via script tag (auto-init) or programmatically.

genai-widget:open

Opens the chat panel.

window.dispatchEvent(new CustomEvent('genai-widget:open'));

genai-widget:close

Closes the chat panel.

window.dispatchEvent(new CustomEvent('genai-widget:close'));

genai-widget:toggle

Toggles the chat panel (open if closed, close if open).

window.dispatchEvent(new CustomEvent('genai-widget:toggle'));

genai-widget:ready

Fired when the widget is fully loaded and ready. Listen only (do not dispatch).

window.addEventListener('genai-widget:ready', function() {
  console.log('Widget is ready');
});

Public Methods

When you have a reference to the widget instance (e.g. var widget = new GenAIEmbeddableWidget({ apiKey: '...' });), you can call these methods.

open()

Opens the chat panel.

widget.open();

close()

Closes the chat panel.

widget.close();

toggle()

Toggles the chat panel open or closed.

widget.toggle();

destroy()

Removes the widget from the page (floating button and iframe) and cleans up event listeners. Use this when unmounting the widget from a single-page app or when the user logs out.

widget.destroy();