XF 1.4 Integrating Xenforo with Intercom.io

C3JCVSG

Member
Does anyone have experience with integrating Xenforo with Intercom.io?
Below are the instructions that they provide.

Code:
// TODO: Paste this code before </body> on every page where your users are logged in.

<script>
  window.intercomSettings = {
    // TODO: The current logged in user's full name
    name: "<?php echo $user->name; ?>",
    // TODO: The current logged in user's email address.
    email: "<?php echo $user->email; ?>",
    // TODO: The current logged in user's sign-up date as a Unix timestamp.
    created_at: <?php echo strtotime($user->created_at); ?>,
    app_id: “XXX”
  };
</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/XXX';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>
 
Hey
Just installed forum via a sub domain on my site - all looking great.

I want to run intercom.io alongside this software yet unsure of how to join the dots.

Intercom provides some JV code to add to pages you want to track yet I'm unsure of where to place this.

Any ideas?

Thanks
 
Interested also, I cannot get any stats to come through to app.intercom.io
Using the following within template page_container_js_body;
HTML:
<script>
  window.intercomSettings = {
    userid: "{$visitor.user_id}",
    name: "{$visitor.username}",
    created_at: {$visitor.register_date},
    app_id: "xxxx"
  };
</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/xxxx';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>
 
Last edited:
Yeah, I'm surprised this is the only thread on this topic.

You guys will need slightly different code to get this working:

<xen:if is="{$visitor.user_id}">

<script>
window.intercomSettings = {
email: "{$visitor.email}",
created_at: {$visitor.register_date},
app_id: "[APP ID GOES HERE]",
"message_count": {$visitor.message_count},
"trophy_points": {$visitor.trophy_points},
"like_count": {$visitor.like_count},
};

(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 GOES HERE]';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>
</xen:if>
 
You guys will need slightly different code to get this working:
Thanks, so it only reports on known users - not guests - and thus the if around the javascript tracking?

But I still get no results coming through ...

Screen Shot 2015-06-22 at 19.54.18.webp

I've definantly got my app_id correct, cut 'n' pasted from their site.
 
I added this code in the page_container_js_body template:

Code:
<xen:if is="{$visitor.user_id}">

<script>
  window.intercomSettings = {
    app_id: "insert_your_app_id",
    name: "{$visitor.username}", // Full name
    email: "{$visitor.email}", // Email address
    //created_at: <?php echo strtotime($current_user->register_date) ?>, // Signup date as a Unix timestamp
    created_at: {$visitor.register_date}, // Signup date as a Unix timestamp - in xenforo non c'è bisogno di trasformarla
  };
</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/';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>
<xen:else />

<script>
  window.intercomSettings = {
    app_id: "insert_your_app_id"
  };
</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/';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>

</xen:if>

and it works.
 
@Kintaro

I added the code but all i get is a the waiting for your app message when I test the code in intercom.. this is where i added the code ...

Code:
<xen:if is="{$visitor.user_id}">

<script>
  window.intercomSettings = {
    app_id: "xxxxxxxx",
    name: "<?php echo $current_user->name ?>", // Full name
    email: "<?php echo $current_user->email ?>", // Email address
    created_at: <?php echo strtotime($current_user->created_at) ?> // Signup date as a Unix timestamp
  };
</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/xq3cd6vf';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>

</xen:if>
</xen:hook>
</script>
 
Last edited:
basically is from their documentation

I simply added:
my_app_id
{$visitor.username}
{$visitor.email}
<?php echo strtotime($current_user->register_date) ?>
{$visitor.register_date}

that code it's essentially what you need to install intercom.io (free version) on XenForo

I'm interested in add event tracking to, but I haven't had time to add events track code yet.
 
This code is slightly different than the one in this thread.

https://xenforo.com/community/threads/intercom-io-integration.99833/

Which one is the correct one for Intercom.io and Xenforo?

<xen:if is="{$visitor.user_id}">
<script>
window.intercomSettings = {
email: "{$visitor.email}",
created_at: {$visitor.register_date},
app_id: "[ App Id Here ]",
"message_count": {$visitor.message_count},
"trophy_points": {$visitor.trophy_points},
"like_count": {$visitor.like_count},
};
(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 Here ]';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>
</xen:if>

2nd version below

<xen:if is="{$visitor.user_id}">
<script>
window.intercomSettings = {
app_id: "insert_your_app_id",
name: "{$visitor.username}", // Full name
email: "{$visitor.email}", // Email address
//created_at: <?php echo strtotime($current_user->register_date) ?>, // Signup date as a Unix timestamp
created_at: {$visitor.register_date}, // Signup date as a Unix timestamp - in xenforo non c'è bisogno di trasformarla
};
</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/';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>
<xen:else />
<script>
window.intercomSettings = {
app_id: "insert_your_app_id"
};
</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/';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>
</xen:if>


Does anyone know which version is the correct one?

Top line of code or the bottom?
 
Did you manage to get this working?
I'm trying to install the code from Intercom.io as well.
Yes. Here's the relevant code I have in template page_container_js_body ...

Code:
<xen:if is="{$visitor.user_id}">
<script>
  window.intercomSettings = {
    user_id: "{$visitor.user_id}",
    name: "{$visitor.username}",
    created_at: {$visitor.register_date},
    app_id: "<your app id here>",
    "message_count": {$visitor.message_count},
    "trophy_points": {$visitor.trophy_points},
    "like_count": {$visitor.like_count},
  };
</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/<your app id here>';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>
</xen:if>

Replace the 2 x <your app id here> in the above with yours.
 
I'm using this and it works:

Code:
<xen:if is="{$visitor.user_id}">

<script>
  window.intercomSettings = {
    app_id: "APP ID",
    name: "{$visitor.username}", // Full name
    email: "{$visitor.email}", // Email address
    //created_at: <?php echo strtotime($current_user->register_date) ?>, // Signup date as a Unix timestamp
    created_at: {$visitor.register_date}, // Signup date as a Unix timestamp - xenforo doesn't need conversion
    numero_post: {$visitor.message_count}, //message_count
    stato_utente: "{$visitor.user_state}", //user_state
  };
</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/';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>
<xen:else />

<script>
  window.intercomSettings = {
    app_id: "APP ID"
  };
</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/';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>

</xen:if>

I added two attributes:
  1. numero_post (message count)
  2. stato_utente (user state).
You can delete that rows if you don't need them.
 
Back
Top Bottom