Identify users using Intercom Messenger
When a user supplies their email in an Intercom messenger session, sending the identified user to AnalyticsJS requires a small update to your Intercom implementation.
Step 1 – Set up Messenger per the Intercom documentation:
Follow the directions here to install and launch Messenger on your webpage. What is most needed is the Intercom
object referenced in the article that is created in the Window
global object.
For example:
window.Intercom('boot', {
app_id: 'abc12345',
email: '[email protected]',
created_at: 1234567890,
name: 'Jane Doe',
user_id: '9876'
});
Step 2 – Add a listener for the onUserEmailSupplied event:
Per the documentation, add a listener for the onUserEmailSupplied
event.
For example:
window.Intercom('onUserEmailSupplied',
function () {
// add logic to find email address
}
)
Step 3 – Locate email address in the form:
This event does not provide the email address, which means the email address will need to be extracted from the form.
The code that goes here is highly dependent on your implementation and will require some knowledge of the inner workings of the form containing the email address.
Once the email address is extracted, it's simply an identify call using analyticsJS, as described here.
For example:
window.Intercom('onUserEmailSupplied',
function () {
const intercom_iframe = document.querySelector(".intercom-messenger-frame").children[0];
const email = intercom_iframe.contentDocument.body.querySelector('input[type="email"]')?.value;
analytics.identify('[email protected]', {
name: 'Jane Doe', // optional
email: '[email protected]'
});
}
)
Step 4 – Verify Setup:
To verify that the setup is complete, please see this article which explains how to confirm that the "Identify" call is being made correctly when an email address is supplied by the user.