title | description | services | author | ms.workload | ms.tgt_pltfrm | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|
Angular plugin for Application Insights JavaScript SDK |
How to install and use Angular plugin for Application Insights JavaScript SDK. |
azure-monitor |
lgayhardt |
tbd |
ibiza |
conceptual |
10/07/2020 |
lagayhar |
The Angular plugin for the Application Insights JavaScript SDK, enables:
- Tracking of router changes
- Tracking uncaught exceptions
Warning
Angular plugin is NOT ECMAScript 3 (ES3) compatible.
Install npm package:
npm install @microsoft/applicationinsights-angularplugin-js
Set up an instance of Application Insights in the entry component in your app:
import { Component } from '@angular/core';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { AngularPlugin } from '@microsoft/applicationinsights-angularplugin-js';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(
private router: Router
){
var angularPlugin = new AngularPlugin();
const appInsights = new ApplicationInsights({ config: {
instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE',
extensions: [angularPlugin],
extensionConfig: {
[angularPlugin.identifier]: { router: this.router }
}
} });
appInsights.loadAppInsights();
}
}
To track uncaught exceptions, setup ApplicationinsightsAngularpluginErrorService in app.module.ts
:
import { ApplicationinsightsAngularpluginErrorService } from '@microsoft/applicationinsights-angularplugin-js';
@NgModule({
...
providers: [
{
provide: ErrorHandler,
useClass: ApplicationinsightsAngularpluginErrorService
}
]
...
})
export class AppModule { }
- To learn more about the JavaScript SDK, see the Application Insights JavaScript SDK documentation
- Angular plugin on GitHub