Loading...

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

agentsAvailable

—

Indicates that agents are available and waiting for requests on the Upscope dashboard.

agentRequestUpdate

status: string

Gives you updates about the status of the current agent request. One of pending, accepted, unavailable, canceled.

callAccepted

—

An audio call has been accepted by the visitor.

callEnd

—

An audio call has ended.

callStart

—

An audio call has started.

connection

—

The connection has been established with Upscope's servers.

connectionReset

—

The connection has been reset, and there will be a new visitor created.

newObserver

observerId: string

[[Someone new is now observing as an agent.]][[Useful to keep track of how many agents there are.]]

observerGone

observerId: string

[[observerGone is no longer observing.]][[Useful to keep track of how many agents there are.]]

sessionEnd

—

A session has ended.

sessionRequest

—

[[An agent is asking to start a session.]][[If you want to change the authorization flow, you'll need to add a onSessionRequest function to the configuration.]]

sessionStart

—

A session has started.

waitingForCall

—

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"))