Glance Browser Agent SDK.
javascript
const express = require('express');
const app = express();
app.post('/loginkey', cors(corsOptions), (request, response) => {
try {
const version = 1;
const expires = (Math.round((new Date()).valueOf() / 1000)) + parseInt(environmentVariables.GLANCE_EXPIRATION, 10);
const keystring = environmentVariables.GLANCE_GROUP_ID + request.query.partneruserid + version + expires;
const CryptoJS = require('crypto-js');
const hmac = CryptoJS.HmacSHA256(keystring, environmentVariables.GLANCE_API_KEY);
const hmacb64 = hmac.toString(CryptoJS.enc.Base64);
const loginkey = "$" + version + "$" + expires + "$" + hmacb64.substr(0, 43).replace(/\+/g, '-').replace(/\//g, '_');
response.json({
'loginKey': loginkey,
'groupId': environmentVariables.GLANCE_GROUP_ID,
'expiration': expires
});
} catch(error) {
// handle error
}
});
`
> In the above example we have made GLANCE_GROUP_ID > GLANCE_EXPIRATION and GLANCE_API_KEY environment variables.
Install
`bash
npm i @glance-networks/agent-plugin
`
Usage
This is an example to get up and running, see the below table for additional props that can be added.
`typescript
import { Glance } from '@glance-networks/agent-plugin';
`
`tsx
groupid={GLANCE_GROUPID}
authurl={URL_TO_LOGINKEY}
puid={GLANCE_PUID}
openlocation={'tab' | 'window' | 'iframe' }
iframeid={IFRAME_ID}
gicon={true}
presence={true | false}
glancebaseurl={'beta' | 'production'}
visitorid={VISITOR_ID}
debugmode={true | false}
custominvoke={{
func: "customFunctionName",
args: {
dataParameter: "dataValue"
}
}}
/>
`
Properties
| Prop | Type | Description |
| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| authbody | function | Optional. If using authmethod=loginkey you can optionally pass data to your function via the POST request body. |
| authheaders | Object | Optional. If using authmethod=loginkey you can further customize your loginkey endpoint by passing headers to your function (e.g. Authorization header). |
| authmethod | enumeration | Optional. Default = loginkey. loginkey OR samlloginkey (requires you have set up SAML with Glance). |
| authurl | string | Required. Enter the URL to your login key service. |
| custominvoke | object | Optional. A Presence Agent can invoke Javascript functions defined on the Visitor's web page by providing an object that defines the following parameters: func name of the function, args function arguments. See below for more detail and an example. |
| debugmode | boolean | Optional. true turns on console logs to assist in debugging. false (default) turns off console logs. |
| gicon | boolean | Required. In order to show the Glance logo next to the Join button, set this to true. If gicon is not set, or it is set to false (default), then the logo will not appear. |
| glancebaseurl | string | Required. Should be production or beta if testing early release features on the glance beta platform. |
| groupid | integer | Required for loginkey, optional for samlloginkey. Enter your Glance Group ID (unique ID assigned to your company by Glance). |
| iframeid | string | Optional. The id of the iframe used when openlocation is set to iframe. If no id is given, a new iframe is created. |
| openlocation | string | tab (default) opens agent viewer in new tab.window opens agent viewer in new browser window. iframe opens agent viewer in an iframe. |
| openwindow | function | Optional. Use this to support the ability to open a Glance Cobrowse session in a new window or tab, when the URL is embedded in an Agent Desktop. |
| presence | boolean | Optional. Determines if presence is enabled. If undefined, presence is set to off. false (default) pressence is off, true presence is on. |
| presessionfunc | function | Optional. In case you need to do some work before a signaling the visitor to accept terms, you can pass a javascript function to this property. See below for more detail and an example. |
| puid | string | Required. Identifies the Glance user. |
| reportingCallback | function | Optional. Specify a function that will be called at the end of each cobrowse session to return session data. |
| visitorid | string | Required when pressence is set to true. Unique identifier that is used to track the visitor presence state and start the 1-click Cobrowse session. |
| errorMessage | string | Optional. Allows you to set error message text session. |
| reportingOrigin | string | Optional. Allows you to set origin property in the Glance Reporting. |
| reportingExternalId | string | Optional. Allows you to set xid property in the Glance Reporting. |
| uiVersion | number | Optional. Allows you to set uiVersion property for component. Allowed values are 1 (default) and 2. |
$3
`javascript
const exampleOpenWindowCallback = (url: string): void => {
// Opens a new window when a Glance Cobrowse session starts.
window.open(url, 'Glance', 'width=800,height=800');
};
`
$3
`javascript
authheaders={{
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Bearer ',
}}
authbody={
new URLSearchParams({
Token: ,
})
}
`
$3
> In order to allow for agent initiated sessions, Glance has created its Presence services framework. This service allows agents to "signal" visitor browsers to do things like start sessions, execute custom code, and so on. Each visitor is unqiuely identified within a Glance groupID using a unique vistor_id value. Visitors are "present" when they are actively focused on a browser tab that has Glance Cobrowse enabled and active or when focused inside a mobile app (Android/iOS SDK). An agent can click on the Join button when a visitor is present to initiate a session request to that user. This concept is usually invoked when an agent in the app/crm is contextually "looking" at a record such as an account/contact/lead etc. for that visitor and wants to cobrowse with that user.
>
> Definitions:
>
> * VisitorID - This is a unique value for the web visitor. This can be up to 62 digits in length, generally a hashed customer UUID format. This value is shared between the web property and the agent CRM for a given user.
>
> * Join Button - This is the UI component the Agent interacts with. It has a few states such as visitor present and not present. The button will be Blue when a visitor is not present currently, this allows teh agent to use the code methods to cnnect with a visitor/guest.
>
> The VISITOR_ID should be set dynamically as a prop to the React component based on a known value that is attached to a customer profile. Following React lifecycle methods, the UI state will update when a new value appears as the VISITOR_ID. You can set this property dynamically when an agent is viewing a record such as a case or contact record that is specific to a customer or action they are working on.
> The visitor side (browser) publishes a visitor_id, the agent side subscribes to that same string in order to determine if the user is available. More detail can be found here
$3
> Visitor's Page:
`javascript
GLANCE_COBROWSE.Custom = {
customFunctionName: function (params) {
// Do custom things on visitor's page.
}
}
`
> Agent's Glance Component:
`tsx
custominvoke={{
func: "customFunctionName",
args: {
dataParameter: "dataValue"
}
}}
/>
`
$3
Enable the ability to report on session metadata.
#### Example reportingCallback function
`javascript
reportingCallback={(data : HistoricalReportingData) => console.log(data)}
`
where HistoricalReportingData is
`typescript
export interface HistoricalReportingData {
sessionId: string; // the Glance Session Identifier to match with Customer Records Retriever, see https://help.glance.net/integrations/webservices/crr/
sessionStart: string; // the Glance Session start as ISO-8601 formatted string, YYYY-MM-DDTHH:mm:ss.sssZ
sessionEnd: string; // the Glance Session end as ISO-8601 formatted string, YYYY-MM-DDTHH:mm:ss.sssZ
duration: number; // the Glance Session time duration in seconds, between Glance Session end and start
}
`
#### Example of the reportingCallback data
`json
{
"sessionId": "111111111",
"sessionStart": "2023-08-14T17:36:02.000Z",
"sessionEnd": "2023-08-14T17:38:22.000Z",
"duration": 140
};
``
$3
You can pass a reference to a function into this prop if you want to handle some work
prior to signaling the visitor's page to show terms. For example, if you need to fetch some user information from
a database or generate a custom key to set on the visitor's session.
> Agent's Glance Component:
`tsx
presessionfunc={functionName}
/>
``