Installing Drift on a React app

by Jason Li

If you're building a React single page application, you may run into some issues with Drift. For example, your playbooks may not trigger on targeted URL's. Here's how you can fix that!

We would recommend taking a look at our Widget API and Javascript SDK documentation to customize when the sidebar or chat widget shows and hides.

If you're using a React Router, you can add the following snippet to your root application component and it should fix things up!

componentWillMount() {
  drift.page(this.props.location.pathname)
}
componentWillReceiveProps(nextProps) {
  if (nextProps.location.pathname !== this.props.location.pathname) {
    drift.page(nextProps.location.pathname)
  }
}

Was this article helpful?