Web JS SDK
Events
DOM events dispatched by the STINGIM web widget: stingim:ready, stingim:state, stingim:identity and stingim:error.
The widget dispatches CustomEvents on window. Listen with window.addEventListener; the payload is in event.detail.
Event list
| Event | event.detail | When |
|---|---|---|
stingim:ready | getStatus() | Once, when the widget is ready to chat. |
stingim:state | getStatus() | The panel opened or closed, or the hidden state changed. |
stingim:identity | { status } | Every time the backend returns a verdict for an identity claim. |
stingim:error | { message } | A fatal error occurred; the widget is now hidden. |
stingim:ready
JavaScript
window.addEventListener('stingim:ready', function (e) {
console.log('chat ready', e.detail); // { ready: true, visible: …, … }
});Because the install script loads asynchronously, this event is the safest place to start using window.stingIm from your own code. It fires once per widget instance.
stingim:state
JavaScript
window.addEventListener('stingim:state', function (e) {
analytics.track(e.detail.open ? 'chat_opened' : 'chat_closed');
});stingim:identity
JavaScript
window.addEventListener('stingim:identity', function (e) {
if (e.detail.status === 'rejected') {
// the userHash was wrong or expired; the visitor is treated as anonymous
}
});status | Meaning |
|---|---|
anonymous | No identity was declared. |
verified | The signature is valid. The same userId shares conversation history across devices. |
unverified | Unsigned claim (or verification is off for this widget). userId, name and email are shown to agents as display attributes only. |
rejected | The claim was discarded (invalid or expired signature, or an unsigned claim when verification is Required). The visitor is treated as anonymous. |
stingim:error
JavaScript
window.addEventListener('stingim:error', function (e) {
console.error('chat unavailable:', e.detail.message);
document.getElementById('help').hidden = true;
});Fired when the install code is incomplete or the backend rejects the widget configuration. The widget hides itself and queued calls resolve with false.
Found a mistake? Email [email protected]
