Angular 1

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.

To enable Crash Reporting and Real User Monitoring monitoring add the following configuration lines to your JavaScript site code, just before the closing </body> tag with your API key included.

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

You will need to add a custom $exceptionHandler in Angular. This is to capture any errors that happen in your Angular code and send them to Raygun.

  .module('exceptionOverride', [])
  .factory('$exceptionHandler', function() {
    return function(exception, cause) {
      rg4js('send', { error: exception, customData: { cause: cause }, tags: ['Angular'] });

Real User Monitoring supports SPA's by calling a trackEvent method when a page transition occurs. In Angular we can listen to the $routeChangeSuccess event listener and call the trackEvent method to notify Raygun that the user is viewing a new page.

$scope.$on('$routeChangeSuccess', function () {
  rg4js('trackEvent', {
      type: 'pageView',
      path: '/' + $scope.area

More documentation about the trackEvent method and how to track SPAs can be found here.

You can track failed Ajax requests by adding a new interceptor on the $httpProvider. This new interceptor will then send an error to Raygun when a requestError or responseError event occurs.

$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
  return {
   'requestError': function(rejection) {
       rg4js('send', {
          error: 'Failed $http request',
          customData: { rejection: rejection }

    'responseError': function(rejection) {
       rg4js('send', {
          error: 'Failed $http response',
          customData: { rejection: rejection }

For more information on interceptors see the official docs.

Custom timings enables you to track up to 10 additional performance metrics of your choosing with each full page load.

You can find more information about our custom timings feature here.

Congratulations, you have successfully implemented Raygun into your application!

tip: We recommend raising a test exception from your application right now to view your dashboard and test that everything is wired up correctly. If your setup is not working get in touch.

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