JavaScript error and performance monitoring 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.

Step 1 - Add script

Add this snippet to your markup, before the closing </head> tag:

<script type="text/javascript">

This 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 find instructions on how to install Raygun via NPM here.

Step 2 - Enable Crash Reporting

Add the following lines underneath the previous code in Step 1 with your API key included.

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

This will configure the provider to automatically send all unhandled JavaScript errors to Raygun.

Optional - Enable Real User Monitoring

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

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

User Tracking

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 provider is open source and available at the Raygun4js repository.