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.
The widget is loaded
<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>
The client has opened the chat widget
<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>
The client closed the chat widget
<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>