Real User Monitoring for React applications with Raygun is available using the Raygun4JS provider.

Raygun4JS is a library you can easily add to your website and web applications which allows you to then monitor frontend performance issues affecting your users.

Once Raygun is installed, it will automatically start monitoring user sessions with Real User Monitoring.

There are two installation methods for Raygun4JS. Through a package manager like NPM and Yarn, or through our CDN.

Install Raygun via NPM.


npm install raygun4js


yarn add raygun4js


bun add raygun4js

Add the following snippet to the beginning of the <head> tag within your markup. Please include this snippet before any other <script> tag references are made to ensure that Raygun has the best chance to capture all error events on the page.

<script type="text/javascript">
  h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({

The above snippet will fetch the Raygun4JS script from our CDN asynchronously so it doesn't block the page load. It will also catch errors that are thrown while the page is loading, and send them when the script is ready.

Alternatively, you can download the production script (minified) or the development script (full source). Note: If you encounter a situation where no events are appearing within Raygun, you may need to hard code the protocol so that the CDN matches your hosting environment. This could look like one of the following -


This will be in replacement of //

Depending on how you have added Raygun4js in your application, setting up Crash Reporting will be different. Below are examples for the two most common use cases. These snippets will set up Raygun4js to automatically send application usage statistics to Raygun.

Add the following lines underneath the previous code in Step 1.

<script type="text/javascript">
  rg4js('apiKey', 'paste_your_api_key_here');
  rg4js('enablePulse', true); // Enables Real User Monitoring

Import the Raygun4JS provider into your application inside of App.js (or equivalent for your framework) and activate real user monitoring.

import rg4js from 'raygun4js';

rg4js('apiKey', 'paste_your_api_key_here');
rg4js('enablePulse', true);

Setup user tracking by providing the following information to the Raygun4JS provider after the previous code snippet.

rg4js('setUser', {
  identifier: 'users_email_address_or_unique_id',
  isAnonymous: false,
  email: '',
  firstName: 'Firstname',
  fullName: 'Firstname Lastname'

The string properties on a User have a maximum length of 255 characters. Users who have fields that exceed this amount will not be processed.

When a user has logged out of your application, you can remove their data from all subsequent events like so:


rg4js('setUser', {
  isAnonymous: true

Raygun's Real User Monitoring supports single page applications (SPAs) through the trackEvent function:

rg4js('trackEvent', {
  type: 'pageView',
  path: '/' + window.location.pathname

When a route or view change is triggered in your SPA, the trackEvent method should be called with type being pageView and path set to a string representing the new view or route. Timing information from this point onwards will be associated to a new "virtual page", which is then viewable in Raygun.

You can track custom performance measurements across your website or application using custom timings. For example, you might track the time it takes for a specific video to play or the search bar to load. Custom timings gives you the flexibility to track the timing of events that matter to your users or business.

For more information see our documentation on custom timings.

For advanced setup instructions please refer to the Advanced Features documentation page.

Below is an example of how you can use React Router alongside the BrowserRouter to automatically track route changes.

// App.js
import { useEffect } from "react";
import {
} from "react-router-dom";
import rg4js from 'raygun4js';

function App() {

  let location = useLocation();

  useEffect(function() {
    rg4js('trackEvent', { type: 'pageView', path: location.pathname });
  }, [location]);

  return (
            <Link to="/">Home</Link>
            <Link to="/about">About</Link>

        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />

function Home() { return <p>Home</p> }
function About() { return <p>About</p> }

export default App;
// index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter as Router } from "react-router-dom";
import rg4js from 'raygun4js';
import App from './App';

rg4js('apiKey', process.env.REACT_APP_RAYGUN_API_KEY);
rg4js('enableCrashReporting', true);
rg4js('enablePulse', true);

const root = ReactDOM.createRoot(document.getElementById('root'));
      <App />

The provider is open source and available at the Raygun4js repository.