1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Integrating Xenforo with Intercom.io

Discussion in 'Styling and Customization Questions' started by C3JCVSG, Nov 6, 2014.

  1. C3JCVSG

    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>
    
     
  2. C3JCVSG

    C3JCVSG Member

  3. Ru Anderson

    Ru Anderson Member

    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
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    JV code?
    Do you mean JavaScript?

    If so, the FAQ in my signature explains where custom JS can be added.
     
  5. Ru Anderson

    Ru Anderson Member

    Thanks man - I found it!
     
  6. mrrobbo

    mrrobbo Member

    How did you go with your Interom integration; I'm about to connect these together and would love some assistance and any insight you gathered
     
  7. Mouth

    Mouth Well-Known Member

    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: Jun 21, 2015
  8. Ru Anderson

    Ru Anderson Member

    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>
     
  9. Mouth

    Mouth Well-Known Member

    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.png

    I've definantly got my app_id correct, cut 'n' pasted from their site.
     
  10. Kintaro

    Kintaro Well-Known Member

    is someone using it? it works?
     
  11. C3JCVSG

    C3JCVSG Member

    I've used it, it works but has become costly following their recent price increase.
     
  12. Kintaro

    Kintaro Well-Known Member

    oh ok
    I'm interested in the free "observe" package.
     
  13. Kintaro

    Kintaro Well-Known Member

    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.
     
  14. Mark Thompson

    Mark Thompson Member

    @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: Aug 27, 2015
  15. Kintaro

    Kintaro Well-Known Member

    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.
     
  16. Mark Thompson

    Mark Thompson Member

    Thanks, got it and it's working..
     
  17. craigbeckta

    craigbeckta Member

    I know this is an old thread but...

    Did you manage to get this working?

    I'm trying to install the code from Intercom.io as well.
     
  18. craigbeckta

    craigbeckta Member

    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?
     
  19. Mouth

    Mouth Well-Known Member

    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.
     
  20. Kintaro

    Kintaro Well-Known Member

    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.
     

Share This Page