Created
February 28, 2017 22:42
-
-
Save hijonathan/100fb9f372121dfec15ed3a9fa633d26 to your computer and use it in GitHub Desktop.
Send Appcues form responses into Intercom
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
// 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