1.0.2 • Published 3 years ago
@omaxel/angular-ms-app-insights v1.0.2
Angular Microsoft Application Insights
Utility library to easily configure Microsoft Application Insights into an Angular project.
Installation
Install dependencies first:
npm i @microsoft/applicationinsights-angularplugin-js @microsoft/applicationinsights-webthen install the package:
npm i @omaxel/angular-ms-app-insights Usage
Configure the module in
app.module.tsAppInsightsModule.forRoot({ connectionString: 'YOUR_CONNECTION_STRING',~~~~ appName: 'YOUR_APP_NAME', // Optionals appVersion: 'YOUR_APP_VERSION', appBuildNumber: 'YOUR_APP_BUILD_NUMBER' }),In the
app.component.tsfile, call theinitmethod:import { Component } from '@angular/core'; import { AppInsightsService } from "@omaxel/angular-ms-app-insights"; @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent { constructor(appInsightsService: AppInsightsService) { appInsightsService.init(); } }
Track custom events
You can call the trackEvent method of AppInsightsService to track a custom event:
@Component({
selector: 'app-example',
templateUrl: './example.component.html'
})
export class ExampleComponent {
constructor(private appInsightsService: AppInsightsService) { }
onClick() {
this.appInsightsService.trackEvent('my-event-name', { myProperty: 'my-value' });
}
}