Description

You can subscribe on Events through the widget code:

<script>
window.replainSettings = {
  id: '<chat ID>',

  // event subscriptions
  **onWidgetLoaded**: <function>,
  **onClientOpenedChat**: <function>,
  **onClientClosedChat**: <function>,
  **onClientSentMessage**: <function>,
  **onClientSentContactForm**: <function>,
  **onClientSentOfflineForm**: <function>,
  **onOperatorChoseClient**: <function>,
  **onOperatorSentMessage**: <function>,
  **onInvitationShown**: <function>,
};

(function(u){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;
var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);
})('<https://widget.replain.cc/dist/client.js>');
</script>

function — the function that will be performed after the completed event.

Available events

onWidgetLoaded

The widget is loaded

Example

<script>
window.replainSettings = {
  id: '<chat ID>',
  **onWidgetLoaded**: function() {
    // the widget is loaded
    window.ReplainAPI('setStartMessage', 'Hey 👋 We are here to help you!');
  },
};

(function(u){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;
var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);
})('<https://widget.replain.cc/dist/client.js>');
</script>

onClientOpenedChat

The client has opened the chat widget

Function parameters

Example

<script>
window.replainSettings = {
  id: '<chat ID>',
  **onClientOpenedChat**: function(client) {
    // the client has opened a chat 
    console.log('client:', client);
  },
};

(function(u){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;
var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);
})('<https://widget.replain.cc/dist/client.js>');
</script>

onClientClosedChat

The client closed the chat widget

Function parameters

Example

<script>
window.replainSettings = {
  id: '<chat ID>',
  **onClientClosedChat**: function(client) {
    // the client closed the chat
    console.log('client:', client);
  },
};

(function(u){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;
var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);
})('<https://widget.replain.cc/dist/client.js>');
</script>