Skip to content
Loopwix Docs

Embed and configure the chat widget

Embed the Loopwix chat widget with one script tag, show it in a page or open it from your own button, control it from JavaScript and set your CSP.

The Loopwix chat widget is one script. Paste it into your page and your published agent answers visitors there. Everything else on this page is optional.

How do I embed the chat widget on my site?

Copy the script tag with your public key from the Install tab of the website chat, and place it before the closing body tag. To show the chat inside a page, choose Embedded in the page and add a loopwix-chat element. To open it from your own button, choose My own button.

Add the script

  1. Open the agent, choose Channels, then Manage on Website chat, then the Install tab.
  2. Copy the snippet. It holds the widget address and your public key.
  3. Paste it once, just before </body>, on every page that should have the chat.
  4. Add your site under Advanced → Allowed sites, or the chat will not load.
<script src="https://YOUR-WIDGET-HOST/widget.js" data-key="lwix_pub_…" defer></script>

Use the exact src from your Install tab. The script starts by itself when it has a data-key. Add data-mount="page" to make the chat fill the whole page instead of showing a launcher.

Single-page apps: load the script once, in the page shell, not on every route. For React and Next.js, see React and Next.js.

The Install tab of the website chat studio
The Install tab · captured 2026-11-02

Choose how the chat appears

On the Install tab, How it appears has a Chat window setting.

Opens from a button (the default) shows a launcher. Under Button, choose Chat bubble for the standard launcher, or My own button to use an element on your page. With My own button, add data-loopwix-open to any button or link:

<button data-loopwix-open>Chat with us</button>

An element with the id loopwix-launcher works the same way.

Embedded in the page renders the chat inside a container you place. Give it the size you want; the chat fills it:

<div id="loopwix-chat" style="width:420px;height:600px"></div>

If the container is missing, the widget shows the chat bubble instead and logs a warning in the browser console. Save the draft and publish the agent for these settings to apply.

JavaScript API

The script defines a global Loopwix object.

// Open, close or toggle the chat. open() is safe to call before the widget has loaded.
document.querySelector('#help').addEventListener('click', () => Loopwix.open());

// React to replies. on() returns a function that removes the listener.
const stop = Loopwix.on('message', (event) => {
  console.log(event.role, event.text); // role is "assistant" (your agent) or "human" (a teammate)
});
stop();
MethodWhat it does
init(options)Starts the widget. Not needed when the script tag has data-key
open(), close(), toggle()Show or hide the chat
on(event, fn)Listen for an event; returns a function that removes the listener
off(event, fn)Remove a listener
EventWhen it fires
readyThe widget has loaded and is ready
open, closeThe chat window opens or closes
messageYour agent or a teammate replies; the event has role and text

Widget options

Start the widget yourself when you leave out data-key, for example to load it only after the visitor gives consent:

<script src="https://YOUR-WIDGET-HOST/widget.js" defer></script>
<script>
  window.addEventListener('load', () => {
    Loopwix.init({ apiKey: 'lwix_pub_…', mount: 'embed' });
  });
</script>
OptionMeaning
apiKeyYour public key (lwix_pub_…). Required
mountembed (default): the launcher or the loopwix-chat container. page: the chat fills the page. preview is used by the studio

Call init once. A second call logs "widget already mounted" and does nothing.

Public keys and allowed sites

The lwix_pub_… key is public: it appears in your page source and cannot read your data. What limits its use is Allowed sites: a request from an address not on the list is refused. See Advanced.

Never put secret credentials in a page. Integration credentials stay on the server; see Security.

CSP, cookies and privacy

If your site sends a Content Security Policy, allow the widget host from your snippet and the API host the widget calls. Find the API host in your browser's network tab, then add both:

Content-Security-Policy: script-src 'self' https://YOUR-WIDGET-HOST; connect-src 'self' https://YOUR-API-HOST; img-src 'self' data: https://YOUR-API-HOST

Check the browser console for anything still blocked.

The widget sets no cookies. It keeps its session in the browser's session storage, or in local storage when the agent keeps chat history across visits. It also stores a few display preferences.

If you use a consent tool, decide whether the chat loads before or after consent; use Loopwix.init to load it after. Link your privacy policy in Contact and legal. Files visitors send are scanned and kept for a limited time; see Messages.

Was this page helpful?

Last reviewed 2026-11-21

On this page