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 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
Lifesaver 👍