Skip to main content

Install the Intercom Messenger using the JavaScript snippet

Documentation on how to install the Intercom Messenger on traditional websites for both users and visitors/leads.

Written by Matthew Krumwiede
Updated over a month ago

You can install the Intercom Messenger on your website by adding a simple JavaScript snippet to your site’s code. This allows you to engage with both anonymous visitors (leads) and logged-in users.

This guide covers:

  • Installing Intercom for visitors and leads

  • Installing Intercom for logged-in users

  • Best practices for a reliable setup


Before you start

To install Intercom, you’ll need your workspace ID.

You can find this in Settings → Installation → Web.


Install Intercom for visitors and leads

Use this setup if your website does not require users to log in, or if you want Intercom to work before a user signs up.

Step 1: Add the JavaScript snippet

Copy and paste the following code just before the closing </body> tag on every page of your site:

<script>
window.intercomSettings = {
app_id: "YOUR_APP_ID"
};
</script>

<script>
(function(){
var w=window;
var ic=w.Intercom;
if(typeof ic==="function"){
ic('reattach_activator');
ic('update',w.intercomSettings);
} else {
var d=document;
var i=function(){i.c(arguments);};
i.q=[];
i.c=function(args){i.q.push(args);};
w.Intercom=i;
var l=function(){
var s=d.createElement('script');
s.type='text/javascript';
s.async=true;
s.src='https://widget.intercom.io/widget/YOUR_APP_ID';
var x=d.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s,x);
};
if(document.readyState==='complete'){
l();
} else if(w.attachEvent){
w.attachEvent('onload',l);
} else {
w.addEventListener('load',l,false);
}
}
})();
</script>

Replace YOUR_APP_ID with your actual Intercom workspace ID.


What happens next?

  • The Messenger will appear on your site.

  • Visitors will be tracked as leads once they interact with the Messenger or provide their email.

  • You can start conversations with visitors in real time.


Install Intercom for logged-in users

If your website has user accounts, you can pass user data to Intercom so conversations are tied to known users.

Step 1: Update the intercomSettings

When a user is logged in, include their details in the snippet:

<script>
window.intercomSettings = {
app_id: "YOUR_APP_ID",
name: "Jane Doe",
email: "[email protected]",
user_id: "123456"
};
</script>

Recommended user fields

  • user_id (recommended) – A unique ID from your system

  • email – The user’s email address

  • name – The user’s full name

This ensures:

  • Conversations are tied to the correct user

  • You can view user history and attributes inside Intercom


When should this load?

Make sure this version of the snippet is loaded only when the user is logged in.

If no user is logged in, fall back to the visitor version.


Best practices

1. Handle logout correctly

When a user logs out, reset Intercom to avoid showing the previous user’s data:

Intercom('shutdown');

This clears the current session and ensures the next visitor starts fresh.


2. Keep user data accurate

Make sure the data you pass (like email and user_id) is:

  • Consistent across sessions

  • Unique to each user

This prevents duplicate users in Intercom.


3. Install on every page

For traditional multi-page websites, the snippet should be included on all pages so the Messenger works consistently.


4. Set the correct regional API (if applicable)

If your workspace is hosted outside the US, include the api_base field:

Europe (EU)

api_base: "https://api-iam.eu.intercom.io"

Australia (AU)

api_base: "https://api-iam.au.intercom.io"

Example:

window.intercomSettings = {
app_id: "YOUR_APP_ID",
api_base: "https://api-iam.eu.intercom.io"
};

Troubleshooting tips

  • Messenger not showing?

    • Check your app_id is correct

    • Make sure the snippet is on the page

    • Confirm there are no JavaScript errors

  • Users not appearing correctly?

    • Ensure user_id or email is being passed consistently

    • Avoid changing identifiers between sessions


What’s next?

Once installed, you can:

  • Customize the Messenger in Intercom settings

  • Set up automated messages

  • Start live chats with visitors and users

Did this answer your question?