Last active
March 31, 2021 19:10
-
-
Save tinyfly/fdf54885770f3a16d47888a014720ff3 to your computer and use it in GitHub Desktop.
Start up the Intercom Respond widget being sure to clear previous user's conversations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Boots up Intercom (intercom.io). This should be run on page load | |
* @param {String} APP_ID - Your Intercom app id | |
* @param {Function} moment - moment.js | |
* @param {Object} [user] - information about the logged in user | |
*/ | |
startupIntercom(APP_ID, moment, user) { | |
// basic settings for all users | |
const intercomSettings = { | |
app_id: APP_ID, | |
custom_launcher_selector: '.js-intercom' | |
}; | |
// Do an initial startup with just the basic settings. | |
Intercom('boot', intercomSettings); | |
// flush out any previous cookie before starting up to prevent seeing | |
// other user's conversations on the same computer this can only be done properly | |
// if 'boot' has already been triggered. | |
// | |
// if this was a single-page app then you could just run this by itself when a user logs out | |
Intercom('shutdown'); | |
// add user specific settings | |
if (user) { | |
intercomSettings.user_id = user.id; | |
intercomSettings.name = user.name; | |
intercomSettings.email = user.email; | |
intercomSettings.created_at = moment( user.created_at, 'YYYY-MM-DD HH:mm:ss').unix(); | |
} | |
// start up the intercom client for real | |
Intercom('boot', intercomSettings); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use Respond with both anonymous users and authenticated users a person can potentially see someone else's conversations if they use the same computer. Looking through the Intercom docs they state to be sure to run the 'shutdown' method when a user logs out of the app. This is pretty straight-forward if you have a single-page app where JavaScript handles logging out just call
Intercom('shutdown')
at the same time you log out the user.However in a traditional application where the browser does a round-trip to the server to handle authentication then it is a bit more difficult. My solution was to manually boot Intercom on page load, call the shutdown method to clear any previous cookies, and then boot up Intercom again to refresh the session.