JavaScript SDK
Listening for Events
Listening for events
You can listen for events by running the following code.
Upscope('on', ...eventNames, callbackFunction);
List of events
Event Name | Additional arguments | Description |
---|---|---|
| — | Indicates that agents are available and waiting for requests on the Upscope dashboard. |
|
| Gives you updates about the status of the current agent request. One of |
| — | An audio call has been accepted by the visitor. |
| — | An audio call has ended. |
| — | An audio call has started. |
| — | The connection has been established with Upscope's servers. |
| — | The connection has been reset, and there will be a new visitor created. |
|
| [[Someone new is now observing as an agent.]][[Useful to keep track of how many agents there are.]] |
|
| [[ |
| — | A session has ended. |
| — | [[An agent is asking to start a session.]][[If you want to change the authorization flow, you'll need to add a |
| — | A session has started. |
| — | The visitor has gotten to the page from an agent's personal link. |
Example
Here's an example of how to use the events API to show a message to the visitor when a session is active.
<div id="upscope-active" style="display: none;">
Screen sharing active.
</div>
<script>
const activeElement = document.getElementById('upscope-active');
Upscope('on', 'sessionStart', 'sessionContinue', () => {
activeElement.style.display = 'block';
});
Upscope('on', 'sessionEnd', () => {
activeElement.style.display = 'none';
});
</script>
Tracking event data such as clicks
All events that originate from the agent will have a isUpscopeBrowserInstruction
attribute set to true
.
​
For example:
​
​button.addEventListener("click", evt => console.log("Clicked by", evt.isUpscopeBrowserInstruction ? "agent" : "user"))