Skip to main content
Skara provides you with JavaScript API methods for your website to help you control and customize your Chats widget behavior. You can use these methods in your website code to get the desired behavior.

Methods

  • The following methods can be used by the developers, in your code to customize the behavior of the Chats as per requirement.
Login
  • This method will initiate the Skara Chats with the information provided by you as a form of an object. You can call this method in the situation where contact/visitor is not logged in when the page is loaded. You can also use this method to update the information of the contact that is logged in. Verify your contact by calling this method and passing the email in user_id, for example in your customer’s login page call this method when the login button is clicked.
SKARA.login({
  user_id: "<< user id | string | We recommend passing the user's email id to generate a unique key >>",
  email: "<< email | string | pass a valid email address >>",
  first_name: "<< first name of contact | string >>",
  last_name: "<< last name of contact | string >>"
});
Example:
SKARA.login({
  user_id: "[email protected]",
  email: "[email protected]",
  first_name: "John",
  last_name: "Doe"
});
Logout
  • This method clears the Skara Chats session of the contact/visitor. Call this method when the user logs out from your application. Otherwise, the cookies will keep tracking new events for the user who was logged in before from the specific machine.
SKARA.logout();
Update
  • This method is used to update the data of existing contact, which is logged in from the widget side. You can update the name, email, or any other data of contact fields that Salesmate provides, but you must provide the user_id with the data you wish to update.
SKARA.update();
SKARA.update({ user_id: "[email protected]", first_name: "Samual" });
hideChatWidget
  • This method hides the Chats if it’s open. It will not hide the Chats launcher button. For example, you can configure your page in such a way that when the user clicks outside the Chats, this method is called.
SKARA.hideChatWidget();
showChatWidget
  • This method shows the Chats. It will try to open Chats last available state; otherwise, it will open the home screen. For example, you can call this method when the page reloads or when a certain button is clicked to open the Chats for promoting your visitors to chat.
SKARA.showChatWidget();
showMessages
  • This method opens up Skara Chats and displays the conversation list.
SKARA.showMessages();
showNewMessage
  • This method opens up Skara Chats and displays the screen to start a new conversation. Also if you provide a message as a parameter then the editor will come up preloaded with your message.
SKARA.showNewMessage();
// or
SKARA.showNewMessage("Hello there");
trackEvent
  • This method helps you to track new events which visitor/contact performs on your website. You can also add further information to this event which will be visible inside your Skara app. Read more about how to track events inside Skara.
SKARA.trackEvent("your_event_name", {});
displayLauncher
  • This method is used to hide or show the Chats launcher button on your website. If you need to hide or show the launcher on some specific pages of your site then this method can be used.
SKARA.displayLauncher(false);
customLauncherSelector
  • This method enables you to define any custom id or class of the HTML elements where, if your website visitor clicks then it will open the Chats launcher.
SKARA.customLauncherSelector("#id_name");
// or
SKARA.customLauncherSelector(".class_name");
Events Emitted
  • Listen to the following events emitted by the Chats for executing any additional code that’s required.

SKARA_ON_WIDGET_HIDE

You can listen to the Chats widget’s hide event and execute additional code on your website whenever Chats is closed.
window.addEventListener("SKARA_ON_WIDGET_HIDE", function () {
 // Your code here
});

SKARA_ON_WIDGET_SHOW

You can listen to the Chats widget’s show event and execute additional code on your website whenever the Chats is opened.
window.addEventListener("SKARA_ON_WIDGET_SHOW", function () {
 // Your code here
});

SKARA_ON_WIDGET_COUNT_CHANGE

You can listen to the Chats widget’s count change event and execute additional code on your website whenever the count of unread message changes.
window.addEventListener("SKARA_ON_WIDGET_COUNT_CHANGE", function () {
 // Your code here
});