GUURU for Developers

GUURU for Developers

  • Docs
  • Contacts

›Loader

Loader

  • Getting Started
  • Public Interface
  • Handling Events
  • Conversion
  • Cookies
  • Examples

SmartChat

  • Getting started
  • Chat Widget

    • Getting started
    • Parameters

SmartForm

  • Getting Started

Admin API

  • Getting started
  • Examples
  • API Reference

    • Queries
    • Mutations
    • Types
    • Pagination

Webhooks

  • Getting started
  • Examples

Integrations

  • Facebook
  • Freshchat
  • Salesforce
  • Zendesk
  • Microsoft
  • Third Party Messaging

Handling Events

The loader supports registering functions to be called on certain events. This allows you to extend it's behavior by adding custom code to handle the events in which you are interested.

Registering an event handler

During the initialization you can define a key named events which should be an array of objects, each containing the keys id and handler.

window.guuru = window.Guuru();
window.guuru.init({
  appId: '<YOUR_APP_ID>',
  locale: 'en',
  events: [{
    id: 'loader:initialized',
    handler: function () {
      console.log('Chat loader initialized!');
    },
  }],
});

Available events

The list belows contains all available events that can be registered. Some events will pass the callee some associated data. These are also described below.

For events which have associated data the handler function should be defined as function (eventId, data) { ... }.

Event IDDescriptionData
loader:initializedChat loader is initialized{enabled: true}
loader:chatOpenedChat window has been opened{}
loader:chatClosedChat window has been closed{}
chat:initializedChat window is initialized{}
chat:newChatNew chat flow has started{}
chat:loadExistingChatResuming an existing chat{}
chat:questionUser wrote a question{ val: "<question>" }
chat:nameUser types his name{ val: "<name>" }
chat:emailUser types his email{ val: "<email>" }
chat:categoryUser picks a category{ val: "<category>" }
chat:smsFallbackPhoneNumberUser types his phone{ val: "<phone>" }
chat:chatCreatedChat is created{ val: chatId }
chat:chatWithExpertUser wrote a message{ val: "<message>" }
chat:rateClickUser clicked the "Rate expert" button{}
chat:reopenChatUser reopens closed chat{}
chat:rateExpertUser rated the guuru{ val: “<yes, partial, no>" }
chat:newChatClickAfter finishing a chat, the user starts a new one{}
chat:expertConnectedA guuru joined the chat{ val: <duration in seconds> }
chat:quickActionSubmittedUser selected a quick action{ val: quickActionId }
chat:bot:welcomeBot displayed welcome message{}
chat:bot:requestPartnerSelectionRequested partner selection{}
chat:bot:requestNameBot requested user's name{}
chat:bot:requestCategoryBot requested question category{}
chat:bot:requestEmailBot requested user's e-mail{}
chat:bot:connectingWithExpertBot says "connecting with expert"{}
chat:bot:connectedWithExpertBot says "you are connected with expert{}

Chat loader loaded event

The previous events can only be registered after the window.Guuru function is already available.

If you load the script synchronously, i.e., using a <script src="..."></script> tag then the browser will block until the script is downloaded and ran, so window.Guuru will be available in any subsequent scripts.

However, in some cases, it might be useful to load the script asynchronously by either using the keywords async or defer in the <script> tag or by loading the script via javascript.

In those cases you need to know when the script is loaded in order to be able to initialize the chat loader, otherwise you may end up trying to use the window.Guuru() function before it is defined. To solve this problem there is an extra event named guuru:loaded that is emitted when the loader is ready.

const initChatloader = function () {
  window.guuru = window.Guuru();
  window.guuru.init({
    appId: '<YOUR_APP_ID>',
    locale: 'en',
  });
};

if ('Guuru' in window) {
  initChatloader();
} else {
  document.addEventListener(
    'guuru:loaded',
    () => initChatloader(),
    { once: true },
  );
}
← Public InterfaceConversion →
  • Registering an event handler
  • Available events
  • Chat loader loaded event
GUURU for Developers
Docs
SmartChatSmartFormAPI Reference
Community
GitLabFacebookLinkedIn
Copyright © 2023 GUURU Solutions Ltd.