@microsoft/applicationinsights-analytics-js 2.7.5-nightly.2203-02 → 2.7.5-nightly.2203-03

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.
Files changed (42) hide show
  1. package/browser/applicationinsights-analytics-js.integrity.json +9 -9
  2. package/browser/applicationinsights-analytics-js.js +1621 -660
  3. package/browser/applicationinsights-analytics-js.js.map +1 -1
  4. package/browser/applicationinsights-analytics-js.min.js +2 -2
  5. package/browser/applicationinsights-analytics-js.min.js.map +1 -1
  6. package/dist/applicationinsights-analytics-js.api.json +49 -184
  7. package/dist/applicationinsights-analytics-js.api.md +8 -18
  8. package/dist/applicationinsights-analytics-js.d.ts +9 -104
  9. package/dist/applicationinsights-analytics-js.js +1621 -660
  10. package/dist/applicationinsights-analytics-js.js.map +1 -1
  11. package/dist/applicationinsights-analytics-js.min.js +2 -2
  12. package/dist/applicationinsights-analytics-js.min.js.map +1 -1
  13. package/dist/applicationinsights-analytics-js.rollup.d.ts +9 -104
  14. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js +674 -0
  15. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js.map +1 -0
  16. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js +21 -8
  17. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +10 -10
  19. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +5 -5
  21. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Timing.js +39 -0
  23. package/dist-esm/JavaScriptSDK/Timing.js.map +1 -0
  24. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
  25. package/dist-esm/applicationinsights-analytics-js.js +2 -2
  26. package/dist-esm/applicationinsights-analytics-js.js.map +1 -1
  27. package/package.json +6 -6
  28. package/src/JavaScriptSDK/{ApplicationInsights.ts → AnalyticsPlugin.ts} +403 -325
  29. package/src/JavaScriptSDK/Telemetry/PageViewManager.ts +32 -13
  30. package/src/JavaScriptSDK/Telemetry/PageViewPerformanceManager.ts +6 -6
  31. package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +1 -1
  32. package/src/JavaScriptSDK/Timing.ts +46 -0
  33. package/src/applicationinsights-analytics-js.ts +1 -1
  34. package/types/JavaScriptSDK/{ApplicationInsights.d.ts → AnalyticsPlugin.d.ts} +12 -16
  35. package/types/JavaScriptSDK/Telemetry/PageViewManager.d.ts +2 -1
  36. package/types/JavaScriptSDK/Telemetry/PageViewPerformanceManager.d.ts +9 -9
  37. package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +4 -4
  38. package/types/JavaScriptSDK/Timing.d.ts +18 -0
  39. package/types/applicationinsights-analytics-js.d.ts +1 -1
  40. package/types/tsdoc-metadata.json +1 -1
  41. package/dist-esm/JavaScriptSDK/ApplicationInsights.js +0 -606
  42. package/dist-esm/JavaScriptSDK/ApplicationInsights.js.map +0 -1
@@ -6,7 +6,7 @@ import {
6
6
  } from "@microsoft/applicationinsights-common";
7
7
  import {
8
8
  IAppInsightsCore, IDiagnosticLogger, LoggingSeverity,
9
- _InternalMessageId, getDocument, getLocation, arrForEach, isNullOrUndefined, getExceptionName, dumpObj
9
+ _InternalMessageId, getDocument, getLocation, arrForEach, isNullOrUndefined, getExceptionName, dumpObj, IProcessTelemetryUnloadContext, ITelemetryUnloadState
10
10
  } from "@microsoft/applicationinsights-core-js";
11
11
  import { PageViewPerformanceManager } from "./PageViewPerformanceManager";
12
12
  import dynamicProto from "@microsoft/dynamicproto-js";
