Angular
The following docs are applicable to Angular 2+ only. Angular 1 (also known as AngularJS) has reached its EOL in January 2022 which, therefore, we no longer support.
Step 1 - Install the Raygun4JS provider
Install the raygun4js
library with NPM:
npm install raygun4js --save
Or with Yarn:
yarn add raygun4js
Step 2 - Configure Raygun
Add the following configuration into app.module.ts to enable Real User Monitoring.
import rg4js from 'raygun4js';
rg4js('apiKey', 'paste_your_api_key_here');
rg4js('enablePulse', true);
In the same file, extend your AppModule
component to subscribe to Router events. Using Angular's NavigationEnd event we can track the exact pages a user has viewed.
import { Component, OnInit } from '@angular/core';
import { Router, NavigationError, NavigationEnd } from '@angular/router';
export class AppModule implements OnInit {
constructor(private router: Router) {}
ngOnInit() {
this.router.events.subscribe(event => {
// Track page views when the NavigationEnd event occurs
if (event instanceof NavigationEnd) {
rg4js('trackEvent', {
type: 'pageView',
path: event.url
});
}
});
}
}
This is just a simple example of tracking one type of Router Event, see the Angular Router Event documentation for all of the types of events you can track.
Advanced Setup
For advanced setup instructions please refer to the Advanced Features documentation page.
Troubleshooting
For troubleshooting tips please refer to the Troubleshooting documentation page.
The provider is open source and available at the Raygun4js repository.