diff --git a/projects/ng-application-insights/src/lib/ng-application-insights.service.ts b/projects/ng-application-insights/src/lib/ng-application-insights.service.ts index 2d735ad..84c363e 100644 --- a/projects/ng-application-insights/src/lib/ng-application-insights.service.ts +++ b/projects/ng-application-insights/src/lib/ng-application-insights.service.ts @@ -1,11 +1,14 @@ import { Injectable } from '@angular/core'; import { ApplicationInsights, + IConfig, + IConfiguration, IEventTelemetry, IExceptionTelemetry, + ITelemetryItem, + } from '@microsoft/applicationinsights-web'; -import { Router, NavigationEnd } from '@angular/router'; -import { filter } from 'rxjs/operators'; +import { Router } from '@angular/router'; interface ICustomProperties { [key: string]: any; @@ -16,15 +19,18 @@ export class NgApplicationInsightsConfig { enabled = true; instrumentationKey = ''; properties?: ICustomProperties = {}; -} + extraConfig?: IConfiguration & IConfig = {}; + disabledUrls?: string[] = []; +}; @Injectable({ providedIn: 'root', }) export class NgApplicationInsightsService { - appInsights: ApplicationInsights; + public appInsights!: ApplicationInsights; private customProperties: ICustomProperties = {}; + constructor( private config: NgApplicationInsightsConfig, private router: Router @@ -34,9 +40,19 @@ export class NgApplicationInsightsService { config: { instrumentationKey: this.config.instrumentationKey, enableAutoRouteTracking: true, + ...this.config.extraConfig, }, }); + this.appInsights.addTelemetryInitializer((envelope: ITelemetryItem) => { + const dataBase = JSON.stringify(envelope.baseData); + const disabled = this.config.disabledUrls || []; + if ( disabled.some((item) => dataBase.includes(item))) { + return false; + } + return true; + }); + this.appInsights.loadAppInsights(); this.createRouterSubscription(); }