Presence Agent API

Including the Presence Agent API

To include the Presence Agent API in a web page, add the following HTML, substituting your group id for "12345".

<meta id="glance-cobrowse" data-groupid="12345" />
<script src="" ></script>

If you are including the presence script bundled in a component or self-hosted, you must add a meta tag to specify the group id: <meta id="glance-cobrowse" data-groupid="groupidhere"></meta>

The Presence Agent API can only be used from a trusted domain.

NOTE: Contact Glance to ensure that your website domain is configured as an allowed agent origin on our Presence Service.


The Presence Agent API requires an Authorization Token which can be obtained from the Glance Authorization Service web service. Authorization should be performed once to obtain a token which can be used for a set duration.

Please refer to the Glance Authorization API for information on obtaining and using an Authorization Token.

The Glance Presence Agent API is defined in the namespace GLANCE.Presence.Agent.

GLANCE.Presence.Agent(params) – constructor

Constructs a Presence agent object. A separate agent object must be instantiated for each visitor that the agent needs to communicate with.

Either a visitorid or a uniqueid must be specified in the params object to identify the visitor connection.


  "presenceserver": [Presence Service, defaults to ""],
  "visitorid":"" //specify visitor id for a visitor connected with GLANCE.Presence.Visitor.connect()
  "uniqueid":"" // specify unique id for a visitor connected with GLANCE.Presence.Visitor.connectUnique()


  "onsuccess" : [called back with visitor presence info if lookup succeeds],
  "onfail" : [function(errorcode) {} called back if lookup fails]


Sends a signal (message) to a visitor who has been connected within the last 5 seconds to the service. If the visitor has an open connection to the service, the visitor will be signaled immediately. Otherwise, the visitor will be signaled on next connect, if within 5 seconds.

The on success callback is called when the signal is confirmed that it was received by the Presence service.


  "data" : [message to send to visitor],
  "onsuccess" : [function to be called back on success],
  "onfail" : [function to be called back on failure]

The visitor receives the signal via the onsignal event


Invokes a visitor side JavaScript function in the GLANCE namespace. Visitor side must have been connected at some point within the last 5 seconds.

The onsuccess callback is called when the invoke message is confirmed that it was received by the Presence service.


  "func" : [name of function to invoke, must be in the GLANCE namespace],
  "args" : [object to pass to the function ],
  "onsuccess" : [function to be called back on success],
  "onfail" : [function to be called back on failure]


Queries Presence data // not implemented yet


Connect to the Presence server to receive notification of events related to the visitor. connect() opens a WebSocket connection to the Presence service.

Before calling connect(), set event handlers as properties of the Agent object.


Disconnect the Presence Agent from the presence service.

Agent Events

Events which may fire on the agent side are:

Event Data Passed
"connected" : [true|false]

Fires when a visitor connects or disconnects from the presence service. Note that for a visitor browsing a website, the actual websocket connection will disconnect and reconnect as the visitor navigates from page to page. The visitor is still considered connected to presence during navigation, so no "visitorconn" event fires.
"connected" : [true|false]

Fires when the visitor's actual socket or websocket connection to the presence server is established or closed.
the presence data just sent by the visitor
"error" : [error code],
"detail" : [error detail]
Error codes:
connfail – Failed to establish or maintain the websocket connection. In the event of a connection failure, a "detail" property will include a detailed reason:
authorization – Authorization token missing, bad, or expired
connection – Network connection dropped
error – Server returned an error
status : ["displayed"|"accepted"|"declined"]
The terms event fires when the terms and conditions dialog is displayed, accepted, or declined by the visitor.
These events fire when the corresponding events sessionstart, sessionend, and error fire on the visitor side. See the GLANCE.Cobrowse.Visitor API documentation for details.
visibility : ["hidden"|"visible"]
The visibility event fires when the visitor's browser tab visibility changes.

Error Handling

The onfail parameters to GLANCE.Presence.Agent methods should be a function which takes a "reason" parameter. The "reason" codes will be one of the following:

  • authorization – Authorization token missing, bad, or expired
  • connection – Network connection could not be established. See the browser console for details.

Sample Code

Visitor Side Sample Code

// Instantiate a Visitor presence object
  var presencevisitor = new GLANCE.Presence.Visitor({
  groupid : 123,
  visitorid : "111111111"

// Start sending regular presence updates (by default, every 60 seconds)


// Send a presence update (now) with some custom data
presencevisitor.presence({ data : { wizardpage : 3} }

// Listen to agent messages.  
presencevisitor.onsignal = handleSignal;

Agent Side Sample Code

// Authenticate the agent
  service: "presence",
  credentials: {
  		username: [Glance account username],
  		password: [Glance account password],
  		gssnid: [Glance website session id],
  		partnerid: [Partner id, usually same as groupid],
  		partneruserid: [Partner user id],
  		loginkey: [Login key signed with secret api key],
  		g4scredentials : [Glance for Salesforce credentials]
// Not all credentials fields are required.  
// See the page on Authorization Token for requirements.
  groupid: "1234",
  duration: [duration of the authorization token in minutes 1-120],
  onsuccess: showpresence,
  onfail: function(reason) {
      // display error ...

function showpresence() {
  // Construct a new Presence Agent object
  presenceagent = new GLANCE.Presence.Agent({
      visitorid: "12345678"

  // Setup event handlers
  presenceagent.onvisitorconn = function(e) {
    // visitor is connecting via websocket and can be signaled
    // display a "connected" status, e.g. light up a cobrowse button

    // Optional, lookup the visitor to find any associated data
            onsuccess: function(visitordata) {
            onfail: function(reason) {};

// Invoke a visitor side api.  Put this code behind a "cobrowse" button
  func: "GLANCE.Cobrowse.VisitorUI.showTerms",
  args: {
    sessionKey: "fjpvlsf9wsd90w"

// Send a custom signal.  onsignal will be called on the GLANCE.Presence.Visitor instance.
// For example, put this code behind a "start chat" button
  chatid: "123456",
  command: "startchat"

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