9

I'm using redux-segment for my analytics and am trying to implement Intercom. The issue I am having is actually getting it to load etc. I'm trying to follow this, but still unsure on where to enter the app id, etc. Intercom segment. I am want to load intercom in my action creator when grabbing the current user, but there is no documentation on how to actually load intercom.

import { EventTypes } from 'redux-segment';

export function currentUser() {

  const request = user.current(); //this correctly grabs current user.

  if(request == null) {
     //having trouble with this part. load intercom non user specific
  } else {
     load intercom user specific
  }

  return {
    type: CURRENT_USER,
    payload: request
  };
}
frandroid
  • 1,343
  • 16
  • 26
joethemow
  • 1,641
  • 4
  • 24
  • 39
  • 1
    [if you look at their docs](https://developers.intercom.com/docs/single-page-app), just like almost any other analytics provider, you need to load the analytics via a script tag in your html file which assigns intercom to your window and then you have access to it. – John Ruddell Feb 22 '17 at 05:55
  • Yeah I figured that out by putting it in the index.html but I dont want to load it there. Is it possible to load it in my index.js? – joethemow Feb 22 '17 at 06:42
  • 1
    sure yea I mean its just javascript. just run that javascript code inside a componentWillMount or something and it should have the same effect. – John Ruddell Feb 22 '17 at 06:46
  • Yup that did the trick, thanks – joethemow Feb 22 '17 at 06:51
  • 1
    ok cool! i just wrote up an answer so we can close this question! :) – John Ruddell Feb 22 '17 at 07:23

2 Answers2

7

What you want to do is put the script to load intercom either in your index.html or in your entry component to load their analytics object. From their docs you can initialize it like this

class MyComponent extends Component {
    constructor(props){
        super(props);
        window.Intercom('boot', {
          app_id: INTERCOM_APP_ID,
          // other settings you'd like to use to initialize Intercom
        });
    }
    ....
}
John Ruddell
  • 25,283
  • 6
  • 57
  • 86
  • 1
    @damianesteban The OP had the code to run and was looking for where to run it and didn't provide it in the question... My answer was related to the scope of the question, that being said I'd be happy to pull in the specific initialization information from the docs site. I would generally recommend looking at the docs they provide first before looking at SO for a way to initialize. – John Ruddell May 19 '20 at 00:36
5

Accepted answer is correct. In detail:

class LandingPage extends Component {

  constructor(props) {
    super(props);

    // initialize intercom (don't forget to *update* when page changes)
    window.Intercom("boot", {
      app_id: "your_app_id"
    });
  }
}

https://app.intercom.io/a/apps/bhfx1oqj/messages/guide/identify_your_users/track_users

user
  • 3,388
  • 7
  • 33
  • 67