File tree Expand file tree Collapse file tree 3 files changed +37
-11
lines changed Expand file tree Collapse file tree 3 files changed +37
-11
lines changed Original file line number Diff line number Diff line change 9
9
Install & save the library to your package.json:
10
10
11
11
``` bash
12
- $ npm i -S @MarkPieszak /ngx-application-insights
12
+ $ npm i -S @markpieszak /ngx-application-insights
13
13
```
14
14
15
15
and then add the library to your Angular Root ` AppModule ` :
16
16
17
17
``` typescript
18
18
// Import the Application Insights library
19
- import { ApplicationInsightsModule } from ' @MarkPieszak /ngx-application-insights' ;
19
+ import { ApplicationInsightsModule } from ' @markpieszak /ngx-application-insights' ;
20
20
21
21
@NgModule ({
22
22
imports: [
23
23
// ... your imports
24
24
25
25
// Add the Module to your imports
26
- ApplicationInsightsModule .forRoot (' Your-Application-Insights-ID' , ' [OPTIONAL] App name for Events' )
26
+ ApplicationInsightsModule .forRoot ({
27
+ appID: ' Your-Application-Insights-ID' ,
28
+ appName: ' [OPTIONAL] App name for Events'
29
+ })
27
30
],
28
31
// ... providers / etc
29
32
})
Original file line number Diff line number Diff line change 1
1
import { OpaqueToken } from '@angular/core' ;
2
2
3
3
export interface IAppInsightConfig {
4
- applicationInsightID : string ;
5
- angularAppName ?: string ;
4
+ appID : string ;
5
+ appName ?: string ;
6
6
}
7
7
8
8
export const APP_INSIGHT_ID : OpaqueToken = new OpaqueToken ( 'XXXX-12345' ) ;
9
9
export const APP_NAME : OpaqueToken = new OpaqueToken ( 'Angular Application' ) ;
10
10
11
11
export function provideConfig ( config : IAppInsightConfig ) : any {
12
+
13
+ if ( ! config . appID ) {
14
+ throw new Error ( '[ ngx-application-insights] Error: MS Application Insight -ID- not passed into config.' ) ;
15
+ }
16
+
12
17
return [
13
- { provide : APP_INSIGHT_ID , useValue : config . applicationInsightID } ,
14
- { provide : APP_NAME , useValue : config . angularAppName ? config . angularAppName : APP_NAME }
18
+ { provide : APP_INSIGHT_ID , useValue : config . appID } ,
19
+ { provide : APP_NAME , useValue : config . appName ? config . appName : APP_NAME }
15
20
] ;
16
21
}
Original file line number Diff line number Diff line change @@ -10,20 +10,38 @@ export class AppInsightsService {
10
10
this . init ( ) ;
11
11
}
12
12
13
- private init ( ) : void {
13
+ // On logEvent AppInsight usage:
14
+ // https://msdn.microsoft.com/en-us/library/dn614099.aspx
15
+
16
+ logEvent ( eventName : string , eventProperties ?: Object , metricProperty ?: Object ) {
14
17
if ( ! this . isBrowser ) {
15
18
return ;
16
19
}
17
20
18
- ( < any > window ) . appInsights . start ( this . appID ) ;
21
+ if ( eventProperties === null ) {
22
+ }
23
+
24
+ try {
25
+ ( < any > window ) . appInsights . logEvent ( eventName , eventProperties , metricProperty ) ;
26
+ } catch ( ex ) {
27
+ console . warn ( 'Angular application insights Error [logEvent]: ' , ex ) ;
28
+ }
29
+
19
30
}
20
31
21
- public trackEvent ( eventName : string , customData : any ) {
32
+ /*
33
+ * Internal
34
+ */
35
+ private init ( ) : void {
22
36
if ( ! this . isBrowser ) {
23
37
return ;
24
38
}
25
39
26
- ( < any > window ) . appInsights . trackEvent ( eventName , customData ) ;
40
+ try {
41
+ ( < any > window ) . appInsights . start ( this . appID ) ;
42
+ } catch ( ex ) {
43
+ console . warn ( 'Angular application insights Error [start]: ' , ex ) ;
44
+ }
27
45
}
28
46
29
47
private isBrowser ( ) : boolean {
You can’t perform that action at this time.
0 commit comments