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)

presencevisitor.presence();

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

// Listen for agent messages.  
presencevisitor.onsignal = function (msg) { console.log("Received", msg); }
presencevisitor.connect();

Agent-Side Sample Code

// Authenticate the agent
GLANCE.Authorization.authorize({
  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
    myhandlevisitor();

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


// Invoke a visitor side api.  Put this code behind a "cobrowse" button
presenceagent.invokeVisitor({
  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
presenceagent.signalVisitor({
  chatid: "123456",
  command: "startchat"
});

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