@microsoft/applicationinsights-angularplugin-js 15.1.1 → 15.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/IErrorService.mjs +2 -0
- package/esm2020/lib/applicationinsights-angularplugin-error.service.mjs +52 -0
- package/esm2020/lib/applicationinsights-angularplugin-js.component.mjs +152 -0
- package/esm2020/lib/applicationinsights-angularplugin-js.module.mjs +23 -0
- package/esm2020/microsoft-applicationinsights-angularplugin-js.mjs +5 -0
- package/esm2020/public-api.mjs +8 -0
- package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs +231 -0
- package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs.map +1 -0
- package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs +230 -0
- package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/IErrorService.ts → lib/IErrorService.d.ts} +0 -1
- package/lib/applicationinsights-angularplugin-error.service.d.ts +16 -0
- package/lib/applicationinsights-angularplugin-js.component.d.ts +20 -0
- package/lib/applicationinsights-angularplugin-js.module.d.ts +7 -0
- package/package.json +47 -30
- package/{src/public-api.ts → public-api.d.ts} +0 -4
- package/.eslintrc.json +0 -74
- package/NOTICE +0 -17
- package/PRIVACY +0 -3
- package/SECURITY.md +0 -41
- package/SUPPORT.md +0 -14
- package/karma.conf.js +0 -43
- package/ng-package.json +0 -15
- package/src/lib/applicationininsights-angularplugin-multiple-instace.spec.ts +0 -245
- package/src/lib/applicationinsights-angularplugin-error.service.spec.ts +0 -113
- package/src/lib/applicationinsights-angularplugin-error.service.ts +0 -57
- package/src/lib/applicationinsights-angularplugin-js.component.spec.ts +0 -158
- package/src/lib/applicationinsights-angularplugin-js.component.ts +0 -203
- package/src/lib/applicationinsights-angularplugin-js.module.ts +0 -14
- package/src/test.ts +0 -13
- package/tsconfig.lib.json +0 -30
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { Component, Injector} from "@angular/core";
|
|
2
|
-
import {
|
|
3
|
-
IConfig, IPageViewTelemetry, PropertiesPluginIdentifier, AnalyticsPluginIdentifier
|
|
4
|
-
} from "@microsoft/applicationinsights-common";
|
|
5
|
-
import {
|
|
6
|
-
IPlugin, IConfiguration, IAppInsightsCore, BaseTelemetryPlugin, arrForEach, ITelemetryItem, ITelemetryPluginChain,
|
|
7
|
-
IProcessTelemetryContext, getLocation, _throwInternal, eLoggingSeverity, _eInternalMessageId, IProcessTelemetryUnloadContext,
|
|
8
|
-
ITelemetryUnloadState, generateW3CId, onConfigChange, IConfigDefaults, isArray
|
|
9
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
10
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
11
|
-
import { NavigationEnd, Router } from "@angular/router";
|
|
12
|
-
import { ApplicationinsightsAngularpluginErrorService } from "./applicationinsights-angularplugin-error.service";
|
|
13
|
-
import { IErrorService } from "./IErrorService";
|
|
14
|
-
import { Subscription } from "rxjs";
|
|
15
|
-
import { AnalyticsPlugin } from "@microsoft/applicationinsights-analytics-js";
|
|
16
|
-
import {objDeepFreeze} from "@nevware21/ts-utils";
|
|
17
|
-
import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
|
|
18
|
-
|
|
19
|
-
interface IAngularExtensionConfig {
|
|
20
|
-
/**
|
|
21
|
-
* Angular router for enabling Application Insights PageView tracking.
|
|
22
|
-
*/
|
|
23
|
-
router?: Router;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Custom error service for global error handling.
|
|
27
|
-
*/
|
|
28
|
-
errorServices?: IErrorService[];
|
|
29
|
-
useInjector?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let undefValue;
|
|
33
|
-
|
|
34
|
-
const defaultAngularExtensionConfig: IConfigDefaults<IAngularExtensionConfig> = objDeepFreeze({
|
|
35
|
-
router: { blkVal: true, v: undefValue},
|
|
36
|
-
errorServices: { blkVal: true, v: undefValue}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
@Component({
|
|
40
|
-
selector: "lib-applicationinsights-angularplugin-js",
|
|
41
|
-
template: "",
|
|
42
|
-
styles: []
|
|
43
|
-
})
|
|
44
|
-
// eslint-disable-next-line @angular-eslint/component-class-suffix
|
|
45
|
-
export class AngularPlugin extends BaseTelemetryPlugin {
|
|
46
|
-
public priority = 186;
|
|
47
|
-
public identifier = "AngularPlugin";
|
|
48
|
-
|
|
49
|
-
constructor(private _injector?: Injector) { // _injector is optional to provide
|
|
50
|
-
super();
|
|
51
|
-
let _analyticsPlugin: AnalyticsPlugin;
|
|
52
|
-
let _propertiesPlugin: PropertiesPlugin;
|
|
53
|
-
let _angularCfg: IAngularExtensionConfig;
|
|
54
|
-
let _eventSubscription: Subscription;
|
|
55
|
-
let _isPageInitialLoad: boolean;
|
|
56
|
-
let _prevRouter: Router;
|
|
57
|
-
let _errorServiceInstance: ApplicationinsightsAngularpluginErrorService;
|
|
58
|
-
|
|
59
|
-
dynamicProto(AngularPlugin, this, (_self, _base) => {
|
|
60
|
-
|
|
61
|
-
const _initDefaults = () => {
|
|
62
|
-
_analyticsPlugin = null;
|
|
63
|
-
_propertiesPlugin = null;
|
|
64
|
-
_angularCfg = null;
|
|
65
|
-
_eventSubscription = null;
|
|
66
|
-
_isPageInitialLoad = true;
|
|
67
|
-
_prevRouter = undefValue;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
_initDefaults();
|
|
71
|
-
|
|
72
|
-
_self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[],
|
|
73
|
-
pluginChain?: ITelemetryPluginChain) => {
|
|
74
|
-
super.initialize(config, core, extensions, pluginChain);
|
|
75
|
-
|
|
76
|
-
_self._addHook(onConfigChange(config, (details) => {
|
|
77
|
-
let ctx = _self._getTelCtx();
|
|
78
|
-
_angularCfg = ctx.getExtCfg<IAngularExtensionConfig>(_self.identifier, defaultAngularExtensionConfig);
|
|
79
|
-
_propertiesPlugin = core.getPlugin<PropertiesPlugin>(PropertiesPluginIdentifier)?.plugin as PropertiesPlugin;
|
|
80
|
-
_analyticsPlugin = core.getPlugin<AnalyticsPlugin>(AnalyticsPluginIdentifier)?.plugin as AnalyticsPlugin;
|
|
81
|
-
|
|
82
|
-
if (_angularCfg.useInjector && _injector){
|
|
83
|
-
_errorServiceInstance = this._injector.get(ApplicationinsightsAngularpluginErrorService);
|
|
84
|
-
}
|
|
85
|
-
_errorServiceInstance = _errorServiceInstance ? _errorServiceInstance
|
|
86
|
-
: ApplicationinsightsAngularpluginErrorService.instance;
|
|
87
|
-
|
|
88
|
-
// two instance of errorService
|
|
89
|
-
|
|
90
|
-
if (_analyticsPlugin) {
|
|
91
|
-
if (_errorServiceInstance !== null) {
|
|
92
|
-
_errorServiceInstance.plugin = _analyticsPlugin;
|
|
93
|
-
if (_angularCfg.errorServices && isArray(_angularCfg.errorServices)) {
|
|
94
|
-
_errorServiceInstance.clearErrorHandlers();
|
|
95
|
-
arrForEach(_angularCfg.errorServices, (errorService: IErrorService) => {
|
|
96
|
-
_errorServiceInstance.addErrorHandler(errorService);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (_angularCfg.router !== _prevRouter) {
|
|
103
|
-
// router is changed, or has not been initialized yet
|
|
104
|
-
|
|
105
|
-
// unsubscribe previous router events
|
|
106
|
-
if (_eventSubscription) {
|
|
107
|
-
_eventSubscription.unsubscribe();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (_angularCfg.router){
|
|
111
|
-
// only track page view if it is the initial page load for this plugin
|
|
112
|
-
if (_isPageInitialLoad){
|
|
113
|
-
const pageViewTelemetry: IPageViewTelemetry = {
|
|
114
|
-
uri: _angularCfg.router.url
|
|
115
|
-
};
|
|
116
|
-
_self.trackPageView(pageViewTelemetry);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// subscribe to new router events
|
|
120
|
-
_eventSubscription = _angularCfg.router.events.subscribe(event => {
|
|
121
|
-
if (_self.isInitialized()) {
|
|
122
|
-
if (event instanceof NavigationEnd) {
|
|
123
|
-
// for page initial load, do not call trackPageView twice
|
|
124
|
-
if (_isPageInitialLoad) {
|
|
125
|
-
_isPageInitialLoad = false;
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const pvt: IPageViewTelemetry = {
|
|
129
|
-
uri: _angularCfg.router.url,
|
|
130
|
-
properties: { duration: 0 } // SPA route change loading durations are undefined, so send 0
|
|
131
|
-
};
|
|
132
|
-
_self.trackPageView(pvt);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
_prevRouter = _angularCfg.router;
|
|
138
|
-
}
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
// for test purpose only
|
|
142
|
-
_self["_getDbgPlgTargets"] = () => _angularCfg;
|
|
143
|
-
_self["_getErrorService"] = () => _errorServiceInstance;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
_self.trackPageView = (pageView: IPageViewTelemetry) => {
|
|
147
|
-
if (_analyticsPlugin) {
|
|
148
|
-
const location = getLocation();
|
|
149
|
-
if (_propertiesPlugin && _propertiesPlugin.context && _propertiesPlugin.context.telemetryTrace) {
|
|
150
|
-
_propertiesPlugin.context.telemetryTrace.traceID = generateW3CId();
|
|
151
|
-
_propertiesPlugin.context.telemetryTrace.name = location && location.pathname || "_unknown_";
|
|
152
|
-
}
|
|
153
|
-
_analyticsPlugin.trackPageView(pageView);
|
|
154
|
-
} else {
|
|
155
|
-
_throwInternal(_self.diagLog(),
|
|
156
|
-
// eslint-disable-next-line max-len
|
|
157
|
-
eLoggingSeverity.CRITICAL, _eInternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, Angular plugin telemetry will not be sent: ");
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
_self._doTeardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState,
|
|
163
|
-
asyncCallback?: () => void): void | boolean => {
|
|
164
|
-
if (_analyticsPlugin && _errorServiceInstance !== null) {
|
|
165
|
-
_errorServiceInstance.plugin = null;
|
|
166
|
-
if (_angularCfg) {
|
|
167
|
-
if (_angularCfg.errorServices && Array.isArray(_angularCfg.errorServices)) {
|
|
168
|
-
_errorServiceInstance.clearErrorHandlers();
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (_eventSubscription) {
|
|
175
|
-
_eventSubscription.unsubscribe();
|
|
176
|
-
_eventSubscription = null;
|
|
177
|
-
}
|
|
178
|
-
_initDefaults();
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Add Part A fields to the event
|
|
185
|
-
*
|
|
186
|
-
* @param event The event that needs to be processed
|
|
187
|
-
*/
|
|
188
|
-
processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext) {
|
|
189
|
-
this.processNext(event, itemCtx);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) {
|
|
194
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
trackPageView(pageView: IPageViewTelemetry) {
|
|
198
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NgModule } from "@angular/core";
|
|
2
|
-
import { AngularPlugin } from "./applicationinsights-angularplugin-js.component";
|
|
3
|
-
import { ApplicationinsightsAngularpluginErrorService } from "./applicationinsights-angularplugin-error.service";
|
|
4
|
-
|
|
5
|
-
@NgModule({
|
|
6
|
-
declarations: [AngularPlugin],
|
|
7
|
-
imports: [
|
|
8
|
-
],
|
|
9
|
-
exports: [AngularPlugin],
|
|
10
|
-
providers: [
|
|
11
|
-
ApplicationinsightsAngularpluginErrorService
|
|
12
|
-
]
|
|
13
|
-
})
|
|
14
|
-
export class ApplicationinsightsAngularpluginJsModule { }
|
package/src/test.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
-
|
|
3
|
-
import "zone.js";
|
|
4
|
-
import "zone.js/testing";
|
|
5
|
-
import { getTestBed } from "@angular/core/testing";
|
|
6
|
-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting} from "@angular/platform-browser-dynamic/testing";
|
|
7
|
-
|
|
8
|
-
// First, initialize the Angular testing environment.
|
|
9
|
-
getTestBed().initTestEnvironment(
|
|
10
|
-
BrowserDynamicTestingModule,
|
|
11
|
-
platformBrowserDynamicTesting(), {
|
|
12
|
-
teardown: { destroyAfterEach: false }
|
|
13
|
-
});
|
package/tsconfig.lib.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"target": "es2015",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"declarationMap": true,
|
|
10
|
-
"inlineSources": true,
|
|
11
|
-
"types": [],
|
|
12
|
-
"lib": [
|
|
13
|
-
"dom",
|
|
14
|
-
"es2018"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"angularCompilerOptions": {
|
|
18
|
-
"skipTemplateCodegen": true,
|
|
19
|
-
"strictMetadataEmit": true,
|
|
20
|
-
"enableResourceInlining": true,
|
|
21
|
-
"fullTemplateTypeCheck": true,
|
|
22
|
-
"strictInjectionParameters": true,
|
|
23
|
-
"flatModuleId": "AUTOGENERATED",
|
|
24
|
-
"flatModuleOutFile": "AUTOGENERATED"
|
|
25
|
-
},
|
|
26
|
-
"exclude": [
|
|
27
|
-
"src/test.ts",
|
|
28
|
-
"**/*.spec.ts"
|
|
29
|
-
]
|
|
30
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/spec",
|
|
6
|
-
"types": [
|
|
7
|
-
"jasmine"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"src/test.ts"
|
|
12
|
-
],
|
|
13
|
-
"include": [
|
|
14
|
-
"**/*.spec.ts",
|
|
15
|
-
"**/*.d.ts"
|
|
16
|
-
]
|
|
17
|
-
}
|