@@ -25,10 +25,10 @@ export interface IAppInsightsInternal {
25
25
  export class PageViewManager {
26
26
 
27
27
  constructor(
28
- appInsights: IAppInsightsInternal,
29
- overridePageViewDuration: boolean,
30
- core: IAppInsightsCore,
31
- pageViewPerformanceManager: PageViewPerformanceManager) {
28
+ appInsights: IAppInsightsInternal,
29
+ overridePageViewDuration: boolean,
30
+ core: IAppInsightsCore,
31
+ pageViewPerformanceManager: PageViewPerformanceManager) {
32
32
 
33
33
  dynamicProto(PageViewManager, this, (_self) => {
34
34
  let intervalHandle: any = null;
@@ -40,11 +40,9 @@ export class PageViewManager {
40
40
  _logger = core.logger;
41
41
  }
42
42
 
43
- function _flushChannels() {
43
+ function _flushChannels(isAsync: boolean) {
44
44
  if (core) {
45
- arrForEach(core.getTransmissionControls(), queues => {
46
- arrForEach(queues, q => q.flush(true))
47
- });
45
+ core.flush(isAsync);
48
46
  }
49
47
  }
50
48
 
@@ -72,7 +70,7 @@ export class PageViewManager {
72
70
 
73
71
  if (doFlush) {
74
72
  // We process at least one item so flush the queue
75
- _flushChannels();
73
+ _flushChannels(true);
76
74
  }
77
75
  }), 100);
78
76
  }
@@ -99,7 +97,7 @@ export class PageViewManager {
99
97
  pageView,
100
98
  customProperties
101
99
  );
102
- _flushChannels();
100
+ _flushChannels(true);
103
101
 
104
102
  // no navigation timing (IE 8, iOS Safari 8.4, Opera Mini 8 - see http://caniuse.com/#feat=nav-timing)
105
103
  _logger.throwInternal(
@@ -143,7 +141,7 @@ export class PageViewManager {
143
141
  pageView,
144
142
  customProperties
145
143
  );
146
- _flushChannels();
144
+ _flushChannels(true);
147
145
  pageViewSent = true;
148
146
  }
149
147
 
@@ -207,7 +205,24 @@ export class PageViewManager {
207
205
 
208
206
  return processed;
209
207
  });
210
- }
208
+ };
209
+
210
+ _self.teardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => {
211
+ if (intervalHandle) {
212
+ clearInterval(intervalHandle);
213
+ intervalHandle = null;
214
+
215
+ let allItems = itemQueue.slice(0);
216
+ let doFlush = false;
217
+ itemQueue = [];
218
+ arrForEach(allItems, (item) => {
219
+ if (item()) {
220
+ doFlush = true;
221
+ }
222
+ });
223
+ }
224
+ };
225
+
211
226
  });
212
227
  }
213
228
 
@@ -224,4 +239,8 @@ export class PageViewManager {
224
239
  public trackPageView(pageView: IPageViewTelemetry, customProperties?: { [key: string]: any }) {
225
240
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
226
241
  }
242
+
243
+ public teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) {
244
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
245
+ }
227
246
  }
@@ -125,15 +125,15 @@ export class PageViewPerformanceManager {
125
125
  return null;
126
126
  }
127
127
 
128
- /**
128
+ /**
129
129
  * Returns true is window PerformanceNavigationTiming API is supported, false otherwise.
130
130
  */
131
- public isPerformanceNavigationTimingSupported() {
131
+ public isPerformanceNavigationTimingSupported() {
132
132
  let perf = getPerformance();
133
133
  return perf && perf.getEntriesByType && perf.getEntriesByType("navigation").length > 0;
134
- }
134
+ }
135
135
 
136
- /**
136
+ /**
137
137
  * Returns true is window performance timing API is supported, false otherwise.
138
138
  */
