Integrating OpenReplay with GitHub
Tags: webdev, testing, tutorial
Published: 2021-11-08 04:55:44

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

Recreating a user’s journey when they use your application goes a long way in resolving issues and improving the user experience. OpenReplay is a session replay tool that lets you see what your users do while using your application.

In this article, we will be looking at how to integrate OpenReplay with GitHub so you can create issues quickly from errors encountered by users in your application.

To follow along with this article, you’ll need to have a deployed OpenReplay instance. You can follow along with the guides listed [here](https://docs.openreplay.com/deployment) or use the SAAS solution. You’ll also need to have the following:

- Knowledge of JavaScript and React
- Node.js v12 or greater
- npm
- GitHub Account


## Creating a Web Application

We will be creating a demo application using [Create React App](https://create-react-app.dev/). To get started, open a terminal and run the code below:

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

The code above creates a React application called `sample-app`. It is a basic React application. Navigate to the `sample-app` directory and run the line below to start the application


```
npm start
```

We will be creating a basic counter application to increase and decrease the value of a number. Open the `App.js` file and paste the code below:


```javascript
import { useState } from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
    const [counter, setCounter] = useState(0);
    const handleClick = (operation = '+') => {
        if (operation === '-') {
            if (counter < 0) {
                throw new Error('Number is less than zero');
            }
            setCounter((prevState) => (prevState -= 1));
            return;
        }
        setCounter((prevState) => (prevState += 1));
    };
    return (
        <div className='App'>
            <header className='App-header'>
                <img src={logo} className='App-logo' alt='logo' />
                <p>
                    Edit <code>src/App.js</code> and save to reload.
                </p>
                <a className='App-link' href='https://reactjs.org' target='_blank' rel='noopener noreferrer'>
                    Learn React
                </a>
            </header>
            <main>
                <button onClick={() => handleClick('-')}>-</button>
                <p>{counter}</p>
                <button onClick={() => handleClick()}>+</button>
            </main>
        </div>
    );
}
export default App;
```

The code above allows a user to increase or decrease the value of a `count` with a catch. If the user decreases the value of count below zero, it throws an error. 


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



## Connecting OpenReplay to an Application

After creating the application, the next step is connecting OpenReplay to the application to start monitoring user events. OpenReplay provides a JavaScript library to help integrate OpenReplay into your web application. Run the code below to install the application:

```
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/fg44zh0d565e34bzw57y.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/zhaehol6uxcv9zwzqtpb.png)

3. Click the Settings icon to go to Preferences


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m682ygm1w3gikjjga0si.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 { useState } from 'react';
import logo from './logo.svg';
import './App.css';
import Tracker from '@openreplay/tracker';
const tracker = new Tracker({
    projectKey: 'O6Q7rBQdbxGMWgIeL7rd',
    ingestPoint: 'https://app.openreplaytutorial.ga/ingest',
});
tracker.start();
function App() {
// rest of the original code
```

OpenReplay doesn’t work in dev environments, so you’ll need to push your code to a repository and deploy it to a server for the tracking to work. I recommend platforms like [](https://www.netlify.com/)[Netlify](https://www.netlify.com/) and [](https://vercel.com/)[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 deploying your app on Netlify). 

After a successful deployment, visit your deployed application and perform operations for a session to be recorded. Close the browser tab when done to stop recording the session.
Visit your OpenReplay instance dashboard to view the recorded session afterwards. 
Note that after terminating a session, it usually takes about 4 minutes 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/jnzewgs12mu59fjkvfwe.png)



## Integrating OpenReplay with GitHub

You should be able to view a session recording on your OpenReplay Dashboard at this point. In this section, we will be looking at how to create a Github issue for a session recording.


1. Go to Github and login
2. After Authentication, go to [Personal Access Tokens](https://github.com/settings/tokens)
3. Enter a note for remembering the use of the token
4. Select an expiry date
5. Select `repo:status`, `repo_deployment`,`public_repo`, `read:user`, and `user:email` scopes
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26fbfpi9fb7lkliknkzh.png)

4. Click on Generate token
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylgq8gg84s82zhzh6t0o.png)

5. Copy the generated token to your clipboard
6. Go to your OpenReplay dashboard then 'Preferences > Integration'
7. Click on Github
8. Paste the copied generated token in the modal that opens up
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am0n94njie12tc7jsqyz.png)


We’ve successfully integrated Github into OpenReplay!

The next step is creating an issue from a recorded session.

1. Go to your OpenReplay dashboard
2. Click on a recorded session
3. Click on the Report issue button on the top right corner of the page.
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w76wk8w925wqx7aofywf.png)

4. Fill the details on the modal that opens
5. Click on Create

After reporting the issue, go to the Issues page of your repository on Github and you’ll see a new issue with the details you provided and a link to OpenReplay like the screenshot below.

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

## Conclusion

In this article, we’ve learned how to Integrate OpenReplay in an application so a developer can replay the actions a user took that resulted in an error. We’ve also looked at creating Github issues from OpenReplay sessions to foster collaboration and resolve errors with your team members.

As earlier stated, the ability to recreate the steps a user took that resulted in an error goes a long way in debugging issues, making OpenReplay an excellent tool to have in your arsenal as a developer. OpenReplay also has a supportive community on [](https://slack.openreplay.com/)[Slack](https://slack.openreplay.com/) to help you with issues you come across.