Last active
November 30, 2018 17:55
-
-
Save fIa5h/662d0d29e872768f86614019c6f91fec to your computer and use it in GitHub Desktop.
This Intercom installation script dynamically captures query string parameters and enables you to map them into CDAs. Please follow the INSTRUCTIONS section in the comments, then please remove comments and set your APP_ID before using. This should be installed the same as the standard Intercom installation, like so: https://developers.intercom.c…
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
<script> | |
/* | |
INSTRUCTIONS | |
To begin syncing these parameters with SFDC you will need to excplitly reference | |
them as qualification attributes in your Intercom Qualification Data settings in the Intercom UI: | |
https://www.intercom.com/help/faqs-and-troubleshooting/capture-qualify-and-convert-leads/what-is-qualification-data | |
Then, you will need to map those qualification attributes to your SFDC lead fields in the Intercom UI. | |
See the "Map and sync your qualification attributes" section of this document: | |
https://www.intercom.com/help/apps-in-intercom/apps/salesforce-app | |
*/ | |
//Set your APP_ID | |
var APP_ID = "** YOUR APP ID **"; | |
//Our function that gets the parameters | |
var getParameterByName = function() { | |
var result = {}; | |
var params = (window.location.search.split('?')[1] || '').split('&'); | |
for (var param in params) { | |
if (params.hasOwnProperty(param)) { | |
paramParts = params[param].split('='); | |
//Decode the query string value for easy use in the UI | |
result[paramParts[0]] = decodeURIComponent(paramParts[1] || ""); | |
} | |
} | |
return result; | |
} | |
//Get the parameters | |
var params = getParameterByName(); | |
//Instantiate our window.intercomSettings object | |
window.intercomSettings = { | |
app_id: APP_ID | |
}; | |
//Now, if we have parameters, let's dynamically map them to window.intercomSettings | |
if (!!params && typeof params == "object") { | |
Object.keys(params).map(function(key) { | |
//Validate the values | |
if (!!key && key != "" && !!params[key] && params[key] != "") { | |
try { | |
var value = params[key]; | |
window.intercomSettings[key] = value; | |
} catch (e) {} | |
} | |
}); | |
} | |
//Then the standard Intercom instantiation script | |
(function() { | |
var w = window; | |
var ic = w.Intercom; | |
if (typeof ic === "function") { | |
ic('reattach_activator'); | |
ic('update', intercomSettings); | |
} else { | |
var d = document; | |
var i = function() { i.c(arguments) }; | |
i.q = []; | |
i.c = function(args) { i.q.push(args) }; | |
w.Intercom = i; | |
function l() { | |
var s = d.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; | |
s.src = 'https://widget.intercom.io/widget/' + APP_ID; | |
var x = d.getElementsByTagName('script')[0]; | |
x.parentNode.insertBefore(s, x); | |
} | |
if (w.attachEvent) { w.attachEvent('onload', l); } else { w.addEventListener('load', l, false); } | |
} | |
})() | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment