Salesmate provides you with JavaScript API methods for your website to help you control and customize your Messenger 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 Messenger as per requirement.
login
This method will initiate the Salesmate Messenger 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.
SALESMATE.login({
user_id: '<< user id | string | We recommend to pass user's email id to generate 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:
SALESMATE.login({
user_id: 'john.doe@example.com',
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe',
});
logout
This method clears the Salesmate Messenger 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.
SALESMATE.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.
SALESMATE.update();
SALESMATE.update({user_id: 'samual@example.com', first_name: 'Samual'});
hideChatWidget
This method hides the Messenger if it's open. It will not hide the Messenger launcher button. For example, you can configure your page in such a way that when the user clicks outside the Messenger, this method is called.
SALESMATE.hideChatWidget();
showChatWidget
This method shows the Messenger. It will try to open Messenger's 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 Messenger for promoting your visitors to chat.
SALESMATE.showChatWidget();
showMessages
This method opens up Salesmate Messenger and displays the conversation list.
SALESMATE.showMessages();
showNewMessage
This method opens up Salesmate Messenger 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.
SALESMATE.showNewMessage();
or
SALESMATE.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 Salesmate app. Read more about how to track events inside Salesmate.
SALESMATE.trackEvent('your_event_name',{});
displayLauncher
This method is used to hide or show the Messenger 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.
SALESMATE.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 Messenger launcher.
SALESMATE.customLauncherSelector('#id_name'); or SALESMATE.customLauncherSelector('.class_name');
Events Emitted
Listen to the following events emitted by the Messenger for executing any additional code that's required.
SALESMATE_ON_WIDGET_HIDE
You can listen to the Messenger widget's hide event and execute additional code on your website whenever Messenger is closed.
window.addEventListener('SALESMATE_ON_WIDGET_HIDE', function() {...} );
SALESMATE_ON_WIDGET_SHOW
You can listen to the messenger widget's show event and execute additional code on your website whenever the Messenger is opened.
window.addEventListener('SALESMATE_ON_WIDGET_SHOW', function() {...} );
SALESMATE_ON_WIDGET_COUNT_CHANGE
You can listen to the Messenger widget's count change event and execute additional code on your website whenever the count of unread message changes.
window.addEventListener('SALESMATE_ON_WIDGET_COUNT_CHANGE', function() {...} );
Comments
0 comments
Please sign in to leave a comment.