15-day Pro trial · no credit cardStart free →

Web JS SDK

Install the web widget

Install the STINGIM chat widget with one script tag and configure it with window.stingImSettings.

The web widget is a chat bubble that runs in an iframe on your site. One script tag installs it; the window.stingIm JavaScript API (host protocol v2) controls it.

Install

Copy the install code from Settings → Channels → Web widget → Code and paste it anywhere on the page. It works in <head> or <body>; in <head> the script waits for DOMContentLoaded before it adds the widget.

HTML
<script src="https://app.stingim.com/chat-bubble/install.js?BASE64_PARAMS" async></script>
  • BASE64_PARAMS encodes your widget's app_secret, channel_id, plugin_id, project_id and tenant_id. The app_secret here is a public site identifier: it appears in every visitor's browser and does not need to be kept secret. The only secret is the identity verification key, which must stay on your server (Identity verification).
  • Inserting the install code twice on one page is safe: the second load does nothing and reuses the existing window.stingIm.
  • If the install code is missing app_secret, channel_id or plugin_id, or the backend rejects the configuration (wrong key, widget disabled or deleted), the widget stays hidden and the browser console shows a single [stingim] Chat widget disabled: … error.

Settings before load: window.stingImSettings

You can set window.stingImSettings before or after the install code — it is read during the handshake. If several snippets set values (identity, tags…), merge them with Object.assign instead of overwriting the whole object, otherwise the later snippet wipes the earlier one:

HTML
<script>
  window.stingImSettings = Object.assign(window.stingImSettings || {}, {
    tags: ['kol_anna'],
    user: { userId: 'u_123', userHash: '…', exp: 1767225600, name: 'Jane', email: '[email protected]' },
    keepQueryParams: ['ref'],
    onReady: function (stingIm) {
      // the widget is ready to chat
    },
  });
</script>
FieldDescription
userThe logged-in user, same shape as identify(). See Identity verification.
tagsEntry tags used for routing — up to 20, each at most 64 characters. You can also put a tag in the page URL as ?stg_tag=kol_anna.
keepQueryParamsExtra URL parameter names to keep when the widget reports the page URL (up to 10, letters, digits, _ and -). See Privacy.
onReady(stingIm)Called once when the widget is ready.

Calling the API before it is ready

window.stingIm exists as soon as install.js has run. Every call made before the iframe handshake completes is queued and delivered in order afterwards, so you never need to poll. Use onReady (or the stingim:ready event) only when you need to know that the widget can actually chat:

JavaScript
window.stingIm.onReady(function (stingIm) {
  console.log(stingIm.getStatus()); // { ready: true, … }
});

Because the script is async, window.stingIm may not exist yet when your own code runs. Either put your code in stingImSettings.onReady, or listen for the stingim:ready event on window.

Open the chat from your own button

HTML
<button type="button" onclick="window.stingIm && window.stingIm.open()">Chat with us</button>

To show only your own button, hide the widget until the button is clicked:

JavaScript
window.stingImSettings = Object.assign(window.stingImSettings || {}, {
  onReady: function (stingIm) { stingIm.hide(); },
});
document.getElementById('help').addEventListener('click', function () {
  window.stingIm.open(); // open() also un-hides
});

What's next

Found a mistake? Email [email protected]