JavaScript Crash Reporting with Raygun is available using the Raygun4JS provider.

Raygun4JS is a library that you can easily add to your website or web application, which will then monitor your application and display all JavaScript errors and frontend performance issues affecting your users within your Raygun account. Installation is painless.

The provider is a single script which includes the sole dependency, allowing you to drop it straight in. It is also available as a script snippet which loads the library from Raygun's CDN.


If you use a JavaScript framework, visit the following links for step by step instructions on how you can integrate Raygun.

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

Package Manager

npm install raygun4js
yarn add raygun4js
bun add raygun4js

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);

Add the following snippet to the beginning of the <head> tag within your markup, before any other <script> tags.

<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({

Paste this snippet below the one you added in step 1.

<script type="text/javascript">
  rg4js('apiKey', 'paste_your_api_key_here');
  rg4js('enableCrashReporting', true);

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

For troubleshooting tips please refer to the Troubleshooting documentation page.

Enable Real User Monitoring to also track your website's performance.

<script type="text/javascript">
  rg4js('enableRealUserMonitoring', true); 

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