Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
  };
}
like image 591
joethemow Avatar asked Feb 22 '17 04:02

joethemow


People also ask

How do you integrate Intercom chat?

After starting an Intercom trial, just copy the code snippet under "Add chat to your website" on the home tab. Paste the code right before the closing body tag of every page where you want the Intercom Messenger to appear. After adding the code, open your website and the Messenger will appear.

How do you add JavaScript to react app?

Installation: Open a terminal inside your ReactJS project folder and write the following code to install react-script-tag Package. Import 'ScriptTag' component: Import the built-in 'ScriptTag' component from the react-script-tag library at the top of the file where we want to add the script tag.


2 Answers

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
        });
    }
    ....
}
like image 198
John Ruddell Avatar answered Sep 18 '22 00:09

John Ruddell


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

like image 27
user Avatar answered Sep 17 '22 00:09

user