如何在我的 React 应用程序中添加 Intercom 脚本?

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

我正在使用 redux-segment 进行分析,并正在尝试实施 Intercom。我遇到的问题实际上是让它加载等。我正在尝试遵循这个,但仍然不确定在哪里输入应用程序 ID 等。 Intercom segment。我想在抓取当前用户时在我的 action creator 中加载对讲机,但是没有关于如何实际加载对讲机的文档。

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

您要做的是将脚本加载到您的 index.html 或您的入口组件中以加载它们的分析对象。 From their docs 你可以这样初始化它

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

接受的答案是正确的。详细:

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