1- import { Injectable , Inject } from '@angular/core' ;
1+ import { Injectable , Optional } from '@angular/core' ;
22import { Router , NavigationStart , NavigationEnd } from '@angular/router' ;
33import { AppInsights } from 'applicationinsights-js' ;
4- import { APP_INSIGHTS_CONFIG } from './app-insight.config' ;
54import 'rxjs/add/operator/filter' ;
65import IAppInsights = Microsoft . ApplicationInsights . IAppInsights ;
76
7+ export class AppInsightsConfig implements Microsoft . ApplicationInsights . IConfig {
8+ instrumentationKey ?: string ;
9+ endpointUrl ?: string ;
10+ emitLineDelimitedJson ?: boolean ;
11+ accountId ?: string ;
12+ sessionRenewalMs ?: number ;
13+ sessionExpirationMs ?: number ;
14+ maxBatchSizeInBytes ?: number ;
15+ maxBatchInterval ?: number ;
16+ enableDebug ?: boolean ;
17+ disableExceptionTracking ?: boolean ;
18+ disableTelemetry ?: boolean ;
19+ verboseLogging ?: boolean ;
20+ diagnosticLogInterval ?: number ;
21+ samplingPercentage ?: number ;
22+ autoTrackPageVisitTime ?: boolean ;
23+ disableAjaxTracking ?: boolean ;
24+ overridePageViewDuration ?: boolean ;
25+ maxAjaxCallsPerView ?: number ;
26+ disableDataLossAnalysis ?: boolean ;
27+ disableCorrelationHeaders ?: boolean ;
28+ disableFlushOnBeforeUnload ?: boolean ;
29+ enableSessionStorageBuffer ?: boolean ;
30+ isCookieUseDisabled ?: boolean ;
31+ cookieDomain ?: string ;
32+ isRetryDisabled ?: boolean ;
33+ isPerfAnalyzerEnabled ?: boolean ;
34+ url ?: string ;
35+ isStorageUseDisabled ?: boolean ;
36+ }
37+
838@Injectable ( )
939export class AppInsightsService implements IAppInsights {
1040 context : Microsoft . ApplicationInsights . ITelemetryContext ;
1141 queue : Array < ( ) => void > ;
12-
13- constructor (
14- @ Inject ( APP_INSIGHTS_CONFIG ) public config : Microsoft . ApplicationInsights . IConfig ,
15- public router : Router
16- ) { }
42+ config : Microsoft . ApplicationInsights . IConfig ;
43+ constructor ( @ Optional ( ) _config : AppInsightsConfig , public router : Router ) {
44+ this . config = _config ;
45+ this . init ( ) ;
46+ }
1747
1848 // https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackevent
1949 // trackEvent(name: string, properties?: {[string]:string}, measurements?: {[string]:number})
@@ -55,8 +85,8 @@ export class AppInsightsService implements IAppInsights {
5585
5686 // https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#starttrackpage
5787 // startTrackPage(name?: string)
58- // Starts the timer for tracking a page view. Use this instead of trackPageView if you want to control when the
59- // page view timer starts and stops, but don't want to calculate the duration yourself. This method doesn't send any
88+ // Starts the timer for tracking a page view. Use this instead of trackPageView if you want to control when the
89+ // page view timer starts and stops, but don't want to calculate the duration yourself. This method doesn't send any
6090 // telemetry. Call stopTrackPage to log the end of the page view and send the event.
6191 startTrackPage ( name ?: string ) {
6292 try {
@@ -68,7 +98,7 @@ export class AppInsightsService implements IAppInsights {
6898
6999 // https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#stoptrackpage
70100 // stopTrackPage(name?: string, url?: string, properties?: Object, measurements?: Object)
71- // Stops the timer that was started by calling startTrackPage and sends the page view telemetry with the
101+ // Stops the timer that was started by calling startTrackPage and sends the page view telemetry with the
72102 // specified properties and measurements. The duration of the page view will be the time between calling startTrackPage and stopTrackPage.
73103 stopTrackPage ( name ?: string , url ?: string , properties ?: { [ name : string ] : string } , measurements ?: { [ name : string ] : number } ) {
74104 try {
@@ -80,7 +110,7 @@ export class AppInsightsService implements IAppInsights {
80110
81111 // https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackmetric
82112 // trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: {[string]:string})
83- // Log a positive numeric value that is not associated with a specific event.
113+ // Log a positive numeric value that is not associated with a specific event.
84114 // Typically used to send regular reports of performance indicators.
85115 trackMetric ( name : string , average : number , sampleCount ?: number , min ?: number , max ?: number , properties ?: { [ name : string ] : string } ) {
86116 try {
@@ -94,7 +124,7 @@ export class AppInsightsService implements IAppInsights {
94124 // trackException(exception: Error, handledAt?: string, properties?: {[string]:string}, measurements?: {[string]:number}, severityLevel?: AI.SeverityLevel)
95125 // Log an exception you have caught. (Exceptions caught by the browser are also logged.)
96126 trackException ( exception : Error , handledAt ?: string , properties ?: { [ name : string ] : string } ,
97- measurements ?: { [ name : string ] : number } , severityLevel ?: AI . SeverityLevel ) {
127+ measurements ?: { [ name : string ] : number } , severityLevel ?: AI . SeverityLevel ) {
98128 try {
99129 AppInsights . trackException ( exception , handledAt , properties , measurements , severityLevel ) ;
100130 } catch ( ex ) {
@@ -139,7 +169,7 @@ export class AppInsightsService implements IAppInsights {
139169
140170 // https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#setauthenticatedusercontext
141171 // setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string)
142- // Set the authenticated user id and the account id in this session. Use this when you have identified a specific
172+ // Set the authenticated user id and the account id in this session. Use this when you have identified a specific
143173 // signed-in user. Parameters must not contain spaces or ,;=|
144174 setAuthenticatedUserContext ( authenticatedUserId : string , accountId ?: string ) {
145175 try {
@@ -166,17 +196,19 @@ export class AppInsightsService implements IAppInsights {
166196
167197 public init ( ) : void {
168198 try {
199+ console . warn ( 'in AppInsights.init' ) ;
169200 AppInsights . downloadAndSetup ( this . config ) ;
201+ console . warn ( 'in AppInsights.init: calling downloadAndSetup' ) ;
170202
171203 this . router . events . filter ( event => event instanceof NavigationStart )
172- . subscribe ( ( event : NavigationStart ) => {
173- this . startTrackPage ( event . url ) ;
174- } ) ;
204+ . subscribe ( ( event : NavigationStart ) => {
205+ this . startTrackPage ( event . url ) ;
206+ } ) ;
175207
176208 this . router . events . filter ( event => event instanceof NavigationEnd )
177- . subscribe ( ( event : NavigationEnd ) => {
178- this . stopTrackPage ( event . url ) ;
179- } ) ;
209+ . subscribe ( ( event : NavigationEnd ) => {
210+ this . stopTrackPage ( event . url ) ;
211+ } ) ;
180212 } catch ( ex ) {
181213 console . warn ( 'Angular application insights Error [downloadAndSetup]: ' , ex ) ;
182214 }
0 commit comments