Skip to content

Commit 4890d27

Browse files
committed
fix(naming): update config naming
1 parent d1b11ca commit 4890d27

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@
99
Install & save the library to your package.json:
1010

1111
```bash
12-
$ npm i -S @MarkPieszak/ngx-application-insights
12+
$ npm i -S @markpieszak/ngx-application-insights
1313
```
1414

1515
and then add the library to your Angular Root `AppModule`:
1616

1717
```typescript
1818
// Import the Application Insights library
19-
import { ApplicationInsightsModule } from '@MarkPieszak/ngx-application-insights';
19+
import { ApplicationInsightsModule } from '@markpieszak/ngx-application-insights';
2020

2121
@NgModule({
2222
imports: [
2323
// ... your imports
2424

2525
// 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+
})
2730
],
2831
// ... providers / etc
2932
})

src/app-insight.config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { OpaqueToken } from '@angular/core';
22

33
export interface IAppInsightConfig {
4-
applicationInsightID: string;
5-
angularAppName?: string;
4+
appID: string;
5+
appName?: string;
66
}
77

88
export const APP_INSIGHT_ID: OpaqueToken = new OpaqueToken('XXXX-12345');
99
export const APP_NAME: OpaqueToken = new OpaqueToken('Angular Application');
1010

1111
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+
1217
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 }
1520
];
1621
}

src/app-insight.service.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,38 @@ export class AppInsightsService {
1010
this.init();
1111
}
1212

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) {
1417
if (!this.isBrowser) {
1518
return;
1619
}
1720

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+
1930
}
2031

21-
public trackEvent(eventName: string, customData: any) {
32+
/*
33+
* Internal
34+
*/
35+
private init(): void {
2236
if (!this.isBrowser) {
2337
return;
2438
}
2539

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+
}
2745
}
2846

2947
private isBrowser(): boolean {

0 commit comments

Comments
 (0)