Interact with your Users
Once you have the Messenger installed and configured on your site you may want to look at some of the other options that are available to interact with your users. You may want, for example, to create events for certain actions that your users are taking. You will also need to update your users based on certain information such as a form they have filled out or an update to their profile. And you will also want to understand how to properly shutdown users sessions to ensure conversations are properly closed in certain situations. We will go through these options here.
Intercom('update')
Calling the update method without any other arguments will trigger the JavaScript to look for new messages that should be displayed to the current user (the one whose details are in the window.intercomSettings variable) and show them if they exist.
Intercom('update');
Calling the update method with a JSON object of user details will update those fields on the current user in addition to logging an impression at the current URL and looking for new messages for the user.
Intercom('update', {"name": "Inigo Montoya"});
If the person's ID is not found in the user list when calling the update, a new user will be created.
Update Throttling
You can call Intercom('update') without getting throttled up to 20 times per 30 minutes. After the 20th call, you'll be throttled and the quota of 20 calls will get reset every 30 minutes. Reloading the page will refresh this state.
Intercom('trackEvent')
You can submit an event using the trackEvent method. This will associate the event with the currently logged in user and send it to Intercom. The final parameter is a map that can be used to send optional metadata about the event.
Intercom('trackEvent', 'invited-friend');
Events With Metadata
You can also add custom information to events in the form of event metadata.
var metadata = {
invitee_email: '[email protected]',
invite_code: 'ADDAFRIEND'
};
Intercom('trackEvent', 'invited-friend', metadata);
Intercom('shutdown')
If you have the Inbox product (combined with another product like Messages) you should call the Intercom shutdown method to clear your usersโ conversations anytime they logout of your application. Otherwise, the cookie we use to track who was most recently logged in on a given device or computer will keep these conversations in the Messenger for one week. This method will effectively clear out any user data that you have been passing through the JS API.
Intercom('shutdown');
Shutdown Intercom Properly
For more information on how to properly shutdown Intercom please see our example here
Interactive Example
The above link is to a Codepen where you can test the different options outlined here. Codepen allows you to copy and paste code into an JS (or HTML and CSS) editor where you see the results immediately. You can use your own App ID if you have one or your can user our test example App ID, whatever you find easier. For more info on Codepen and how to use it with Intercom please see this page
Updated over 6 years ago