Presence Visitor API

For more control over the type and frequency of Presence data, and to allow the visitor to listen for custom messages, you can load the API, but suppress the default Presence behavior:

  • Include the standard Cobrowse script tag to get the GLANCE.Cobrowse.Loader API.

  • Set data-presence="api" in the script tag. The Visitor Presence script also includes SockJS, which defines a single global variable SockJS.

The Presence Visitor API is defined in the namespace GLANCE.Presence.Visitor. Use the Visitor API to customize presence behavior. As noted above, it is not necessary to make any API calls in order to get the behavior described under Default Presence Behavior.

All API calls take a single JavaScript object as a parameter. GLANCE.Presence.Visitor(params) – constructor

Constructor for a Visitor Object

Parameters

{
  "groupid" : [group id], // defaults to GLANCE_COBROWSE.groupid
  "visitorid" : [visitor id],<span class="Apple-converted-space">  // defaults to GLANCE_COBROWSE.visitorid</span>
}

GLANCE.Presence.Visitor.prototype.presence(params) Sends Presence information to the Presence service.

Parameters

{
  "data": [custom data to be stored on the presence server] // optional
}

NOTE: Data must be a JavaScript object whose properties are of type string or number.

The first time presence() is called after a new page is loaded, general visitor information such as URL and browser are sent to the Presence service, as well as any user specified information. On subsequent calls to presence(), any new Presence information provided will be merged with any existing information already on the server.

GLANCE.Presence.Visitor.instance

GLANCE.Presence.Visitor.instance is set to the most recently instantiated GLANCE.Presence.Visitor object. This allows multiple scripts running on a page to share a single Visitor instance.

GLANCE.Presence.Visitor.prototype.connect(params)

Connect to the Presence service to listen for Presence events related to the visitor. Behind the scenes, this method opens a SockJS connection to a specific Presence server. If the Presence server instance shuts down due to an auto scaling event, the Visitor object automatically connects to a new Presence server instance.

connect() must be called on the visitor side in order to receive commands from the agent, for example if the agent calls signalVisitor() or invokeVisitor().

GLANCE.Presence.Visitor.prototype.disconnect()

Disconnect the Presence Visitor from the Presence service.

Visitor Events

Before calling connect(), add event handlers as properties on the Visitor instance. Supported events are:

Event Description
onerror
See Glance.Presence.Agent onerror event.
onsignal(data)
onsignal fires when the agent sends a message via signalVisitor({ "data" : data }). data contains the object passed into signalVisitor by the agent.

If the visitor navigates to a new page, connect() must be called again to reestablish the connection. If the visitor is not connected at the time an agent signals or invokes the visitor, the visitor will receive the message upon next connection.

Visitor Presence and Focus

If a visitor has multiple windows or tabs open, only the currently active tab will send presence information or listen for messages from agents.

By continuing to use the site, you agree to the use of cookies. Learn More