Intercom + Discourse

Hey team,

Is it possible to also add Intercom to my Discourse forum?

I would need to add an Intercom javascript snippet to my Discourse forum.

I appreciate any ideas and insight.

Thank you!

1 Like

Go to
Admin -> customize -> theme -> Edit CSS/html
There you can add javascript in the head or in the footer :slight_smile:

6 Likes

Thank you very much for the helpful reply!

I have placed the code below within the area (please see attached image).

So far I have not been able to load the Intercom messenger, but I will continue working on this and will post my results.

<script>

window.intercomSettings = {
app_id: “m866jl5z”,
name: <%= current_user.name %>, // Full name
email: <%= current_user.email %>, // Email address
created_at: <%= current_user.created_at.to_i %> // Signup date as a Unix timestamp
};

1 Like

This is in part based on @jesselperry’s previous comment, but updated with the latest Intercom messenger and implemented according to Intercom’s setup guide for single page apps. The following is what I have and it seems to be working ok.

First add this to the </head> section:

<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/[YOUR_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>

And add this to the </body> section:

<script>
$.getJSON("https://[YOUR_DISCOURSE_DOMAIN]/session/current.json", function(json){
    var currentusernamefromjson = String(json.current_user.username);
    var currentuserflname = String(json.current_user.name);
    var fulllinktojson = "https://[YOUR_DISCOURSE_DOMAIN]/users/" + currentusernamefromjson + ".json";
    $.getJSON(fulllinktojson, function(json){
        var currentuseremail = String(json.user.email);
        var currentuserid = String(json.user.id);

        window.Intercom('boot', {
            app_id: '[YOUR_APP_ID]',
            email: currentuseremail,
            name: currentuserflname,
            "discourse_username": currentusernamefromjson,
            "discourse_uid": currentuserid
        });
    });
});
</script>

Make sure to replace [YOUR_APP_ID] with your Intercom app ID, and [YOUR_DISCOURSE_DOMAIN] with your domain (and change https to http if that’s what you use).

5 Likes

Thanks so much for posting this.

I tried inserting the code with my app ID and discourse forum URL, but I still can’t get it working.

Below is what I have added to my head section:

 <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/m866jl5z';
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>
<script>
window.Intercom('boot', {
   app_id: 'm866jl5z',
   custom_launcher_selector: '#my_custom_link' 
});
</script>
<script>
window.Intercom('boot', {
   app_id: 'm866jl5z',
   email: 'example@example.com',
   user_id: 'abc123',
   created_at: 1234567890,
   custom_launcher_selector: '#my_custom_link' 
});
</script>
<script>
$(window).scroll(function() {

    if ($(this).scrollTop() > 120)
     {
        $('.crunchify-container').fadeIn();
     }
    else
     {
      $('.crunchify-container').fadeIn();
     }
 });
</script>
<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/m866jl5z';
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>

And here is what I have added to my body section:

<script>
$.getJSON("https://community.myfishingcapecod.com/session/current.json", function(json){
    var currentusernamefromjson = String(json.current_user.username);
    var currentuserflname = String(json.current_user.name);
    var fulllinktojson = "https://community.myfishingcapecod.com/users/" + currentusernamefromjson + ".json";
    $.getJSON(fulllinktojson, function(json){
        var currentuseremail = String(json.user.email);
        var currentuserid = String(json.user.id);

        window.Intercom('boot', {
            app_id: 'm866jl5z',
            email: currentuseremail,
            name: currentuserflname,
            "discourse_username": currentusernamefromjson,
            "discourse_uid": currentuserid
        });
    });
});
</script>

I reached out to the Intercom support team as well, so I will post back any solutions if I find any.

Obviously I appreciate any insight anyone here on this forum may also be able to provide to help me get Intercom working with Discourse. Thank you all for the helpful posts thus far :+1:

Now there are an Advanced Discourse Intercom plugin and also an Intercom widget to integrate Intercom with Discourse.

4 Likes