Integrating OpenReplay with Slack in a Web Application
Tags: react, javascript, tutorial
Published: 2021-09-12 16:30:59

_by autor [Samaila Bala](https://blog.openreplay.com/authors/samaila-bala)_

Session replay is a powerful tool to be able to get user's insights from a web application. It provides a way to replay a user's journey in a web application and investigate errors the user faced while using the application. [OpenReplay](https://openreplay.com/) is an open-source session replay tool that makes it easier to replay user sessions and troubleshoot issues. In this article, we will be looking at how to share sessions recorded by OpenReplay in a web application with teammates on [Slack](https://slack.com/).

This tutorial assumes you know how to deploy OpenReplay to a platform of your choice, if not you can follow any of the guides listed [here](https://docs.openreplay.com/deployment) to get started. You will also need the below elements to follow along:

- Knowledge of JavaScript and React
- Node.js v12 or greater
- npm
- Access to a Slack workspace

## Creating a Web Application

We will be creating a basic web application to fetch data from an API using React. To get started open a terminal and run the code below

```
npx create-react-app sample-app
```

The above command bootstraps an application  with [Create React App](https://create-react-app.dev/). After the process is complete. Navigate to the created app folder and run the command below to start the application


```
npm start
```

We will be creating a little application that guesses the age of a user based on the name. Open up the `App.js` file in a code editor and replace the code with the code below


```javascript
import React, { useState } from 'react';
import './App.css';
function App() {
  const [name, setName] = useState('');
  const [age, setAge] = useState(0);
  const [isLoading, setIsLoading] = useState(false);
  const [isError, setIsError] = useState(false);
  const handleSubmit = async () => {
    try {
      setIsLoading(true);
      setIsError(false);
      const response = await fetch(`https://api.agify.io/?name=${name}`);
      const { age } = await response.json();
      setIsLoading(false);
      if (age === null) {
        setIsError(true);
        throw new Error('Error fetching age');
      }
      setAge(age);
      return;
    } catch (error) {
      setIsLoading(false);
      setIsError(true);
      console.log(error);
      throw new Error('Error getting data');
    }
  };
  return (
    <main>
      <h1> Guess your Age</h1>
      <input
        type="text"
        aria-label="Enter your name"
        placeholder="Enter your name"
        value={name}
        onChange={(e) => setName(e.target.value)}
        required
      />
      <button onClick={handleSubmit}>Submit</button>
      {isLoading && <p>Guessing age...</p>}
      {!isLoading && isError && <p>Error guessing age</p>}
      {!isLoading && age > 0 && age !== null && (
        <p>Your are {age} years old.</p>
      )}
    </main>
  );
}
export default App;
```


The code above accepts a value as input and when a user clicks on the submit button. It makes a call to an api to guess the age based on the input available. Save and view the application in your browser.


![Demo Application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x567tw15o4g6ydg11rls.png)

## Open Source Session Replay
Debugging a web application in production may be challenging and time-consuming. [OpenReplay](https://github.com/openreplay/openreplay) is an Open-source alternative to FullStory, LogRocket and Hotjar. It allows you to monitor and replay everything your users do and shows how your app behaves for every issue. 
It’s like having your browser’s inspector open while looking over your user’s shoulder.
OpenReplay is the only open-source alternative currently available.

![OpenReplay](https://raw.githubusercontent.com/openreplay/openreplay/main/static/replayer.png)

Happy debugging, for modern frontend teams - [Start monitoring your web app for free](https://github.com/openreplay/openreplay).



## Connecting OpenReplay to a Web Application

Now that we have a working application the next step is integrating OpenReplay so we can start replaying the activities performed by users on the application.  OpenReplay provides a JavaScript library that makes integration into web applications easy. Open a terminal in the root of your application and run the code below to install the OpenReplay SDK


```
npm i @openreplay/tracker
```

After installation :

1. Go to your deployed OpenReplay instance and click on “Add New Project”
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l34kf9jzb02ufn1n7qsx.png)

2. Enter the name of the project in the modal that comes up and click on Add to create the project
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tyd34zz6vy3z631lplqa.png)

3. Click the Settings icon to go to Preferences


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c2n3xykh4wq72c7fcrb.png)

4. Select Projects


5. Click on the “Tracking code” button for the Project created 
6. Copy the code in the usage section
7. Open the `App.js` file and paste the copied code before the begininning of the `App` function

Our `App.js` file should now look like the code below


```javascript
import React, { useState } from 'react';
import Tracker from '@openreplay/tracker';
import './App.css';

const tracker = new Tracker({
  projectKey: "your project key",
  ingestPoint: "your injest point url",
});
tracker.start();
function App() {
  const [name, setName] = useState('');
  const [age, setAge] = useState(0);
  const [isLoading, setIsLoading] = useState(false);
  const [isError, setIsError] = useState(false);
  const handleSubmit = async () => {

//... the rest of the original code
```


The next step after this is deploying your app as OpenReplay’s tracking only works on a live environment, so commit your code to a repository and deploy the app to platforms like [Netlify](https://www.netlify.com/) and [Vercel](https://vercel.com/) ([here is a quick tutorial](https://blog.openreplay.com/step-by-step-guide-to-building-and-deploying-a-vue-js-app-with-netlify-in-2021) on how to deploy your app on Netlify)

After deploying, visit the deployed app and perform some operations so OpenReplay can track and record the session.

**Note:** You have to close the window or tab of the deployed app when you’re done so OpenReplay can finish recording that particular session.

After recording a session, visit your OpenReplay dashboard to check the recorded session, it usually takes about 4 minutes after terminating a session for it to reflect on the OpenReplay dashboard so  be patient if you don’t see the recorded session immediately.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy6ffd6eu79w07i400sg.png)

## Connecting OpenReplay to Slack

At this point, we have successfully integrated OpenReplay into our application and can now replay user sessions to view actions performed and errors that occurred. The next step is connecting OpenReplay with Slack so you can share these recorded sessions with teammates in a Slack group.


1. Sign in to your Slack workspace and go to the [app creation page](https://api.slack.com/apps?new_app=1)
2. Click on “Create new app”
3. Select “From scratch” on the modal that pops up
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48esrg3woxzk3zqelu7f.png)

4. Enter “OpenReplay” as the name of the app
5. Select the workspace and save
6. Select Incoming Webhooks from the sidebar of the created app
7. Switch on the “Activate Incoming Webhooks”
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ks241hser1c1wrqyoshz.png)

8. Click on “Add new Webhook” and select the channel to share the recorded sessions to
9. Click “Allow” and copy the webhook URL
10. Go to OpenReplay dashboard then 'Preferences > Integration'
11. Select Slack and paste the copied Webhook URL before clicking 'Add'
12. You should get a welcome message similar to the screenshot below
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4n3zhyvd4a88dv8qi4fu.png)


 
 We are done connecting Slack to OpenReplay to share a recorded session to a Slack Group:
 
 1. Go to the OpenReplay dashboard
 2. Click on the recorded session
 3. Click on the Share button on the top right corner of the page

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3pbl3rqanfroxj8l3mb.png)


 
You can now share recorded sessions with team mates in a Slack group. The message will be similar to the screenshot below.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgbimdeh4zbg1k1zz3wp.png)


## Conclusion

In this article, we’ve looked at how to connect OpenReplay to a web application and integrate slack with OpenReplay. This makes it easy for you to share recorded sessions of users who use your application with teammates on slack to foster collaboration and help resolve issues quickly.

OpenReplay also has a supportive community on [Slack](https://slack.openreplay.com/) to help you with issues you come across.