@microsoft/applicationinsights-analytics-js 3.0.0-beta.2210-01 → 3.0.0-beta.2210-02

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 (33) hide show
  1. package/browser/applicationinsights-analytics-js.integrity.json +9 -9
  2. package/browser/applicationinsights-analytics-js.js +1013 -542
  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 +5 -43
  7. package/dist/applicationinsights-analytics-js.api.md +2 -6
  8. package/dist/applicationinsights-analytics-js.d.ts +15 -18
  9. package/dist/applicationinsights-analytics-js.js +1013 -542
  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 +15 -18
  14. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js +155 -148
  15. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js +14 -15
  17. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +9 -10
  19. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +8 -9
  21. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Timing.js +1 -1
  23. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
  24. package/dist-esm/__DynamicConstants.js +16 -24
  25. package/dist-esm/__DynamicConstants.js.map +1 -1
  26. package/dist-esm/applicationinsights-analytics-js.js +1 -1
  27. package/package.json +6 -6
  28. package/src/JavaScriptSDK/AnalyticsPlugin.ts +177 -175
  29. package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +4 -4
  30. package/src/__DynamicConstants.ts +15 -23
  31. package/types/JavaScriptSDK/AnalyticsPlugin.d.ts +14 -17
  32. package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +3 -3
  33. package/types/__DynamicConstants.d.ts +15 -23
@@ -13,14 +13,15 @@ import {
13
13
  utlEnableStorage
14
14
  } from "@microsoft/applicationinsights-common";
15
15
  import {
16
- BaseTelemetryPlugin, IAppInsightsCore, IConfiguration, ICookieMgr, ICustomProperties, IDistributedTraceContext, IInstrumentCallDetails,
17
- IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryInitializerHandler, ITelemetryItem, ITelemetryPluginChain,
18
- ITelemetryUnloadState, InstrumentEvent, TelemetryInitializerFunction, _eInternalMessageId, arrForEach, createProcessTelemetryContext,
19
- createUniqueNamespace, dumpObj, eLoggingSeverity, eventOff, eventOn, generateW3CId, getDocument, getExceptionName, getHistory,
20
- getLocation, getWindow, hasHistory, hasWindow, isFunction, isNullOrUndefined, isString, isUndefined, mergeEvtNamespace,
21
- objDefineAccessors, objForEachKey, safeGetCookieMgr, strUndefined, throwError
16
+ BaseTelemetryPlugin, IAppInsightsCore, IConfigDefaults, IConfiguration, ICookieMgr, ICustomProperties, IDistributedTraceContext,
17
+ IInstrumentCallDetails, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryInitializerHandler, ITelemetryItem,
18
+ ITelemetryPluginChain, ITelemetryUnloadState, InstrumentEvent, TelemetryInitializerFunction, _eInternalMessageId, arrForEach,
19
+ createProcessTelemetryContext, createUniqueNamespace, dumpObj, eLoggingSeverity, eventOff, eventOn, generateW3CId, getDocument,
20
+ getExceptionName, getHistory, getLocation, getWindow, hasHistory, hasWindow, isFunction, isNullOrUndefined, isString, isUndefined,
21
+ mergeEvtNamespace, objDefineAccessors, onConfigChange, safeGetCookieMgr, strUndefined, throwError
22
22
  } from "@microsoft/applicationinsights-core-js";
23
23
  import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
24
+ import { objDeepFreeze, objDefineProp } from "@nevware21/ts-utils";
24
25
  import { IAppInsightsInternal, PageViewManager } from "./Telemetry/PageViewManager";
25
26
  import { PageViewPerformanceManager } from "./Telemetry/PageViewPerformanceManager";
26
27
  import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