139
139
  public isPerformanceTimingSupported() {
@@ -141,7 +141,7 @@ export class PageViewPerformanceManager {
141
141
  return perf && perf.timing;
142
142
  }
143
143
 
144
- /**
144
+ /**
145
145
  * As page loads different parts of performance timing numbers get set. When all of them are set we can report it.
146
146
  * Returns true if ready, false otherwise.
147
147
  */
@@ -160,7 +160,7 @@ export class PageViewPerformanceManager {
160
160
  && timing.domLoading > 0;
161
161
  }
162
162
 
163
- /**
163
+ /**
164
164
  * This method tells if given durations should be excluded from collection.
165
165
  */
166
166
  public shouldCollectDuration(...durations: number[]): boolean {
@@ -23,7 +23,7 @@ export class PageVisitTimeManager {
23
23
  this._logger = logger;
24
24
  }
25
25
 
26
- /**
26
+ /**
27
27
  * Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time
28
28
  * @param currentPageName Name of page to begin timing for visit duration
29
29
  * @param currentPageUrl Url of page to begin timing for visit duration
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { dateTimeUtilsDuration } from "@microsoft/applicationinsights-common";
5
+ import { IDiagnosticLogger, LoggingSeverity, _InternalMessageId, _throwInternal } from "@microsoft/applicationinsights-core-js";
6
+
7
+ /**
8
+ * Used to record timed events and page views.
9
+ */
10
+ export class Timing {
11
+
12
+ public action: (name?: string, url?: string, duration?: number, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => void;
13
+ public start: (name: string) => void;
14
+ public stop: (name: string, url: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => void;
15
+
16
+ constructor(logger: IDiagnosticLogger, name: string) {
17
+ let _self = this;
18
+ let _events: { [key: string]: number; } = {}
19
+
20
+ _self.start = (name: string) => {
21
+ if (typeof _events[name] !== "undefined") {
22
+ _throwInternal(logger,
23
+ LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.",
24
+ { name, key: name }, true);
25
+ }
26
+
27
+ _events[name] = +new Date;
28
+ }
29
+
30
+ _self.stop = (name: string, url: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => {
31
+ const start = _events[name];
32
+ if (isNaN(start)) {
33
+ _throwInternal(logger,
34
+ LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.",
35
+ { name, key: name }, true);
36
+ } else {
37
+ const end = +new Date;
38
+ const duration = dateTimeUtilsDuration(start, end);
39
+ _self.action(name, url, duration, properties, measurements);
40
+ }
41
+
42
+ delete _events[name];
43
+ _events[name] = undefined;
44
+ }
45
+ }
46
+ }
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
3
 
4
- export { ApplicationInsights } from "./JavaScriptSDK/ApplicationInsights";
4
+ export { AnalyticsPlugin, AnalyticsPlugin as ApplicationInsights } from "./JavaScriptSDK/AnalyticsPlugin";
5
5
  export { IAppInsightsInternal } from "./JavaScriptSDK/Telemetry/PageViewManager";
@@ -3,22 +3,17 @@
3
3
  * @copyright Microsoft 2018
4
4
  */
5
5
  import { IConfig, IAppInsights, IEventTelemetry, IExceptionTelemetry, ITraceTelemetry, IMetricTelemetry, IAutoExceptionTelemetry, IPageViewTelemetryInternal, IPageViewTelemetry, IPageViewPerformanceTelemetry, IPageViewPerformanceTelemetryInternal } from "@microsoft/applicationinsights-common";
6
- import { IPlugin, IConfiguration, IAppInsightsCore, BaseTelemetryPlugin, ITelemetryItem, IProcessTelemetryContext, ITelemetryPluginChain, ICustomProperties, ICookieMgr } from "@microsoft/applicationinsights-core-js";
7
- import { PageViewManager, IAppInsightsInternal } from "./Telemetry/PageViewManager";
8
- import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
9
- import { PageViewPerformanceManager } from "./Telemetry/PageViewPerformanceManager";
10
- export declare class ApplicationInsights extends BaseTelemetryPlugin implements IAppInsights, IAppInsightsInternal {
6
+ import { IPlugin, IConfiguration, IAppInsightsCore, BaseTelemetryPlugin, ITelemetryItem, IProcessTelemetryContext, ITelemetryPluginChain, ICustomProperties, ICookieMgr, ITelemetryInitializerHandler } from "@microsoft/applicationinsights-core-js";
7
+ import { IAppInsightsInternal } from "./Telemetry/PageViewManager";
8
+ declare function _getDefaultConfig(config?: IConfig): IConfig;
9
+ export declare class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights, IAppInsightsInternal {
11
10
  static Version: string;
12
- static getDefaultConfig(config?: IConfig): IConfig;
11
+ static getDefaultConfig: typeof _getDefaultConfig;
13
12
  identifier: string;
14
13
  priority: number;
15
14
  config: IConfig;
16
15
  queue: Array<() => void>;
17
16
  autoRoutePVDelay: number;
18
- protected _telemetryInitializers: Array<(envelope: ITelemetryItem) => boolean | void>;
19
- protected _pageViewManager: PageViewManager;
20
- protected _pageViewPerformanceManager: PageViewPerformanceManager;
21
- protected _pageVisitTimeManager: PageVisitTimeManager;
22
17
  constructor();
23
18
  /**
24
19
  * Get the current cookie manager for this instance
@@ -116,11 +111,11 @@ export declare class ApplicationInsights extends BaseTelemetryPlugin implements
116
111
  [key: string]: number;
117
112
  }): void;
118
113
  /**
119
- * @ignore INTERNAL ONLY
120
- * @param exception
121
- * @param properties
122
- * @param systemProperties
123
- */
114
+ * @ignore INTERNAL ONLY
115
+ * @param exception
116
+ * @param properties
117
+ * @param systemProperties
118
+ */
124
119
  sendExceptionInternal(exception: IExceptionTelemetry, customProperties?: {
125
120
  [key: string]: any;
126
121
  }, systemProperties?: {
@@ -142,6 +137,7 @@ export declare class ApplicationInsights extends BaseTelemetryPlugin implements
142
137
  * @memberof ApplicationInsights
143
138
  */
144
139
  _onerror(exception: IAutoExceptionTelemetry): void;
145
- addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): void;
140
+ addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler | void;
146
141
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
147
142
  }
143
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { IPageViewTelemetry, IPageViewTelemetryInternal, IPageViewPerformanceTelemetryInternal } from "@microsoft/applicationinsights-common";
2
- import { IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
2
+ import { IAppInsightsCore, IProcessTelemetryUnloadContext, ITelemetryUnloadState } from "@microsoft/applicationinsights-core-js";
3
3
  import { PageViewPerformanceManager } from "./PageViewPerformanceManager";
4
4
  /**
5
5
  * Internal interface to pass appInsights object to subcomponents without coupling
@@ -26,4 +26,5 @@ export declare class PageViewManager {
26
26
  trackPageView(pageView: IPageViewTelemetry, customProperties?: {
27
27
  [key: string]: any;
28
28
  }): void;
29
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void;
29
30
  }
@@ -11,20 +11,20 @@ export declare class PageViewPerformanceManager {
11
11
  getPerformanceTiming(): PerformanceTiming | null;
12
12
  getPerformanceNavigationTiming(): PerformanceNavigationTiming | null;
13
13
  /**
14
- * Returns true is window PerformanceNavigationTiming API is supported, false otherwise.
15
- */
14
+ * Returns true is window PerformanceNavigationTiming API is supported, false otherwise.
15
+ */
16
16
  isPerformanceNavigationTimingSupported(): boolean;
17
17
  /**
18
- * Returns true is window performance timing API is supported, false otherwise.
19
- */
18
+ * Returns true is window performance timing API is supported, false otherwise.
19
+ */
20
20
  isPerformanceTimingSupported(): PerformanceTiming;
21
21
  /**
22
- * As page loads different parts of performance timing numbers get set. When all of them are set we can report it.
23
- * Returns true if ready, false otherwise.
24
- */
22
+ * As page loads different parts of performance timing numbers get set. When all of them are set we can report it.
23
+ * Returns true if ready, false otherwise.
24
+ */
25
25
  isPerformanceTimingDataReady(): boolean;
26
26
  /**
27
- * This method tells if given durations should be excluded from collection.
28
- */
27
+ * This method tells if given durations should be excluded from collection.
28
+ */
29
29
  shouldCollectDuration(...durations: number[]): boolean;
30
30
  }
@@ -13,10 +13,10 @@ export declare class PageVisitTimeManager {
13
13
  */
14
14
  constructor(logger: IDiagnosticLogger, pageVisitTimeTrackingHandler: (pageName: string, pageUrl: string, pageVisitTime: number) => void);
15
15
  /**
16
- * Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time
17
- * @param currentPageName Name of page to begin timing for visit duration
18
- * @param currentPageUrl Url of page to begin timing for visit duration
19
- */
16
+ * Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time
17
+ * @param currentPageName Name of page to begin timing for visit duration
18
+ * @param currentPageUrl Url of page to begin timing for visit duration
19
+ */
20
20
  trackPreviousPageVisit(currentPageName: string, currentPageUrl: string): void;
21
21
  /**
22
22
  * Stops timing of current page (if exists) and starts timing for duration of visit to pageName
@@ -0,0 +1,18 @@
1
+ import { IDiagnosticLogger } from "@microsoft/applicationinsights-core-js";
2
+ /**
3
+ * Used to record timed events and page views.
4
+ */
5
+ export declare class Timing {
6
+ action: (name?: string, url?: string, duration?: number, properties?: {
7
+ [key: string]: string;
8
+ }, measurements?: {
9
+ [key: string]: number;
10
+ }) => void;
11
+ start: (name: string) => void;
12
+ stop: (name: string, url: string, properties?: {
13
+ [key: string]: string;
14
+ }, measurements?: {
15
+ [key: string]: number;
16
+ }) => void;
17
+ constructor(logger: IDiagnosticLogger, name: string);
18
+ }
@@ -1,2 +1,2 @@
1
- export { ApplicationInsights } from "./JavaScriptSDK/ApplicationInsights";
1
+ export { AnalyticsPlugin, AnalyticsPlugin as ApplicationInsights } from "./JavaScriptSDK/AnalyticsPlugin";
2
2
  export { IAppInsightsInternal } from "./JavaScriptSDK/Telemetry/PageViewManager";
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.19.4"
8
+ "packageVersion": "7.19.5"
9
9
  }
10
10
  ]
11
11
  }