Collections

The Gist JavaScript API

By Jitta

updated about 1 month ago

The Gist JavaScript library provides a Gist JavaScript object that responds to a few methods that allow you to update users without a page refresh and interact with the message window. Here is a guide to using the JavaScript API.

Identifying Leads and Users with Gist JavaScript API

Here are the different types of Gist JavaScript API that you can use to connect to other apps.

1. When you want to track logged in uses; for instance, membership site or your SaaS app, and you want to send those users and their data to Gist, use the following code.

gist.identify("12345", {
    "email": "johndoe@tacos.com",
    "name": "John Doe",
    "user_id": "12345"
    "subdomain": "app",
    "last_paid_at" : 1283495946,
});

Please note that for this code to work, user id and email are mandatory attributes. You can also add any number of optional attributes to pass on to Gist.

This is the only method you can use to identify logged in users/customers on Gist.

If you want to identify leads or subscribers who are not registered for membership on your site or app, then you can use the following:

2. If you're sending only the email address and do not want to collect other attributes, then the syntax is:

gist.identify("email_address");

3. If you wish to send other custom attributes along with the email address, then the syntax is:

gist.identify({
    email: "email_address",
    name: "name",
    restaurant_type: "fine_dining"
});

4. This is another variation of the syntax above. If you are already using JavaScript code for identifying logged in users, as mentioned in 1., then you can use the same syntax, along with an empty string for user ID.

gist.identify("", {
    email: "email_address",
    name: "name",
    restaurant_type: "fine_dining"
});

Gist JavaScript API for Chat Messenger

Following is the JavaScript API you can call to show, hide, or load the Gist chat messenger on specific pages and to specific users.

Display the chat messenger

This will display the Gist chat messenger on the page on which this API is called.

If there are no previous conversations with the user, it will open with the new message view. If, however, there are previous conversations with that user, if there are it will open with the message list. To make this happen, you can call the following API.

gist.chat('show')

You can use this API call to show the chat messenger only on specific pages of your website, such as your 'app' or member login area.

Hide the chat messenger

This call will hide the Gist chat messenger panel if it is open on that particular page. It will not hide the Messenger Launcher everywhere in general, but just hides on those pages where this script loads. To make this happen, you can call the following API.

gist.chat('hide');

This is useful if you want to hide the chat messenger by default on a page and only display it when an event is triggered by your users, such as clicking a link or a button.

Launch Gist Messenger on Clicking a Link

You can set up Gist to launch the chat messenger when your users perform a specific event on your website, such as clicking a link or a 'Contact Us' button. To make this happen, you can call the following API.

gist.chat('openNewConversation');

For example, you can add a link anywhere on your site, including HTML text or buttons on a particular page, which when clicked will load the Gist chat messenger ready for a new conversation. This can be used to enable chat to only those users that perform those actions and avoid everyone else.

Example use cases:

API call for loading the chat messenger on link click:

If you have any questions about our pricing, please <a href="#" onclick="gist.chat('openNewConversation')">contact our support team</a>

You can use these two API calls to use a custom launcher for the chat messenger on a specific page.

For instance, if you do not wish to display the chat messenger by default, but only launch it when a user clicks on a link or button on that page, you can use a combination of the gist.chat('hide'); and gist.chat('openNewConversation'); calls to achieve this.

Launch Gist Messenger Without the Messenger Launcher on Button Click

You can launch the Gist Messenger without the Gist launcher using the following API method:

gist.chat('openConversationList');

For example, you can add a link anywhere on your site, including HTML text or buttons on a particular page and turn it into your own custom Gist Messenger launcher.

If you are using jQuery library, here are code sample that demonstrates how you can apply this method:

<script>
    document.addEventListener('gistChatReady', function () {
        gist.chat('openConversationList');
    });
</script>

Note: Call the above-mentioned method only after the chat window gets loaded to your page. If not the conversation list will not be displayed.


Need Help?

If you have any questions, please start a Live Chat. Just "Click" on the Chat Icon in the lower right corner to talk with our support team.

Did this answer your question?