Crash Reporting for React applications with Raygun is available using the Raygun4JS provider.
Once Raygun is installed, it will automatically start monitoring your application for errors with Crash Reporting.
Step 1 - Add the Raygun4JS script
There are two installation methods for Raygun4JS. Through a package manager like NPM and Yarn, or through our CDN.
NPM, Yarn, or Bun
npm install raygun4js
yarn install raygun4js
bun install 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.
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
Step 2 - Enable Crash Reporting
Add the following lines underneath the previous code in Step 1.
Using NPM, Yarn, or Bun
Import the Raygun4JS provider into your application inside of
App.js (or equivalent for your framework) and enable Crash Reporting.
import rg4js from 'raygun4js'; rg4js('apiKey', 'paste_your_api_key_here'); rg4js('enableCrashReporting', true);
Step 3 - Test your installation
Raygun should now be setup! Send a test exception using the snippet below to test your installation. Once we detect your first error event, your Raygun app will automatically update.
throw new Error("This is a test exception");
For advanced setup instructions please refer to the Advanced Features documentation page.
For troubleshooting tips please refer to the Troubleshooting documentation page.
The provider is open source and available at the Raygun4js repository.