@@ -50,42 +51,35 @@ function _getReason(error: any) {
50
51
 
51
52
  const MinMilliSeconds = 60000;
52
53
 
53
- function _configMilliseconds(value: number, defValue: number) {
54
+ const defaultValues: IConfigDefaults<IConfig> = objDeepFreeze({
55
+ sessionRenewalMs: { set: _chkConfigMilliseconds, v:30 * 60 * 1000 },
56
+ sessionExpirationMs: { set: _chkConfigMilliseconds, v: 24 * 60 * 60 * 1000 },
57
+ disableExceptionTracking: { set: stringToBoolOrDefault },
58
+ autoTrackPageVisitTime: { set: stringToBoolOrDefault },
59
+ overridePageViewDuration: { set: stringToBoolOrDefault },
60
+ enableUnhandledPromiseRejectionTracking: { set: stringToBoolOrDefault },
61
+ autoUnhandledPromiseInstrumented: false,
62
+ samplingPercentage: { isVal: _chkSampling, v: 100 },
63
+ isStorageUseDisabled: { set: stringToBoolOrDefault },
64
+ isBrowserLinkTrackingEnabled: { set: stringToBoolOrDefault },
65
+ enableAutoRouteTracking: { set: stringToBoolOrDefault },
66
+ namePrefix: "",
67
+ enableDebug: { set: stringToBoolOrDefault },
68
+ disableFlushOnBeforeUnload: { set: stringToBoolOrDefault },
69
+ disableFlushOnUnload: { set: stringToBoolOrDefault, fb: "disableFlushOnBeforeUnload" }
70
+ });
71
+
72
+ function _chkConfigMilliseconds(value: number, defValue: number): number {
54
73
  value = value || defValue;
55
74
  if (value < MinMilliSeconds) {
56
75
  value = MinMilliSeconds;
57
76
  }
58
77
 
59
- return value;
78
+ return +value;
60
79
  }
61
80
 
62
- function _getDefaultConfig(config?: IConfig): IConfig {
63
- if (!config) {
64
- config = {};
65
- }
66
-
67
- // set default values
68
- config.sessionRenewalMs = _configMilliseconds(config.sessionRenewalMs, 30 * 60 * 1000);
69
- config.sessionExpirationMs = _configMilliseconds(config.sessionExpirationMs, 24 * 60 * 60 * 1000);
70
- config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
71
- config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
72
- config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
73
- config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
74
-
75
- if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
76
- config.samplingPercentage = 100;
77
- }
78
-
79
- config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
80
- config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
81
- config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
82
- config.namePrefix = config.namePrefix || "";
83
-
84
- config.enableDebug = stringToBoolOrDefault(config.enableDebug);
85
- config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
86
- config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
87
-
88
- return config;
81
+ function _chkSampling(value: number) {
82
+ return !isNaN(value) && value > 0 && value <= 100;
89
83
  }
90
84
 
91
85
  function _updateStorageUsage(extConfig: IConfig) {
@@ -103,11 +97,9 @@ function _updateStorageUsage(extConfig: IConfig) {
103
97
  export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights, IAppInsightsInternal {
104
98
  public static Version = "#version#"; // Not currently used anywhere
105
99
 
106
- public static getDefaultConfig = _getDefaultConfig;
107
-
108
100
  public identifier: string = AnalyticsPluginIdentifier; // do not change name or priority
109
101
  public priority: number = 180; // take from reserved priority range 100- 200
110
- public config: IConfig;
102
+ public readonly config: IConfig;
111
103
  public queue: Array<() => void>;
112
104
  public autoRoutePVDelay = 500; // ms; Time to wait after a route change before triggering a pageview to allow DOM changes to take place
113
105
 
@@ -127,6 +119,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
127
119
  let _autoExceptionInstrumented: boolean;
128
120
  let _enableUnhandledPromiseRejectionTracking: boolean;
129
121
  let _autoUnhandledPromiseInstrumented: boolean;
122
+ let _extConfig: IConfig;
123
+ let _autoTrackPageVisitTime: boolean;
130
124
 
131
125
  // Counts number of trackAjax invocations.
132
126
  // By default we only monitor X ajax call per view to avoid too much load.
@@ -205,7 +199,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
205
199
 
206
200
  /**
207
201
  * @description Log a diagnostic message
208
- * @param {ITraceTelemetry} trace
202
+ * @param trace
209
203
  * @param ICustomProperties.
210
204
  * @memberof ApplicationInsights
211
205
  */
@@ -233,8 +227,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
233
227
  * use the name and average fields of {@link IMetricTelemetry}. If you take measurements
234
228
  * frequently, you can reduce the telemetry bandwidth by aggregating multiple measurements
235
229
  * and sending the resulting average at intervals
236
- * @param {IMetricTelemetry} metric input object argument. Only name and average are mandatory.
237
- * @param {{[key: string]: any}} customProperties additional data used to filter metrics in the
230
+ * @param metric - input object argument. Only name and average are mandatory.
231
+ * @param } customProperties additional data used to filter metrics in the
238
232
  * portal. Defaults to empty.
239
233
  * @memberof ApplicationInsights
240
234
  */
@@ -259,8 +253,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
259
253
 
260
254
  /**
261
255
  * Logs that a page or other item was viewed.
262
- * @param IPageViewTelemetry The string you used as the name in startTrackPage. Defaults to the document title.
263
- * @param customProperties Additional data used to filter events and metrics. Defaults to empty.
256
+ * @param IPageViewTelemetry - The string you used as the name in startTrackPage. Defaults to the document title.
257
+ * @param customProperties - Additional data used to filter events and metrics. Defaults to empty.
264
258
  * If a user wants to provide duration for pageLoad, it'll have to be in pageView.properties.duration
265
259
  */
266
260
  _self.trackPageView = (pageView?: IPageViewTelemetry, customProperties?: ICustomProperties) => {
@@ -268,7 +262,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
268
262
  let inPv = pageView || {};
269
263
  _pageViewManager.trackPageView(inPv, {...inPv.properties, ...inPv.measurements, ...customProperties});
270
264
 
271
- if (_self.config.autoTrackPageVisitTime) {
265
+ if (_autoTrackPageVisitTime) {
272
266
  _pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
273
267
  }
274
268
  } catch (e) {
@@ -282,9 +276,9 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
282
276
 
283
277
  /**
284
278
  * Create a page view telemetry item and send it to the SDK pipeline through the core.track API
285
- * @param pageView Page view item to be sent
286
- * @param properties Custom properties (Part C) that a user can add to the telemetry item
287
- * @param systemProperties System level properties (Part A) that a user can add to the telemetry item
279
+ * @param pageView - Page view item to be sent
280
+ * @param properties - Custom properties (Part C) that a user can add to the telemetry item
281
+ * @param systemProperties - System level properties (Part A) that a user can add to the telemetry item
288
282
  */
289
283
  _self.sendPageViewInternal = (pageView: IPageViewTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) => {
290
284
  let doc = getDocument();
@@ -346,7 +340,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
346
340
  * Starts the timer for tracking a page load time. Use this instead of `trackPageView` if you want to control when the page view timer starts and stops,
347
341
  * but don't want to calculate the duration yourself. This method doesn't send any telemetry. Call `stopTrackPage` to log the end of the page view
348
342
  * and send the event.
349
- * @param name A string that idenfities this item, unique within this HTML document. Defaults to the document title.
343
+ * @param name - A string that idenfities this item, unique within this HTML document. Defaults to the document title.
350
344
  */
351
345
  _self.startTrackPage = (name?: string) => {
352
346
  try {
@@ -387,7 +381,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
387
381
 
388
382
  _pageTracking.stop(name, url, properties, measurement);
389
383
 
390
- if (_self.config.autoTrackPageVisitTime) {
384
+ if (_autoTrackPageVisitTime) {
391
385
  _pageVisitTimeManager.trackPreviousPageVisit(name, url);
392
386
  }
393
387
  } catch (e) {
@@ -430,8 +424,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
430
424
  /**
431
425
  * Log an exception you have caught.
432
426
  *
433
- * @param {IExceptionTelemetry} exception Object which contains exception to be sent
434
- * @param {{[key: string]: any}} customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
427
+ * @param exception - Object which contains exception to be sent
428
+ * @param } customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
435
429
  *
436
430
  * Any property of type double will be considered a measurement, and will be treated by Application Insights as a metric.
437
431
  * @memberof ApplicationInsights
@@ -454,7 +448,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
454
448
 
455
449
  /**
456
450
  * @description Custom error handler for Application Insights Analytics
457
- * @param {IAutoExceptionTelemetry} exception
451
+ * @param exception
458
452
  * @memberof ApplicationInsights
459
453
  */
460
454
  _self._onerror = (exception: IAutoExceptionTelemetry): void => {
@@ -509,7 +503,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
509
503
  }
510
504
  };
511
505
 
512
- _self.addTelemetryInitializer = (telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void => {
506
+ _self.addTelemetryInitializer = (telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler => {
513
507
  if (_self.core) {
514
508
  // Just add to the core
515
509
  return _self.core.addTelemetryInitializer(telemetryInitializer);
@@ -543,15 +537,12 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
543
537
  _preInitTelemetryInitializers = null;
544
538
  }
545
539
 
546
- let extConfig = _populateDefaults(config);
547
- _updateStorageUsage(extConfig);
540
+ _populateDefaults(config);
548
541
 
549
542
  _pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
550
- _pageViewManager = new PageViewManager(this, extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
543
+ _pageViewManager = new PageViewManager(this, _extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
551
544
  _pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), (pageName, pageUrl, pageVisitTime) => trackPageVisitTime(pageName, pageUrl, pageVisitTime))
552
-
553
- _updateBrowserLinkTracking(extConfig, config);
554
-
545
+
555
546
  _eventTracking = new Timing(_self.diagLog(), "trackEvent");
556
547
  _eventTracking.action =
557
548
  (name?: string, url?: string, duration?: number, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => {
@@ -588,8 +579,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
588
579
  }
589
580
 
590
581
  if (hasWindow()) {
591
- _updateExceptionTracking(extConfig);
592
- _updateLocationChange(extConfig);
582
+ _updateExceptionTracking();
583
+ _updateLocationChange();
593
584
  }
594
585
 
595
586
  } catch (e) {
@@ -608,35 +599,27 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
608
599
  };
609
600
 
610
601
  function _populateDefaults(config: IConfiguration) {
611
- let ctx = createProcessTelemetryContext(null, config, _self.core);
612
602
  let identifier = _self.identifier;
603
+ let core = _self.core;
613
604
 
614
- // load default values if specified
615
- const defaults: IConfig = _getDefaultConfig(config);
616
- let extConfig = _self.config = ctx.getExtCfg<IConfig>(identifier);
605
+ _self._addHook(onConfigChange(config, () => {
606
+ let ctx = createProcessTelemetryContext(null, config, core);
607
+ _extConfig = ctx.getExtCfg(identifier, defaultValues);
617
608
 
618
- if (defaults !== undefined) {
619
- objForEachKey(defaults, (field, value) => {
620
- // for each unspecified field, set the default value
621
- extConfig[field] = ctx.getConfig(identifier, field, value);
622
- if (extConfig[field] === undefined) {
623
- extConfig = value;
624
- }
625
- });
626
- }
609
+ _autoTrackPageVisitTime = _extConfig.autoTrackPageVisitTime;
627
610
 
628
- return extConfig;
629
- }
611
+ _updateStorageUsage(_extConfig);
630
612
 
631
- function _updateBrowserLinkTracking(extConfig: IConfig, config: IConfig) {
632
- _isBrowserLinkTrackingEnabled = extConfig.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled;
633
- _addDefaultTelemetryInitializers();
613
+ // _updateBrowserLinkTracking
614
+ _isBrowserLinkTrackingEnabled = _extConfig.isBrowserLinkTrackingEnabled;
615
+ _addDefaultTelemetryInitializers();
616
+ }));
634
617
  }
635
618
 
636
619
  /**
637
620
  * Log a page visit time
638
621
  * @param pageName Name of page
639
- * @param pageVisitDuration Duration of visit to the page in milleseconds
622
+ * @param pageVisitDuration Duration of visit to the page in milliseconds
640
623
  */
641
624
  function trackPageVisitTime(pageName: string, pageUrl: string, pageVisitTime: number) {
642
625
  let properties = { PageName: pageName, PageUrl: pageUrl };
@@ -667,7 +650,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
667
650
  return true;
668
651
  }
669
652
 
670
- _self.addTelemetryInitializer(dropBrowserLinkRequests);
653
+ _self._addHook(_self.addTelemetryInitializer(dropBrowserLinkRequests));
671
654
  _browserLinkInitializerAdded = true;
672
655
  }
673
656
  }
@@ -684,52 +667,56 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
684
667
  _self.core.track(telemetryItem);
685
668
  }
686
669
 
687
- function _updateExceptionTracking(extConfig: IConfig) {
670
+ function _updateExceptionTracking() {
688
671
  let _window = getWindow();
689
672
  let locn = getLocation(true);
690
673
 
691
- _disableExceptionTracking = extConfig.disableExceptionTracking;
692
-
693
- if (!_disableExceptionTracking && !_autoExceptionInstrumented && !extConfig.autoExceptionInstrumented) {
694
- // We want to enable exception auto collection and it has not been done so yet
695
- _addHook(InstrumentEvent(_window, "onerror", {
696
- ns: _evtNamespace,
697
- rsp: (callDetails: IInstrumentCallDetails, message, url, lineNumber, columnNumber, error) => {
698
- if (!_disableExceptionTracking && callDetails.rslt !== true) {
699
- _self._onerror(Exception.CreateAutoException(
700
- message,
701
- url,
702
- lineNumber,
703
- columnNumber,
704
- error,
705
- callDetails.evt
706
- ));
674
+ _self._addHook(onConfigChange(_extConfig, () => {
675
+ _disableExceptionTracking = _extConfig.disableExceptionTracking;
676
+
677
+ if (!_disableExceptionTracking && !_autoExceptionInstrumented && !_extConfig.autoExceptionInstrumented) {
678
+ // We want to enable exception auto collection and it has not been done so yet
679
+ _addHook(InstrumentEvent(_window, "onerror", {
680
+ ns: _evtNamespace,
681
+ rsp: (callDetails: IInstrumentCallDetails, message, url, lineNumber, columnNumber, error) => {
682
+ if (!_disableExceptionTracking && callDetails.rslt !== true) {
683
+ _self._onerror(Exception.CreateAutoException(
684
+ message,
685
+ url,
686
+ lineNumber,
687
+ columnNumber,
688
+ error,
689
+ callDetails.evt
690
+ ));
691
+ }
707
692
  }
708
- }
709
- }, false));
693
+ }, false));
710
694
 
711
- _autoExceptionInstrumented = true;
712
- }
695
+ _autoExceptionInstrumented = true;
696
+ }
697
+ }));
713
698
 
714
- _addUnhandledPromiseRejectionTracking(extConfig, _window, locn);
699
+ _addUnhandledPromiseRejectionTracking(_window, locn);
715
700
  }
716
701
 
717
- function _updateLocationChange(extConfig: IConfig) {
702
+ function _updateLocationChange() {
718
703
  let win = getWindow();
719
704
  let locn = getLocation(true);
720
705
 
721
- _enableAutoRouteTracking = extConfig.enableAutoRouteTracking === true;
706
+ _self._addHook(onConfigChange(_extConfig, () => {
707
+ _enableAutoRouteTracking = _extConfig.enableAutoRouteTracking === true;
722
708
 
723
- /**
724
- * Create a custom "locationchange" event which is triggered each time the history object is changed
725
- */
726
- if (win && _enableAutoRouteTracking && hasHistory()) {
727
- let _history = getHistory();
709
+ /**
710
+ * Create a custom "locationchange" event which is triggered each time the history object is changed
711
+ */
712
+ if (win && _enableAutoRouteTracking && !_historyListenerAdded && hasHistory()) {
713
+ let _history = getHistory();
728
714
 
729
- if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strUndefined) {
730
- _addHistoryListener(extConfig, win, _history, locn);
715
+ if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strUndefined) {
716
+ _addHistoryListener(win, _history, locn);
717
+ }
731
718
  }
732
- }
719
+ }));
733
720
  }
734
721
 
735
722
  function _getDistributedTraceCtx(): IDistributedTraceContext {
@@ -755,9 +742,13 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
755
742
  /**
756
743
  * Create a custom "locationchange" event which is triggered each time the history object is changed
757
744
  */
758
- function _addHistoryListener(extConfig: IConfig, win: Window, history: History, locn: Location) {
745
+ function _addHistoryListener(win: Window, history: History, locn: Location) {
746
+ if (_historyListenerAdded) {
747
+ return;
748
+ }
759
749
 
760
- let namePrefix = extConfig.namePrefix || "";
750
+ // Name Prefix is only referenced during the initial initialization and cannot be changed afterwards
751
+ let namePrefix = _extConfig.namePrefix || "";
761
752
 
762
753
  function _popstateHandler() {
763
754
  if (_enableAutoRouteTracking) {
@@ -794,64 +785,65 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
794
785
  }
795
786
  }
796
787
 
797
- if (!_historyListenerAdded) {
798
- _addHook(InstrumentEvent(history, "pushState", {
799
- ns: _evtNamespace,
800
- rsp: () => {
801
- if (_enableAutoRouteTracking) {
802
- _dispatchEvent(win, createDomEvent(namePrefix + "pushState"));
803
- _dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
804
- }
788
+ _addHook(InstrumentEvent(history, "pushState", {
789
+ ns: _evtNamespace,
790
+ rsp: () => {
791
+ if (_enableAutoRouteTracking) {
792
+ _dispatchEvent(win, createDomEvent(namePrefix + "pushState"));
793
+ _dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
805
794
  }
806
- }, true));
807
-
808
- _addHook(InstrumentEvent(history, "replaceState", {
809
- ns: _evtNamespace,
810
- rsp: () => {
811
- if (_enableAutoRouteTracking) {
812
- _dispatchEvent(win, createDomEvent(namePrefix + "replaceState"));
813
- _dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
814
- }
795
+ }
796
+ }, true));
797
+
798
+ _addHook(InstrumentEvent(history, "replaceState", {
799
+ ns: _evtNamespace,
800
+ rsp: () => {
801
+ if (_enableAutoRouteTracking) {
802
+ _dispatchEvent(win, createDomEvent(namePrefix + "replaceState"));
803
+ _dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
815
804
  }
816
- }, true));
805
+ }
806
+ }, true));
817
807
 
818
- eventOn(win, namePrefix + "popstate", _popstateHandler, _evtNamespace);
819
- eventOn(win, namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
808
+ eventOn(win, namePrefix + "popstate", _popstateHandler, _evtNamespace);
809
+ eventOn(win, namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
820
810
 
821
- _historyListenerAdded = true;
822
- }
811
+ _historyListenerAdded = true;
823
812
  }
824
813
 
825
- function _addUnhandledPromiseRejectionTracking(extConfig: IConfig, _window: Window, _location: Location) {
826
- _enableUnhandledPromiseRejectionTracking = extConfig.enableUnhandledPromiseRejectionTracking === true;
827
-
828
- if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
829
- // We want to enable exception auto collection and it has not been done so yet
830
- _addHook(InstrumentEvent(_window, "onunhandledrejection", {
831
- ns: _evtNamespace,
832
- rsp: (callDetails: IInstrumentCallDetails, error: PromiseRejectionEvent) => {
833
- if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) { // handled could be typeof function
834
- _self._onerror(Exception.CreateAutoException(
835
- _getReason(error),
836
- _location ? _location.href : "",
837
- 0,
838
- 0,
839
- error,
840
- callDetails.evt
841
- ));
814
+ function _addUnhandledPromiseRejectionTracking(_window: Window, _location: Location) {
815
+ _self._addHook(onConfigChange(_extConfig, () => {
816
+
817
+ _enableUnhandledPromiseRejectionTracking = _extConfig.enableUnhandledPromiseRejectionTracking === true;
818
+ _autoExceptionInstrumented = _autoExceptionInstrumented || _extConfig.autoUnhandledPromiseInstrumented;
819
+
820
+ if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
821
+ // We want to enable exception auto collection and it has not been done so yet
822
+ _addHook(InstrumentEvent(_window, "onunhandledrejection", {
823
+ ns: _evtNamespace,
824
+ rsp: (callDetails: IInstrumentCallDetails, error: PromiseRejectionEvent) => {
825
+ if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) { // handled could be typeof function
826
+ _self._onerror(Exception.CreateAutoException(
827
+ _getReason(error),
828
+ _location ? _location.href : "",
829
+ 0,
830
+ 0,
831
+ error,
832
+ callDetails.evt
833
+ ));
834
+ }
842
835
  }
843
- }
844
- }, false));
845
-
846
- _autoUnhandledPromiseInstrumented = true;
847
- extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented;
848
- }
836
+ }, false));
837
+
838
+ _extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented = true;
839
+ }
840
+ }));
849
841
  }
850
842
 
851
843
  /**
852
844
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
853
- * @param severity {eLoggingSeverity} - The severity of the log message
854
- * @param message {_InternalLogMessage} - The log message.
845
+ * @param severity - {eLoggingSeverity} - The severity of the log message
846
+ * @param msgId - {_eInternalLogMessage} - The log message.
855
847
  */
856
848
  function _throwInternal(severity: eLoggingSeverity, msgId: _eInternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void {
857
849
  _self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
@@ -872,6 +864,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
872
864
  _autoExceptionInstrumented = false;
873
865
  _enableUnhandledPromiseRejectionTracking = false;
874
866
  _autoUnhandledPromiseInstrumented = false;
867
+ _autoTrackPageVisitTime = false;
875
868
 
876
869
  // Counts number of trackAjax invocations.
877
870
  // By default we only monitor X ajax call per view to avoid too much load.
@@ -884,6 +877,14 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
884
877
  _prevUri = location && location.href || "";
885
878
  _currUri = null;
886
879
  _evtNamespace = null;
880
+ _extConfig = null;
881
+
882
+ // Define _self.config
883
+ objDefineProp(_self, "config", {
884
+ configurable: true,
885
+ enumerable: true,
886
+ get: () => _extConfig
887
+ });
887
888
  }
888
889
 
889
890
  // For backward compatibility
@@ -930,7 +931,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
930
931
 
931
932
  /**
932
933
  * @description Log a diagnostic message
933
- * @param {ITraceTelemetry} trace
934
+ * @param trace
934
935
  * @param ICustomProperties.
935
936
  * @memberof ApplicationInsights
936
937
  */
@@ -944,8 +945,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
944
945
  * use the name and average fields of {@link IMetricTelemetry}. If you take measurements
945
946
  * frequently, you can reduce the telemetry bandwidth by aggregating multiple measurements
946
947
  * and sending the resulting average at intervals
947
- * @param {IMetricTelemetry} metric input object argument. Only name and average are mandatory.
948
- * @param {{[key: string]: any}} customProperties additional data used to filter metrics in the
948
+ * @param metric - input object argument. Only name and average are mandatory.
949
+ * @param } customProperties additional data used to filter metrics in the
949
950
  * portal. Defaults to empty.
950
951
  * @memberof ApplicationInsights
951
952
  */
@@ -955,8 +956,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
955
956
 
956
957
  /**
957
958
  * Logs that a page or other item was viewed.
958
- * @param IPageViewTelemetry The string you used as the name in startTrackPage. Defaults to the document title.
959
- * @param customProperties Additional data used to filter events and metrics. Defaults to empty.
959
+ * @param IPageViewTelemetry - The string you used as the name in startTrackPage. Defaults to the document title.
960
+ * @param customProperties - Additional data used to filter events and metrics. Defaults to empty.
960
961
  * If a user wants to provide duration for pageLoad, it'll have to be in pageView.properties.duration
961
962
  */
962
963
  public trackPageView(pageView?: IPageViewTelemetry, customProperties?: ICustomProperties) {
@@ -965,9 +966,9 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
965
966
 
966
967
  /**
967
968
  * Create a page view telemetry item and send it to the SDK pipeline through the core.track API
968
- * @param pageView Page view item to be sent
969
- * @param properties Custom properties (Part C) that a user can add to the telemetry item
970
- * @param systemProperties System level properties (Part A) that a user can add to the telemetry item
969
+ * @param pageView - Page view item to be sent
970
+ * @param properties - Custom properties (Part C) that a user can add to the telemetry item
971
+ * @param systemProperties - System level properties (Part A) that a user can add to the telemetry item
971
972
  */
972
973
  public sendPageViewInternal(pageView: IPageViewTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) {
973
974
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
@@ -995,7 +996,7 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
995
996
  * Starts the timer for tracking a page load time. Use this instead of `trackPageView` if you want to control when the page view timer starts and stops,
996
997
  * but don't want to calculate the duration yourself. This method doesn't send any telemetry. Call `stopTrackPage` to log the end of the page view
997
998
  * and send the event.
998
- * @param name A string that idenfities this item, unique within this HTML document. Defaults to the document title.
999
+ * @param name - A string that idenfities this item, unique within this HTML document. Defaults to the document title.
999
1000
  */
1000
1001
  public startTrackPage(name?: string) {
1001
1002
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
@@ -1026,8 +1027,8 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
1026
1027
  /**
1027
1028
  * Log an exception you have caught.
1028
1029
  *
1029
- * @param {IExceptionTelemetry} exception Object which contains exception to be sent
1030
- * @param {{[key: string]: any}} customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
1030
+ * @param exception - Object which contains exception to be sent
1031
+ * @param } customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
1031
1032
  *
1032
1033
  * Any property of type double will be considered a measurement, and will be treated by Application Insights as a metric.
1033
1034
  * @memberof ApplicationInsights
@@ -1038,15 +1039,16 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
1038
1039
 
1039
1040
  /**
1040
1041
  * @description Custom error handler for Application Insights Analytics
1041
- * @param {IAutoExceptionTelemetry} exception
1042
+ * @param exception
1042
1043
  * @memberof ApplicationInsights
1043
1044
  */
1044
1045
  public _onerror(exception: IAutoExceptionTelemetry): void {
1045
1046
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
1046
1047
  }
1047
1048
 
1048
- public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler | void {
1049
+ public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler {
1049
1050
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
1051
+ return null;
1050
1052
  }
1051
1053
 
1052
1054
  public initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) {
@@ -16,7 +16,7 @@ export class PageVisitTimeManager {
16
16
 
17
17
  /**
18
18
  * Creates a new instance of PageVisitTimeManager
19
- * @param pageVisitTimeTrackingHandler Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)
19
+ * @param pageVisitTimeTrackingHandler - Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)
20
20
  * @returns {}
21
21
  */
22
22
  constructor(logger: IDiagnosticLogger, pageVisitTimeTrackingHandler: (pageName: string, pageUrl: string, pageVisitTime: number) => void) {
@@ -40,7 +40,7 @@ export class PageVisitTimeManager {
40
40
 
41
41
  /**
42
42
  * Stops timing of current page (if exists) and starts timing for duration of visit to pageName
43
- * @param pageName Name of page to begin timing visit duration
43
+ * @param pageName - Name of page to begin timing visit duration
44
44
  * @returns {PageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.
45
45
  */
46
46
  function restartPageVisitTimer(pageName: string, pageUrl: string) {
@@ -119,8 +119,8 @@ export class PageVisitTimeManager {
119
119
 
120
120
  /**
121
121
  * Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time
122
- * @param currentPageName Name of page to begin timing for visit duration
123
- * @param currentPageUrl Url of page to begin timing for visit duration
122
+ * @param currentPageName - Name of page to begin timing for visit duration
123
+ * @param currentPageUrl - Url of page to begin timing for visit duration
124
124
  */
125
125
  public trackPreviousPageVisit(currentPageName: string, currentPageUrl: string): void {
126
126
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging