Skip to content

Instantly share code, notes, and snippets.

@hijonathan
Created February 28, 2017 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hijonathan/100fb9f372121dfec15ed3a9fa633d26 to your computer and use it in GitHub Desktop.
Save hijonathan/100fb9f372121dfec15ed3a9fa633d26 to your computer and use it in GitHub Desktop.
Send Appcues form responses into Intercom
// Add the following snippet to your application after loading Appcues and Intercom.
Appcues.on('form_submitted', function(data) {
var responses = {};
// Intercom doesn't like special characters.
var slugify = function(str) {
return str.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '');
};
// Loop through the responses and add them as user properties.
if (data.interaction && Array.isArray(data.interaction.response)) {
data.interaction.response.forEach(function(res) {
responses[slugify(response.label)] = response.value;
});
// Send the responses to Intercom as user properties.
// This also checks for new messages.
Intercom('update', responses);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment