Gladly

Gladly

The Gladly Sidekick is an embeddable UI element that lives on your website and allows customers to search for answers or talk and interact with your team in real-time. The Gladly Sidekick API enables you to have programmatic control of the Gladly Sidekick.

JavaScript snippet

Add the following JavaScript embed code to all your site’s pages, preferably at the bottom of the page to avoid slowing down the main page content to load. This will load the code that powers the Gladly Sidekick on your site.

Note that the fourth argument of the snippet below specifies 'PROD' which enables you to use the latest release of the Chat-SDK with your production appId.

<script>
  (function(c,n,i,t){var p;var s=[];var l;if(t==="PROD"||!t){l="https://cdn.gladly.com/chat-sdk/widget.js"}else if(t==="STAGING"){l="https://cdn.gladly.qa/gladly/chat-sdk/widget.js"}else{l=t}c[i]={init:function(){p=arguments;var e={then:function(t){s.push({type:"t",next:t});return e},catch:function(t){s.push({type:"c",next:t});return e}};return e}};function e(){try{var t=n.getElementsByTagName("script")[0];var e=n.createElement("script");e.async=true;e.src=l+"?q="+(new Date).getTime();t.parentNode.insertBefore(e,t)}catch(t){}}c.__onGladlyHostReady__=function t(e){delete c.__onGladlyHostReady__;c[i]=e;e.loaderCdn=l;if(p){var n=e.init.apply(e,p);for(var a=0;a<s.length;a++){var r=s[a];if(r.type==="t"){n=n.then(r.next)}else{n=n.catch(r.next)}}}};e()})
  (window,document,'Gladly','PROD')
</script>

Initialize

In order to start the Gladly Sidekick on your site, you must initialize it after you load the above JavaScript embed code.

Basic Initialization:

Add the following script tag to your page to automatically initialize the Gladly Sidekick. This is most appropriate if you do not want to take advantage of any Gladly API functionality and just want to display a basic widget. Work with your Gladly CSM to get the “your-own-id” value.

<script>
 window.gladlyConfig = {
   appId: 'your-own-id'
 };
</script>

Manual Initialization:

Sidekick can be manually initialized to get better control over when to display the Sidekick. This could be desirable, for example, if you want to start the Sidekick from your own button.

For a more dynamic interaction, Sidekick exposes an Availability state that allows the site to change the behavior depending on if chat is closed or if it's unavailable due to high demand.

The example below initializes the Sidekick, then checks to see if chat is available and sets a class on a button assumed to exist on the page.

Gladly.init({
  appId: "your-own-id"
}).then(function() {
  // This is called once Sidekick has been initialized.

  // An element with the id "start-chat" is assumed to be on the page.
  var startChatButton = document.getElementById('start-chat');

  // An onClick handler can be attached to the "start-chat" element
  startChatButton.onclick = function() {Gladly.show()};

  // This API call gets the current availability
  var availablility = Gladly.getAvailability();

  // Setting the availability as the class name on the "start-chat" element,
  // this allows us to change the look of the button via CSS.
  startChatButton.setAttribute('class', availablility.toLowerCase());

  // Subscribe to changes in availability, and update the class on the "start-chat" element.
  Gladly.on('availability:change', function(availablility) {
    startChatButton.setAttribute('class', availablility.toLowerCase());
  });
}).catch(function(error) {
  // If anything goes wrong when Sidekick is being initialized, this gets called.
  console.log('error:', error)
});

Browser Support

The Gladly Sidekick supports major browsers. For the desktop, we support current + previous major versions of Chrome, Firefox, and Safari along with IE11 and the current version of Microsoft Edge. For mobile, we support current + previous major versions of Chrome on Android and iOS and the current + previous versions of Safari on iOS.

Working with Sandbox / Staging Environment

You can use our sandbox environment to test upcoming Chat-SDK releases or new configuration on your staging site. To launch the Gladly Sidekick on your staging site, follow the steps above to add the JavaScript embed code and initialize. Then make following modification:

Change the value in this part of your embed code to 'STAGING':

    (window,document,'Gladly','STAGING')

Deployment Checklist

  1. Add embed code to correct environment
  2. Add embed code only once to each page
  3. Initialize the Sidekick by either defining window.gladlyConfig OR calling Gladly.init(), never both

Members

(static) Availability :string

The different availability states that exist:

  • AVAILABLE: Chat agents are ready to receive new chat messages
  • UNAVAILABLE_OFFICE_CLOSED: Chat is unavailable due to office hours
  • UNAVAILABLE_BUSY: Chat is unavailable due to high demand
Type:
  • string

Methods

(static) init(config) → {Promise}

This method initializes the Sidekick on your site using the ID specified in the config parameter. It returns a promise that will resolve when the Sidekick is ready.

Note that init must be called, and the initialization must fully complete (which is signaled when the returned promise is resolved) before calling any other api methods.

Parameters:
Name Type Description
config Gladly.SidekickConfig

Sidekick configuration

Returns:
Type
Promise

(static) getAvailability() → {Gladly.Availability}

This method returns the current chat Availability

Returns:
Type
Gladly.Availability

(static) on(eventName, observer) → {function}

This method subscribes an observer to eventName and returns an unsubscribe function.

Parameters:
Name Type Description
eventName String

The name of the event to subscribe to

observer function

Observer function to be invoked when event triggers

Returns:
Type
function

(static) show()

This method displays the Gladly Sidekick when called.

Example:

<button onClick="Gladly.show()">Start Chat</button>

(static) navigate()

This method is used to notify the Sidekick when your website navigates without reloading the page. Gladly will read the updated location from 'document.location.href'.

Most common use for this would be if you have a single page application and you have rules configured to control what pages the Sidekick is displayed on.

Example:

Gladly.navigate();

Type Definitions

SidekickConfig

Properties:
Name Type Description
appId string

id specifying your own application

Type:
  • Object

Events

availability:change

When availability changes, this event emits current availability.

Parameters:
Type Description
Gladly.Availability

Current availability


Documentation generated by JSDoc 3.5.5 on Fri Jun 14 2019 15:43:38 GMT-0700 (PDT) using the docdash theme.