reactjsintercom

How do I add the Intercom script in my React app?


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
  };
}

Solution

  • 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
            });
        }
        ....
    }