Skip to main content

Sending event data

tip
The chat widget supports the method that sends event data on the site.

Text message

Use the following function to send a text message from the page with the chat widget:

window.JustWidget.sendText({ text: "Hello World!", hiddenMessage: true });

The message can either be displayed as a user reply or can be hidden. Use the hiddenMessage: true flag to hide the message.

Event

Use the following function to send a event message from the page with the chat widget:

window.JustWidget.sendEvent({ event: "customEvent", eventData: { example: false }});

The event message is not displayed as a user reply.

Data are available in the $request.data.eventData variable within the script.

caution
Use window for iframe when you embed a chat widget in the iframe. For example: document.getElementById("iframe").contentWindow.

Example of sending event data

<button onclick="customText(false)">Send message</button>
<button onclick="customText(true)">Send hidden message</button>
<button onclick="customEvent()">Send event</button>

<script src="PATH/TO/YOUR/justwidget.js" async></script>
<script type="text/javascript">
// sending text
function customText(hidden) {
window.JustWidget.sendText({ text: "Hello World!", hiddenMessage: true });
}
// sending event
function customEvent() {
window.JustWidget.sendEvent({ event: "customEvent", eventData: { example: false }});
}
</script>