@microsoft/applicationinsights-web 2.8.0-beta.2203-03 → 2.8.0-beta.2203-06

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 (50) hide show
  1. package/browser/{ai.2.8.0-beta.2203-03.cjs.js → ai.2.8.0-beta.2203-06.cjs.js} +639 -356
  2. package/browser/ai.2.8.0-beta.2203-06.cjs.js.map +1 -0
  3. package/browser/ai.2.8.0-beta.2203-06.cjs.min.js +6 -0
  4. package/browser/ai.2.8.0-beta.2203-06.cjs.min.js.map +1 -0
  5. package/browser/{ai.2.8.0-beta.2203-03.gbl.js → ai.2.8.0-beta.2203-06.gbl.js} +639 -356
  6. package/browser/ai.2.8.0-beta.2203-06.gbl.js.map +1 -0
  7. package/browser/ai.2.8.0-beta.2203-06.gbl.min.js +6 -0
  8. package/browser/ai.2.8.0-beta.2203-06.gbl.min.js.map +1 -0
  9. package/browser/ai.2.8.0-beta.2203-06.integrity.json +66 -0
  10. package/browser/{ai.2.8.0-beta.2203-03.js → ai.2.8.0-beta.2203-06.js} +639 -356
  11. package/browser/ai.2.8.0-beta.2203-06.js.map +1 -0
  12. package/browser/ai.2.8.0-beta.2203-06.min.js +6 -0
  13. package/browser/ai.2.8.0-beta.2203-06.min.js.map +1 -0
  14. package/browser/ai.2.cjs.js +638 -355
  15. package/browser/ai.2.cjs.js.map +1 -1
  16. package/browser/ai.2.cjs.min.js +2 -2
  17. package/browser/ai.2.cjs.min.js.map +1 -1
  18. package/browser/ai.2.gbl.js +638 -355
  19. package/browser/ai.2.gbl.js.map +1 -1
  20. package/browser/ai.2.gbl.min.js +2 -2
  21. package/browser/ai.2.gbl.min.js.map +1 -1
  22. package/browser/ai.2.js +638 -355
  23. package/browser/ai.2.js.map +1 -1
  24. package/browser/ai.2.min.js +2 -2
  25. package/browser/ai.2.min.js.map +1 -1
  26. package/dist/applicationinsights-web.api.json +227 -164
  27. package/dist/applicationinsights-web.api.md +14 -20
  28. package/dist/applicationinsights-web.d.ts +108 -106
  29. package/dist/applicationinsights-web.js +639 -356
  30. package/dist/applicationinsights-web.js.map +1 -1
  31. package/dist/applicationinsights-web.min.js +2 -2
  32. package/dist/applicationinsights-web.min.js.map +1 -1
  33. package/dist/applicationinsights-web.rollup.d.ts +108 -106
  34. package/dist-esm/ApplicationInsightsContainer.js +1 -1
  35. package/dist-esm/ApplicationInsightsDeprecated.js +1 -1
  36. package/dist-esm/Init.js +1 -1
  37. package/dist-esm/Initialization.js +1 -1
  38. package/dist-esm/applicationinsights-web.js +1 -1
  39. package/package.json +7 -7
  40. package/types/Initialization.d.ts +1 -1
  41. package/browser/ai.2.8.0-beta.2203-03.cjs.js.map +0 -1
  42. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js +0 -6
  43. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js.map +0 -1
  44. package/browser/ai.2.8.0-beta.2203-03.gbl.js.map +0 -1
  45. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js +0 -6
  46. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js.map +0 -1
  47. package/browser/ai.2.8.0-beta.2203-03.integrity.json +0 -66
  48. package/browser/ai.2.8.0-beta.2203-03.js.map +0 -1
  49. package/browser/ai.2.8.0-beta.2203-03.min.js +0 -6
  50. package/browser/ai.2.8.0-beta.2203-03.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-03
2
+ * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -357,6 +357,7 @@
357
357
  var strIsInitialized = "isInitialized";
358
358
  var strTeardown = "teardown";
359
359
  var strCore = "core";
360
+ var strUpdate = "update";
360
361
  var strDisabled = "disabled";
361
362
  var strDoTeardown = "_doTeardown";
362
363
  var strProcessNext = "processNext";
@@ -825,7 +826,7 @@
825
826
  }
826
827
  return theObject;
827
828
  }
828
- function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
829
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
829
830
  var theArgs = arguments;
830
831
  var extended = theArgs[0] || {};
831
832
  var argLen = theArgs.length;
@@ -1272,6 +1273,10 @@
1272
1273
  }
1273
1274
  return DiagnosticLogger;
1274
1275
  }());
1276
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1277
+ if (isUserAct === void 0) { isUserAct = false; }
1278
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1279
+ }
1275
1280
 
1276
1281
  var strExecutionContextKey = "ctx";
1277
1282
  var _defaultPerfManager = null;
@@ -1696,7 +1701,7 @@
1696
1701
  completeDetails.func.call(completeDetails.self, completeDetails.args);
1697
1702
  }
1698
1703
  catch (e) {
1699
- core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1704
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1700
1705
  }
1701
1706
  });
1702
1707
  _onComplete = [];
@@ -1795,6 +1800,27 @@
1795
1800
  context.createNew = _createNew;
1796
1801
  return context;
1797
1802
  }
1803
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1804
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1805
+ var context = internalContext.ctx;
1806
+ function _processNext(updateState) {
1807
+ return context.iterate(function (plugin) {
1808
+ if (isFunction(plugin[strUpdate])) {
1809
+ plugin[strUpdate](context, updateState);
1810
+ }
1811
+ });
1812
+ }
1813
+ function _createNew(plugins, startAt) {
1814
+ if (plugins === void 0) { plugins = null; }
1815
+ if (isArray(plugins)) {
1816
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1817
+ }
1818
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1819
+ }
1820
+ context.processNext = _processNext;
1821
+ context.createNew = _createNew;
1822
+ return context;
1823
+ }
1798
1824
  function createTelemetryProxyChain(plugins, config, core, startAt) {
1799
1825
  var firstProxy = null;
1800
1826
  var add = startAt ? false : true;
@@ -1841,6 +1867,7 @@
1841
1867
  },
1842
1868
  processTelemetry: _processTelemetry,
1843
1869
  unload: _unloadPlugin,
1870
+ update: _updatePlugin,
1844
1871
  _id: chainId,
1845
1872
  _setNext: function (nextPlugin) {
1846
1873
  nextProxy = nextPlugin;
@@ -1880,7 +1907,7 @@
1880
1907
  hasRun = true;
1881
1908
  }
1882
1909
  if (!nextProxy || !hasNextRun) {
1883
- itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1910
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1884
1911
  }
1885
1912
  }
1886
1913
  }, details, isAsync);
@@ -1928,6 +1955,24 @@
1928
1955
  unloadCtx.processNext(unloadState);
1929
1956
  }
1930
1957
  }
1958
+ function _updatePlugin(updateCtx, updateState) {
1959
+ function _callUpdate() {
1960
+ var hasRun = false;
1961
+ if (plugin) {
1962
+ var pluginState = _getPluginState(plugin);
1963
+ var pluginCore = plugin[strCore] || pluginState.core;
1964
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1965
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1966
+ hasRun = true;
1967
+ }
1968
+ }
1969
+ }
1970
+ return hasRun;
1971
+ }
1972
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1973
+ updateCtx.processNext(updateState);
1974
+ }
1975
+ }
1931
1976
  return objFreeze(proxyChain);
1932
1977
  }
1933
1978
 
@@ -2097,7 +2142,7 @@
2097
2142
  _supportsCookies = doc[strCookie] !== undefined;
2098
2143
  }
2099
2144
  catch (e) {
2100
- logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2145
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2101
2146
  }
2102
2147
  }
2103
2148
  return _supportsCookies;
@@ -2226,6 +2271,17 @@
2226
2271
  }
2227
2272
  _runChainOnComplete();
2228
2273
  }
2274
+ function _doUpdate(updateCtx, updateState) {
2275
+ var theUpdateState = updateState || {
2276
+ reason: 0
2277
+ };
2278
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2279
+ chainCtx[strProcessNext](theUpdateState);
2280
+ }, function () {
2281
+ updateCtx[strProcessNext](theUpdateState);
2282
+ });
2283
+ return true;
2284
+ }
2229
2285
  function _doTeardown(unloadCtx, unloadState) {
2230
2286
  var theUnloadState = unloadState || {
2231
2287
  reason: 0 ,
@@ -2277,7 +2333,8 @@
2277
2333
  }, function () {
2278
2334
  itemCtx[strProcessNext](item);
2279
2335
  });
2280
- }
2336
+ },
2337
+ update: _doUpdate
2281
2338
  },
2282
2339
  _a[strPause] = function () {
2283
2340
  _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
@@ -2375,7 +2432,7 @@
2375
2432
  handler(unloadCtx, unloadState);
2376
2433
  }
2377
2434
  catch (e) {
2378
- unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2435
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2379
2436
  }
2380
2437
  });
2381
2438
  handlers = [];
@@ -2434,6 +2491,30 @@
2434
2491
  }
2435
2492
  return result;
2436
2493
  };
2494
+ _self.update = function (updateCtx, updateState) {
2495
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
2496
+ return;
2497
+ }
2498
+ var result;
2499
+ var updateDone = false;
2500
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2501
+ var theUpdateState = updateState || {
2502
+ reason: 0
2503
+ };
2504
+ function _updateCallback() {
2505
+ if (!updateDone) {
2506
+ updateDone = true;
2507
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2508
+ }
2509
+ }
2510
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2511
+ _updateCallback();
2512
+ }
2513
+ else {
2514
+ result = true;
2515
+ }
2516
+ return result;
2517
+ };
2437
2518
  _self._addHook = function (hooks) {
2438
2519
  if (hooks) {
2439
2520
  if (isArray(hooks)) {
@@ -2548,7 +2629,7 @@
2548
2629
  }
2549
2630
  }
2550
2631
  catch (e) {
2551
- itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2632
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2552
2633
  }
2553
2634
  }
2554
2635
  }
@@ -2669,7 +2750,7 @@
2669
2750
  _configExtensions = [];
2670
2751
  _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2671
2752
  _channelConfig = (config || {}).channels;
2672
- _initPluginChain(config);
2753
+ _initPluginChain(config, null);
2673
2754
  if (_self.getTransmissionControls().length === 0) {
2674
2755
  throwError("No channels available");
2675
2756
  }
@@ -2812,22 +2893,28 @@
2812
2893
  _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2813
2894
  return;
2814
2895
  }
2896
+ var updateState = {
2897
+ reason: 16
2898
+ };
2815
2899
  function _addPlugin(removed) {
2816
2900
  _configExtensions.push(plugin);
2817
- _initPluginChain(_self.config);
2901
+ updateState.added = [plugin];
2902
+ _initPluginChain(_self.config, updateState);
2818
2903
  addCb && addCb(true);
2819
2904
  }
2820
2905
  if (existingPlugin) {
2821
- var removedPlugins = [existingPlugin.plugin];
2906
+ var removedPlugins_1 = [existingPlugin.plugin];
2822
2907
  var unloadState = {
2823
2908
  reason: 2 ,
2824
2909
  isAsync: isAsync
2825
2910
  };
2826
- _removePlugins(removedPlugins, unloadState, function (removed) {
2911
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2827
2912
  if (!removed) {
2828
2913
  addCb && addCb(false);
2829
2914
  }
2830
2915
  else {
2916
+ updateState.removed = removedPlugins_1;
2917
+ updateState.reason |= 32 ;
2831
2918
  _addPlugin();
2832
2919
  }
2833
2920
  });
@@ -2865,7 +2952,7 @@
2865
2952
  function _createTelCtx() {
2866
2953
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2867
2954
  }
2868
- function _initPluginChain(config) {
2955
+ function _initPluginChain(config, updateState) {
2869
2956
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2870
2957
  _coreExtensions = theExtensions.core;
2871
2958
  _pluginChain = null;
@@ -2891,6 +2978,9 @@
2891
2978
  _channelControl.initialize(config, _self, allExtensions);
2892
2979
  initializePlugins(_createTelCtx(), allExtensions);
2893
2980
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2981
+ if (updateState) {
2982
+ _doUpdate(updateState);
2983
+ }
2894
2984
  }
2895
2985
  function _getPlugin(pluginIdentifier) {
2896
2986
  var theExt = null;
@@ -2923,7 +3013,10 @@
2923
3013
  };
2924
3014
  _removePlugins(pluginsToRemove, unloadState, function (removed) {
2925
3015
  if (removed) {
2926
- _initPluginChain(_self.config);
3016
+ _initPluginChain(_self.config, {
3017
+ reason: 32 ,
3018
+ removed: pluginsToRemove
3019
+ });
2927
3020
  }
2928
3021
  removeCb && removeCb(removed);
2929
3022
  });
@@ -3020,10 +3113,16 @@
3020
3113
  var extConfig = getSetValue(config, strExtensionConfig);
3021
3114
  extConfig.NotificationManager = _notificationManager;
3022
3115
  }
3116
+ function _doUpdate(updateState) {
3117
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
3118
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3119
+ updateCtx.processNext(updateState);
3120
+ }
3121
+ }
3023
3122
  function _logOrThrowError(message) {
3024
3123
  var logger = _self.logger;
3025
3124
  if (logger) {
3026
- logger.throwInternal(2 , 73 , message);
3125
+ _throwInternal(logger, 2 , 73 , message);
3027
3126
  }
3028
3127
  else {
3029
3128
  throwError(message);
@@ -3138,6 +3237,8 @@
3138
3237
  var strOnPrefix = "on";
3139
3238
  var strAttachEvent = "attachEvent";
3140
3239
  var strAddEventHelper = "addEventListener";
3240
+ var strDetachEvent = "detachEvent";
3241
+ var strRemoveEventListener = "removeEventListener";
3141
3242
  var strEvents = "events";
3142
3243
  var strVisibilityChangeEvt = "visibilitychange";
3143
3244
  var strPageHide = "pagehide";
@@ -3154,12 +3255,12 @@
3154
3255
  }
3155
3256
  return name;
3156
3257
  }
3157
- function _getEvtNamespace(eventName, namespaces) {
3158
- if (namespaces) {
3258
+ function _getEvtNamespace(eventName, evtNamespace) {
3259
+ if (evtNamespace) {
3159
3260
  var theNamespace_1 = "";
3160
- if (isArray(namespaces)) {
3261
+ if (isArray(evtNamespace)) {
3161
3262
  theNamespace_1 = "";
3162
- arrForEach(namespaces, function (name) {
3263
+ arrForEach(evtNamespace, function (name) {
3163
3264
  name = _normalizeNamespace(name);
3164
3265
  if (name) {
3165
3266
  if (name[0] !== ".") {
@@ -3170,7 +3271,7 @@
3170
3271
  });
3171
3272
  }
3172
3273
  else {
3173
- theNamespace_1 = _normalizeNamespace(namespaces);
3274
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
3174
3275
  }
3175
3276
  if (theNamespace_1) {
3176
3277
  if (theNamespace_1[0] !== ".") {
@@ -3194,6 +3295,16 @@
3194
3295
  }
3195
3296
  return registeredEvents;
3196
3297
  }
3298
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3299
+ if (obj && evtName && evtName.type) {
3300
+ if (obj[strRemoveEventListener]) {
3301
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3302
+ }
3303
+ else if (obj[strDetachEvent]) {
3304
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3305
+ }
3306
+ }
3307
+ }
3197
3308
  function _doAttach(obj, evtName, handlerRef, useCapture) {
3198
3309
  var result = false;
3199
3310
  if (obj && evtName && evtName.type && handlerRef) {
@@ -3208,6 +3319,34 @@
3208
3319
  }
3209
3320
  return result;
3210
3321
  }
3322
+ function _doUnregister(target, events, evtName, unRegFn) {
3323
+ var idx = events.length;
3324
+ while (idx--) {
3325
+ var theEvent = events[idx];
3326
+ if (theEvent) {
3327
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3328
+ if (!unRegFn || unRegFn(theEvent)) {
3329
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3330
+ events.splice(idx, 1);
3331
+ }
3332
+ }
3333
+ }
3334
+ }
3335
+ }
3336
+ function _unregisterEvents(target, evtName, unRegFn) {
3337
+ if (evtName.type) {
3338
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3339
+ }
3340
+ else {
3341
+ var eventCache = elmNodeData.get(target, strEvents, {});
3342
+ objForEachKey(eventCache, function (evtType, events) {
3343
+ _doUnregister(target, events, evtName, unRegFn);
3344
+ });
3345
+ if (objKeys(eventCache).length === 0) {
3346
+ elmNodeData.kill(target, strEvents);
3347
+ }
3348
+ }
3349
+ }
3211
3350
  function mergeEvtNamespace(theNamespace, namespaces) {
3212
3351
  var newNamespaces;
3213
3352
  if (namespaces) {
@@ -3245,6 +3384,27 @@
3245
3384
  }
3246
3385
  return result;
3247
3386
  }
3387
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3388
+ if (useCapture === void 0) { useCapture = false; }
3389
+ if (target) {
3390
+ try {
3391
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3392
+ var found_1 = false;
3393
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3394
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3395
+ found_1 = true;
3396
+ return true;
3397
+ }
3398
+ return false;
3399
+ });
3400
+ if (!found_1) {
3401
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3402
+ }
3403
+ }
3404
+ catch (e) {
3405
+ }
3406
+ }
3407
+ }
3248
3408
  function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3249
3409
  if (useCapture === void 0) { useCapture = false; }
3250
3410
  return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
@@ -3685,7 +3845,7 @@
3685
3845
  name = strTrim(name.toString());
3686
3846
  if (name.length > 150 ) {
3687
3847
  nameTrunc = name.substring(0, 150 );
3688
- logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3848
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3689
3849
  }
3690
3850
  }
3691
3851
  return nameTrunc || name;
@@ -3698,7 +3858,7 @@
3698
3858
  value = strTrim(value);
3699
3859
  if (value.toString().length > maxLength) {
3700
3860
  valueTrunc = value.toString().substring(0, maxLength);
3701
- logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3861
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3702
3862
  }
3703
3863
  }
3704
3864
  return valueTrunc || value;
@@ -3711,7 +3871,7 @@
3711
3871
  if (message) {
3712
3872
  if (message.length > 32768 ) {
3713
3873
  messageTrunc = message.substring(0, 32768 );
3714
- logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3874
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3715
3875
  }
3716
3876
  }
3717
3877
  return messageTrunc || message;
@@ -3722,7 +3882,7 @@
3722
3882
  var value = "" + exception;
3723
3883
  if (value.length > 32768 ) {
3724
3884
  exceptionTrunc = value.substring(0, 32768 );
3725
- logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3885
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3726
3886
  }
3727
3887
  }
3728
3888
  return exceptionTrunc || exception;
@@ -3736,7 +3896,7 @@
3736
3896
  value = getJSON().stringify(value);
3737
3897
  }
3738
3898
  catch (e) {
3739
- logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3899
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3740
3900
  }
3741
3901
  }
3742
3902
  value = dataSanitizeString(logger, value, 8192 );
@@ -3767,7 +3927,7 @@
3767
3927
  input = strTrim(input);
3768
3928
  if (input.length > maxLength) {
3769
3929
  inputTrunc = input.substring(0, maxLength);
3770
- logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3930
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3771
3931
  }
3772
3932
  }
3773
3933
  return inputTrunc || input;
@@ -3905,8 +4065,12 @@
3905
4065
  _canUseLocalStorage = false;
3906
4066
  _canUseSessionStorage = false;
3907
4067
  }
3908
- function utlCanUseLocalStorage() {
3909
- if (_canUseLocalStorage === undefined) {
4068
+ function utlEnableStorage() {
4069
+ _canUseLocalStorage = utlCanUseLocalStorage(true);
4070
+ _canUseSessionStorage = utlCanUseSessionStorage(true);
4071
+ }
4072
+ function utlCanUseLocalStorage(reset) {
4073
+ if (reset || _canUseLocalStorage === undefined) {
3910
4074
  _canUseLocalStorage = !!_getVerifiedStorageObject(StorageType.LocalStorage);
3911
4075
  }
3912
4076
  return _canUseLocalStorage;
@@ -3919,7 +4083,7 @@
3919
4083
  }
3920
4084
  catch (e) {
3921
4085
  _canUseLocalStorage = false;
3922
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4086
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3923
4087
  }
3924
4088
  }
3925
4089
  return null;
@@ -3933,7 +4097,7 @@
3933
4097
  }
3934
4098
  catch (e) {
3935
4099
  _canUseLocalStorage = false;
3936
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4100
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3937
4101
  }
3938
4102
  }
3939
4103
  return false;
@@ -3947,13 +4111,13 @@
3947
4111
  }
3948
4112
  catch (e) {
3949
4113
  _canUseLocalStorage = false;
3950
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4114
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3951
4115
  }
3952
4116
  }
3953
4117
  return false;
3954
4118
  }
3955
- function utlCanUseSessionStorage() {
3956
- if (_canUseSessionStorage === undefined) {
4119
+ function utlCanUseSessionStorage(reset) {
4120
+ if (reset || _canUseSessionStorage === undefined) {
3957
4121
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
3958
4122
  }
3959
4123
  return _canUseSessionStorage;
@@ -3975,7 +4139,7 @@
3975
4139
  }
3976
4140
  catch (e) {
3977
4141
  _canUseSessionStorage = false;
3978
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4142
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3979
4143
  }
3980
4144
  }
3981
4145
  return null;
@@ -3989,7 +4153,7 @@
3989
4153
  }
3990
4154
  catch (e) {
3991
4155
  _canUseSessionStorage = false;
3992
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4156
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3993
4157
  }
3994
4158
  }
3995
4159
  return false;
@@ -4003,7 +4167,7 @@
4003
4167
  }
4004
4168
  catch (e) {
4005
4169
  _canUseSessionStorage = false;
4006
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4170
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4007
4171
  }
4008
4172
  }
4009
4173
  return false;
@@ -5580,6 +5744,33 @@
5580
5744
  return PageViewPerformanceManager;
5581
5745
  }());
5582
5746
 
5747
+ var Timing = /** @class */ (function () {
5748
+ function Timing(logger, name) {
5749
+ var _self = this;
5750
+ var _events = {};
5751
+ _self.start = function (name) {
5752
+ if (typeof _events[name] !== "undefined") {
5753
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
5754
+ }
5755
+ _events[name] = +new Date;
5756
+ };
5757
+ _self.stop = function (name, url, properties, measurements) {
5758
+ var start = _events[name];
5759
+ if (isNaN(start)) {
5760
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
5761
+ }
5762
+ else {
5763
+ var end = +new Date;
5764
+ var duration = dateTimeUtilsDuration(start, end);
5765
+ _self.action(name, url, duration, properties, measurements);
5766
+ }
5767
+ delete _events[name];
5768
+ _events[name] = undefined;
5769
+ };
5770
+ }
5771
+ return Timing;
5772
+ }());
5773
+
5583
5774
  var durationProperty = "duration";
5584
5775
  var strEvent = "event";
5585
5776
  function _dispatchEvent(target, evnt) {
@@ -5597,47 +5788,78 @@
5597
5788
  }
5598
5789
  return error || "";
5599
5790
  }
5600
- var ApplicationInsights = /** @class */ (function (_super) {
5601
- __extendsFn(ApplicationInsights, _super);
5602
- function ApplicationInsights() {
5791
+ var MinMilliSeconds = 60000;
5792
+ function _configMilliseconds(value, defValue) {
5793
+ value = value || defValue;
5794
+ if (value < MinMilliSeconds) {
5795
+ value = MinMilliSeconds;
5796
+ }
5797
+ return value;
5798
+ }
5799
+ function _getDefaultConfig(config) {
5800
+ if (!config) {
5801
+ config = {};
5802
+ }
5803
+ config.sessionRenewalMs = _configMilliseconds(config.sessionRenewalMs, 30 * 60 * 1000);
5804
+ config.sessionExpirationMs = _configMilliseconds(config.sessionExpirationMs, 24 * 60 * 60 * 1000);
5805
+ config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
5806
+ config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
5807
+ config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
5808
+ config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
5809
+ if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
5810
+ config.samplingPercentage = 100;
5811
+ }
5812
+ config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
5813
+ config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
5814
+ config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
5815
+ config.namePrefix = config.namePrefix || "";
5816
+ config.enableDebug = stringToBoolOrDefault(config.enableDebug);
5817
+ config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
5818
+ config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
5819
+ return config;
5820
+ }
5821
+ function _updateStorageUsage(extConfig) {
5822
+ if (!isUndefined(extConfig.isStorageUseDisabled)) {
5823
+ if (extConfig.isStorageUseDisabled) {
5824
+ utlDisableStorage();
5825
+ }
5826
+ else {
5827
+ utlEnableStorage();
5828
+ }
5829
+ }
5830
+ }
5831
+ var AnalyticsPlugin = /** @class */ (function (_super) {
5832
+ __extendsFn(AnalyticsPlugin, _super);
5833
+ function AnalyticsPlugin() {
5603
5834
  var _this = _super.call(this) || this;
5604
5835
  _this.identifier = AnalyticsPluginIdentifier;
5605
5836
  _this.priority = 180;
5606
5837
  _this.autoRoutePVDelay = 500;
5607
5838
  var _eventTracking;
5608
5839
  var _pageTracking;
5609
- var _properties;
5840
+ var _pageViewManager;
5841
+ var _pageViewPerformanceManager;
5842
+ var _pageVisitTimeManager;
5843
+ var _preInitTelemetryInitializers;
5844
+ var _isBrowserLinkTrackingEnabled;
5845
+ var _browserLinkInitializerAdded;
5846
+ var _enableAutoRouteTracking;
5847
+ var _historyListenerAdded;
5848
+ var _disableExceptionTracking;
5849
+ var _autoExceptionInstrumented;
5850
+ var _enableUnhandledPromiseRejectionTracking;
5851
+ var _autoUnhandledPromiseInstrumented;
5610
5852
  var _prevUri;
5611
5853
  var _currUri;
5612
- dynamicProto(ApplicationInsights, _this, function (_self, _base) {
5613
- var location = getLocation(true);
5614
- _prevUri = location && location.href || "";
5854
+ var _evtNamespace;
5855
+ dynamicProto(AnalyticsPlugin, _this, function (_self, _base) {
5856
+ var _addHook = _base._addHook;
5857
+ _initDefaults();
5615
5858
  _self.getCookieMgr = function () {
5616
5859
  return safeGetCookieMgr(_self.core);
5617
5860
  };
5618
5861
  _self.processTelemetry = function (env, itemCtx) {
5619
- doPerf(_self.core, function () { return _self.identifier + ":processTelemetry"; }, function () {
5620
- var doNotSendItem = false;
5621
- var telemetryInitializersCount = _self._telemetryInitializers.length;
5622
- itemCtx = _self._getTelCtx(itemCtx);
5623
- for (var i = 0; i < telemetryInitializersCount; ++i) {
5624
- var telemetryInitializer = _self._telemetryInitializers[i];
5625
- if (telemetryInitializer) {
5626
- try {
5627
- if (telemetryInitializer.apply(null, [env]) === false) {
5628
- doNotSendItem = true;
5629
- break;
5630
- }
5631
- }
5632
- catch (e) {
5633
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5634
- }
5635
- }
5636
- }
5637
- if (!doNotSendItem) {
5638
- _self.processNext(env, itemCtx);
5639
- }
5640
- }, function () { return ({ item: env }); }, !(env.sync));
5862
+ _self.processNext(env, itemCtx);
5641
5863
  };
5642
5864
  _self.trackEvent = function (event, customProperties) {
5643
5865
  try {
@@ -5645,7 +5867,7 @@
5645
5867
  _self.core.track(telemetryItem);
5646
5868
  }
5647
5869
  catch (e) {
5648
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5870
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5649
5871
  }
5650
5872
  };
5651
5873
  _self.startTrackEvent = function (name) {
@@ -5653,7 +5875,7 @@
5653
5875
  _eventTracking.start(name);
5654
5876
  }
5655
5877
  catch (e) {
5656
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5878
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5657
5879
  }
5658
5880
  };
5659
5881
  _self.stopTrackEvent = function (name, properties, measurements) {
@@ -5661,7 +5883,7 @@
5661
5883
  _eventTracking.stop(name, undefined, properties);
5662
5884
  }
5663
5885
  catch (e) {
5664
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5886
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5665
5887
  }
5666
5888
  };
5667
5889
  _self.trackTrace = function (trace, customProperties) {
@@ -5670,7 +5892,7 @@
5670
5892
  _self.core.track(telemetryItem);
5671
5893
  }
5672
5894
  catch (e) {
5673
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5895
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5674
5896
  }
5675
5897
  };
5676
5898
  _self.trackMetric = function (metric, customProperties) {
@@ -5679,19 +5901,19 @@
5679
5901
  _self.core.track(telemetryItem);
5680
5902
  }
5681
5903
  catch (e) {
5682
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5904
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5683
5905
  }
5684
5906
  };
5685
5907
  _self.trackPageView = function (pageView, customProperties) {
5686
5908
  try {
5687
5909
  var inPv = pageView || {};
5688
- _self._pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
5910
+ _pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
5689
5911
  if (_self.config.autoTrackPageVisitTime) {
5690
- _self._pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
5912
+ _pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
5691
5913
  }
5692
5914
  }
5693
5915
  catch (e) {
5694
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5916
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5695
5917
  }
5696
5918
  };
5697
5919
  _self.sendPageViewInternal = function (pageView, properties, systemProperties) {
@@ -5707,12 +5929,13 @@
5707
5929
  _self.core.track(telemetryItem);
5708
5930
  };
5709
5931
  _self.trackPageViewPerformance = function (pageViewPerformance, customProperties) {
5932
+ var inPvp = pageViewPerformance || {};
5710
5933
  try {
5711
- _self._pageViewPerformanceManager.populatePageViewPerformanceEvent(pageViewPerformance);
5712
- _self.sendPageViewPerformanceInternal(pageViewPerformance, customProperties);
5934
+ _pageViewPerformanceManager.populatePageViewPerformanceEvent(inPvp);
5935
+ _self.sendPageViewPerformanceInternal(inPvp, customProperties);
5713
5936
  }
5714
5937
  catch (e) {
5715
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5938
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5716
5939
  }
5717
5940
  };
5718
5941
  _self.startTrackPage = function (name) {
@@ -5724,7 +5947,7 @@
5724
5947
  _pageTracking.start(name);
5725
5948
  }
5726
5949
  catch (e) {
5727
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5950
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5728
5951
  }
5729
5952
  };
5730
5953
  _self.stopTrackPage = function (name, url, properties, measurement) {
@@ -5739,11 +5962,11 @@
5739
5962
  }
5740
5963
  _pageTracking.stop(name, url, properties, measurement);
5741
5964
  if (_self.config.autoTrackPageVisitTime) {
5742
- _self._pageVisitTimeManager.trackPreviousPageVisit(name, url);
5965
+ _pageVisitTimeManager.trackPreviousPageVisit(name, url);
5743
5966
  }
5744
5967
  }
5745
5968
  catch (e) {
5746
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5969
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5747
5970
  }
5748
5971
  };
5749
5972
  _self.sendExceptionInternal = function (exception, customProperties, systemProperties) {
@@ -5753,11 +5976,14 @@
5753
5976
  _self.core.track(telemetryItem);
5754
5977
  };
5755
5978
  _self.trackException = function (exception, customProperties) {
5979
+ if (exception && !exception.exception && exception.error) {
5980
+ exception.exception = exception.error;
5981
+ }
5756
5982
  try {
5757
5983
  _self.sendExceptionInternal(exception, customProperties);
5758
5984
  }
5759
5985
  catch (e) {
5760
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5986
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5761
5987
  }
5762
5988
  };
5763
5989
  _self._onerror = function (exception) {
@@ -5791,158 +6017,97 @@
5791
6017
  }
5792
6018
  catch (e) {
5793
6019
  var errorString = error ? (error.name + ", " + error.message) : "null";
5794
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
6020
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
5795
6021
  + getExceptionName(e), { exception: dumpObj(e), errorString: errorString });
5796
6022
  }
5797
6023
  };
5798
6024
  _self.addTelemetryInitializer = function (telemetryInitializer) {
5799
- _self._telemetryInitializers.push(telemetryInitializer);
6025
+ if (_self.core) {
6026
+ return _self.core.addTelemetryInitializer(telemetryInitializer);
6027
+ }
6028
+ if (!_preInitTelemetryInitializers) {
6029
+ _preInitTelemetryInitializers = [];
6030
+ }
6031
+ _preInitTelemetryInitializers.push(telemetryInitializer);
5800
6032
  };
5801
6033
  _self.initialize = function (config, core, extensions, pluginChain) {
5802
6034
  if (_self.isInitialized()) {
5803
6035
  return;
5804
6036
  }
5805
6037
  if (isNullOrUndefined(core)) {
5806
- throw Error("Error initializing");
6038
+ throwError("Error initializing");
5807
6039
  }
5808
6040
  _base.initialize(config, core, extensions, pluginChain);
5809
- _self.setInitialized(false);
5810
- var ctx = _self._getTelCtx();
5811
- var identifier = _self.identifier;
5812
- _self.config = ctx.getExtCfg(identifier);
5813
- var defaults = ApplicationInsights.getDefaultConfig(config);
5814
- if (defaults !== undefined) {
5815
- objForEachKey(defaults, function (field, value) {
5816
- _self.config[field] = ctx.getConfig(identifier, field, value);
5817
- if (_self.config[field] === undefined) {
5818
- _self.config[field] = value;
5819
- }
5820
- });
5821
- }
5822
- if (_self.config.isStorageUseDisabled) {
5823
- utlDisableStorage();
5824
- }
5825
- var configGetters = {
5826
- instrumentationKey: function () { return config.instrumentationKey; },
5827
- accountId: function () { return _self.config.accountId || config.accountId; },
5828
- sessionRenewalMs: function () { return _self.config.sessionRenewalMs || config.sessionRenewalMs; },
5829
- sessionExpirationMs: function () { return _self.config.sessionExpirationMs || config.sessionExpirationMs; },
5830
- sampleRate: function () { return _self.config.samplingPercentage || config.samplingPercentage; },
5831
- sdkExtension: function () { return _self.config.sdkExtension || config.sdkExtension; },
5832
- isBrowserLinkTrackingEnabled: function () { return _self.config.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled; },
5833
- appId: function () { return _self.config.appId || config.appId; }
5834
- };
5835
- _self._pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
5836
- _self._pageViewManager = new PageViewManager(_this, _self.config.overridePageViewDuration, _self.core, _self._pageViewPerformanceManager);
5837
- _self._pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
5838
- _self._telemetryInitializers = _self._telemetryInitializers || [];
5839
- _addDefaultTelemetryInitializers(configGetters);
5840
- _eventTracking = new Timing(_self.diagLog(), "trackEvent");
5841
- _eventTracking.action =
5842
- function (name, url, duration, properties) {
5843
- if (!properties) {
6041
+ try {
6042
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("AnalyticsPlugin"), core.evtNamespace && core.evtNamespace());
6043
+ if (_preInitTelemetryInitializers) {
6044
+ arrForEach(_preInitTelemetryInitializers, function (initializer) {
6045
+ core.addTelemetryInitializer(initializer);
6046
+ });
6047
+ _preInitTelemetryInitializers = null;
6048
+ }
6049
+ var extConfig = _populateDefaults(config);
6050
+ _updateStorageUsage(extConfig);
6051
+ _pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
6052
+ _pageViewManager = new PageViewManager(_this, extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
6053
+ _pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
6054
+ _updateBrowserLinkTracking(extConfig, config);
6055
+ _eventTracking = new Timing(_self.diagLog(), "trackEvent");
6056
+ _eventTracking.action =
6057
+ function (name, url, duration, properties) {
6058
+ if (!properties) {
6059
+ properties = {};
6060
+ }
6061
+ properties[durationProperty] = duration.toString();
6062
+ _self.trackEvent({ name: name, properties: properties });
6063
+ };
6064
+ _pageTracking = new Timing(_self.diagLog(), "trackPageView");
6065
+ _pageTracking.action = function (name, url, duration, properties, measurements) {
6066
+ if (isNullOrUndefined(properties)) {
5844
6067
  properties = {};
5845
6068
  }
5846
6069
  properties[durationProperty] = duration.toString();
5847
- _self.trackEvent({ name: name, properties: properties });
5848
- };
5849
- _pageTracking = new Timing(_self.diagLog(), "trackPageView");
5850
- _pageTracking.action = function (name, url, duration, properties, measurements) {
5851
- if (isNullOrUndefined(properties)) {
5852
- properties = {};
5853
- }
5854
- properties[durationProperty] = duration.toString();
5855
- var pageViewItem = {
5856
- name: name,
5857
- uri: url,
5858
- properties: properties,
5859
- measurements: measurements
5860
- };
5861
- _self.sendPageViewInternal(pageViewItem, properties);
5862
- };
5863
- var _window = getWindow();
5864
- var _history = getHistory();
5865
- var _location = getLocation(true);
5866
- var instance = _this;
5867
- if (_self.config.disableExceptionTracking === false &&
5868
- !_self.config.autoExceptionInstrumented && _window) {
5869
- var onerror_1 = "onerror";
5870
- var originalOnError_1 = _window[onerror_1];
5871
- _window.onerror = function (message, url, lineNumber, columnNumber, error) {
5872
- var evt = _window[strEvent];
5873
- var handled = originalOnError_1 && originalOnError_1(message, url, lineNumber, columnNumber, error);
5874
- if (handled !== true) {
5875
- instance._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, evt));
5876
- }
5877
- return handled;
5878
- };
5879
- _self.config.autoExceptionInstrumented = true;
5880
- }
5881
- if (_self.config.disableExceptionTracking === false &&
5882
- _self.config.enableUnhandledPromiseRejectionTracking === true &&
5883
- !_self.config.autoUnhandledPromiseInstrumented && _window) {
5884
- var onunhandledrejection_1 = "onunhandledrejection";
5885
- var originalOnUnhandledRejection_1 = _window[onunhandledrejection_1];
5886
- _window[onunhandledrejection_1] = function (error) {
5887
- var evt = _window[strEvent];
5888
- var handled = originalOnUnhandledRejection_1 && originalOnUnhandledRejection_1.call(_window, error);
5889
- if (handled !== true) {
5890
- instance._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, evt));
5891
- }
5892
- return handled;
6070
+ var pageViewItem = {
6071
+ name: name,
6072
+ uri: url,
6073
+ properties: properties,
6074
+ measurements: measurements
6075
+ };
6076
+ _self.sendPageViewInternal(pageViewItem, properties);
5893
6077
  };
5894
- _self.config.autoUnhandledPromiseInstrumented = true;
5895
- }
5896
- if (_self.config.enableAutoRouteTracking === true
5897
- && _history && isFunction(_history.pushState) && isFunction(_history.replaceState)
5898
- && _window
5899
- && typeof Event !== "undefined") {
5900
- var _self_1 = _this;
5901
- arrForEach(extensions, function (extension) {
5902
- if (extension.identifier === PropertiesPluginIdentifier) {
5903
- _properties = extension;
5904
- }
5905
- });
5906
- _history.pushState = (function (f) { return function pushState() {
5907
- var ret = f.apply(this, arguments);
5908
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "pushState"));
5909
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5910
- return ret;
5911
- }; })(_history.pushState);
5912
- _history.replaceState = (function (f) { return function replaceState() {
5913
- var ret = f.apply(this, arguments);
5914
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "replaceState"));
5915
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5916
- return ret;
5917
- }; })(_history.replaceState);
5918
- if (_window.addEventListener) {
5919
- _window.addEventListener(_self_1.config.namePrefix + "popstate", function () {
5920
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5921
- });
5922
- _window.addEventListener(_self_1.config.namePrefix + "locationchange", function () {
5923
- if (_properties && _properties.context && _properties.context.telemetryTrace) {
5924
- _properties.context.telemetryTrace.traceID = generateW3CId();
5925
- var traceLocationName = "_unknown_";
5926
- if (_location && _location.pathname) {
5927
- traceLocationName = _location.pathname + (_location.hash || "");
5928
- }
5929
- _properties.context.telemetryTrace.name = dataSanitizeString(_self_1.diagLog(), traceLocationName);
5930
- }
5931
- if (_currUri) {
5932
- _prevUri = _currUri;
5933
- _currUri = _location && _location.href || "";
5934
- }
5935
- else {
5936
- _currUri = _location && _location.href || "";
5937
- }
5938
- setTimeout((function (uri) {
5939
- _self_1.trackPageView({ refUri: uri, properties: { duration: 0 } });
5940
- }).bind(_this, _prevUri), _self_1.autoRoutePVDelay);
5941
- });
6078
+ if (hasWindow()) {
6079
+ _updateExceptionTracking(extConfig);
6080
+ _updateLocationChange(extConfig);
5942
6081
  }
5943
6082
  }
5944
- _self.setInitialized(true);
6083
+ catch (e) {
6084
+ _self.setInitialized(false);
6085
+ throw e;
6086
+ }
6087
+ };
6088
+ _self._doTeardown = function (unloadCtx, unloadState) {
6089
+ eventOff(window, null, null, _evtNamespace);
6090
+ _initDefaults();
5945
6091
  };
6092
+ function _populateDefaults(config) {
6093
+ var ctx = createProcessTelemetryContext(null, config, _self.core);
6094
+ var identifier = _self.identifier;
6095
+ var defaults = _getDefaultConfig(config);
6096
+ var extConfig = _self.config = ctx.getExtCfg(identifier);
6097
+ if (defaults !== undefined) {
6098
+ objForEachKey(defaults, function (field, value) {
6099
+ extConfig[field] = ctx.getConfig(identifier, field, value);
6100
+ if (extConfig[field] === undefined) {
6101
+ extConfig = value;
6102
+ }
6103
+ });
6104
+ }
6105
+ return extConfig;
6106
+ }
6107
+ function _updateBrowserLinkTracking(extConfig, config) {
6108
+ _isBrowserLinkTrackingEnabled = extConfig.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled;
6109
+ _addDefaultTelemetryInitializers();
6110
+ }
5946
6111
  function trackPageVisitTime(pageName, pageUrl, pageVisitTime) {
5947
6112
  var properties = { PageName: pageName, PageUrl: pageUrl };
5948
6113
  _self.trackMetric({
@@ -5953,11 +6118,11 @@
5953
6118
  sampleCount: 1
5954
6119
  }, properties);
5955
6120
  }
5956
- function _addDefaultTelemetryInitializers(configGetters) {
5957
- if (!configGetters.isBrowserLinkTrackingEnabled()) {
6121
+ function _addDefaultTelemetryInitializers() {
6122
+ if (!_browserLinkInitializerAdded && _isBrowserLinkTrackingEnabled) {
5958
6123
  var browserLinkPaths_1 = ["/browserLinkSignalR/", "/__browserLink/"];
5959
6124
  var dropBrowserLinkRequests = function (envelope) {
5960
- if (envelope.baseType === RemoteDependencyData.dataType) {
6125
+ if (_isBrowserLinkTrackingEnabled && envelope.baseType === RemoteDependencyData.dataType) {
5961
6126
  var remoteData = envelope.baseData;
5962
6127
  if (remoteData) {
5963
6128
  for (var i = 0; i < browserLinkPaths_1.length; i++) {
@@ -5969,70 +6134,147 @@
5969
6134
  }
5970
6135
  return true;
5971
6136
  };
5972
- _addTelemetryInitializer(dropBrowserLinkRequests);
6137
+ _self.addTelemetryInitializer(dropBrowserLinkRequests);
6138
+ _browserLinkInitializerAdded = true;
5973
6139
  }
5974
6140
  }
5975
- function _addTelemetryInitializer(telemetryInitializer) {
5976
- _self._telemetryInitializers.push(telemetryInitializer);
5977
- }
5978
6141
  function _sendCORSException(exception, properties) {
5979
6142
  var telemetryItem = TelemetryItemCreator.create(exception, Exception.dataType, Exception.envelopeType, _self.diagLog(), properties);
5980
6143
  _self.core.track(telemetryItem);
5981
6144
  }
5982
- });
5983
- return _this;
5984
- }
5985
- ApplicationInsights.getDefaultConfig = function (config) {
5986
- if (!config) {
5987
- config = {};
5988
- }
5989
- config.sessionRenewalMs = 30 * 60 * 1000;
5990
- config.sessionExpirationMs = 24 * 60 * 60 * 1000;
5991
- config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
5992
- config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
5993
- config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
5994
- config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
5995
- if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
5996
- config.samplingPercentage = 100;
5997
- }
5998
- config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
5999
- config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
6000
- config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
6001
- config.namePrefix = config.namePrefix || "";
6002
- config.enableDebug = stringToBoolOrDefault(config.enableDebug);
6003
- config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
6004
- config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
6005
- return config;
6006
- };
6007
- ApplicationInsights.Version = "2.8.0-beta.2203-03";
6008
- return ApplicationInsights;
6009
- }(BaseTelemetryPlugin));
6010
- var Timing = /** @class */ (function () {
6011
- function Timing(logger, name) {
6012
- var _self = this;
6013
- var _events = {};
6014
- _self.start = function (name) {
6015
- if (typeof _events[name] !== "undefined") {
6016
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
6145
+ function _updateExceptionTracking(extConfig) {
6146
+ var _window = getWindow();
6147
+ var locn = getLocation(true);
6148
+ _disableExceptionTracking = extConfig.disableExceptionTracking;
6149
+ if (!_disableExceptionTracking && !_autoExceptionInstrumented && !extConfig.autoExceptionInstrumented) {
6150
+ _addHook(InstrumentFunc(_window, "onerror", {
6151
+ ns: _evtNamespace,
6152
+ rsp: function (callDetails, message, url, lineNumber, columnNumber, error) {
6153
+ if (!_disableExceptionTracking && callDetails.rslt !== true) {
6154
+ _self._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, callDetails.evt));
6155
+ }
6156
+ }
6157
+ }));
6158
+ _autoExceptionInstrumented = true;
6159
+ }
6160
+ _addUnhandledPromiseRejectionTracking(extConfig, _window, locn);
6017
6161
  }
6018
- _events[name] = +new Date;
6019
- };
6020
- _self.stop = function (name, url, properties, measurements) {
6021
- var start = _events[name];
6022
- if (isNaN(start)) {
6023
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
6162
+ function _updateLocationChange(extConfig) {
6163
+ var win = getWindow();
6164
+ var locn = getLocation(true);
6165
+ _enableAutoRouteTracking = extConfig.enableAutoRouteTracking === true;
6166
+ if (win && _enableAutoRouteTracking && hasHistory()) {
6167
+ var _history = getHistory();
6168
+ if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strShimUndefined) {
6169
+ _addHistoryListener(extConfig, win, _history, locn);
6170
+ }
6171
+ }
6024
6172
  }
6025
- else {
6026
- var end = +new Date;
6027
- var duration = dateTimeUtilsDuration(start, end);
6028
- _self.action(name, url, duration, properties, measurements);
6173
+ function _addHistoryListener(extConfig, win, history, locn) {
6174
+ function _popstateHandler() {
6175
+ if (_enableAutoRouteTracking) {
6176
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6177
+ }
6178
+ }
6179
+ function _locationChangeHandler() {
6180
+ if (_currUri) {
6181
+ _prevUri = _currUri;
6182
+ _currUri = locn && locn.href || "";
6183
+ }
6184
+ else {
6185
+ _currUri = locn && locn.href || "";
6186
+ }
6187
+ if (_enableAutoRouteTracking) {
6188
+ var properties = _self.core.getPlugin(PropertiesPluginIdentifier);
6189
+ if (properties) {
6190
+ var context = properties.plugin.context;
6191
+ if (context && context.telemetryTrace) {
6192
+ context.telemetryTrace.traceID = generateW3CId();
6193
+ var traceLocationName = "_unknown_";
6194
+ if (locn && locn.pathname) {
6195
+ traceLocationName = locn.pathname + (locn.hash || "");
6196
+ }
6197
+ context.telemetryTrace.name = dataSanitizeString(_self.diagLog(), traceLocationName);
6198
+ }
6199
+ }
6200
+ setTimeout((function (uri) {
6201
+ _self.trackPageView({ refUri: uri, properties: { duration: 0 } });
6202
+ }).bind(this, _prevUri), _self.autoRoutePVDelay);
6203
+ }
6204
+ }
6205
+ if (!_historyListenerAdded) {
6206
+ _addHook(InstrumentFunc(history, "pushState", {
6207
+ ns: _evtNamespace,
6208
+ rsp: function () {
6209
+ if (_enableAutoRouteTracking) {
6210
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "pushState"));
6211
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6212
+ }
6213
+ }
6214
+ }));
6215
+ _addHook(InstrumentFunc(history, "replaceState", {
6216
+ ns: _evtNamespace,
6217
+ rsp: function () {
6218
+ if (_enableAutoRouteTracking) {
6219
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "replaceState"));
6220
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6221
+ }
6222
+ }
6223
+ }));
6224
+ eventOn(win, extConfig.namePrefix + "popstate", _popstateHandler, _evtNamespace);
6225
+ eventOn(win, extConfig.namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
6226
+ _historyListenerAdded = true;
6227
+ }
6228
+ }
6229
+ function _addUnhandledPromiseRejectionTracking(extConfig, _window, _location) {
6230
+ _enableUnhandledPromiseRejectionTracking = extConfig.enableUnhandledPromiseRejectionTracking === true;
6231
+ if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
6232
+ _addHook(InstrumentFunc(_window, "onunhandledrejection", {
6233
+ ns: _evtNamespace,
6234
+ rsp: function (callDetails, error) {
6235
+ if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) {
6236
+ _self._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, callDetails.evt));
6237
+ }
6238
+ }
6239
+ }));
6240
+ _autoUnhandledPromiseInstrumented = true;
6241
+ extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented;
6242
+ }
6029
6243
  }
6030
- delete _events[name];
6031
- _events[name] = undefined;
6032
- };
6244
+ function _throwInternal(severity, msgId, msg, properties, isUserAct) {
6245
+ _self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
6246
+ }
6247
+ function _initDefaults() {
6248
+ _eventTracking = null;
6249
+ _pageTracking = null;
6250
+ _pageViewManager = null;
6251
+ _pageViewPerformanceManager = null;
6252
+ _pageVisitTimeManager = null;
6253
+ _preInitTelemetryInitializers = null;
6254
+ _isBrowserLinkTrackingEnabled = false;
6255
+ _browserLinkInitializerAdded = false;
6256
+ _enableAutoRouteTracking = false;
6257
+ _historyListenerAdded = false;
6258
+ _disableExceptionTracking = false;
6259
+ _autoExceptionInstrumented = false;
6260
+ _enableUnhandledPromiseRejectionTracking = false;
6261
+ _autoUnhandledPromiseInstrumented = false;
6262
+ var location = getLocation(true);
6263
+ _prevUri = location && location.href || "";
6264
+ _currUri = null;
6265
+ _evtNamespace = null;
6266
+ }
6267
+ objDefineAccessors(_self, "_pageViewManager", function () { return _pageViewManager; });
6268
+ objDefineAccessors(_self, "_pageViewPerformanceManager", function () { return _pageViewPerformanceManager; });
6269
+ objDefineAccessors(_self, "_pageVisitTimeManager", function () { return _pageVisitTimeManager; });
6270
+ objDefineAccessors(_self, "_evtNamespace", function () { return "." + _evtNamespace; });
6271
+ });
6272
+ return _this;
6033
6273
  }
6034
- return Timing;
6035
- }());
6274
+ AnalyticsPlugin.Version = "2.8.0-beta.2203-06";
6275
+ AnalyticsPlugin.getDefaultConfig = _getDefaultConfig;
6276
+ return AnalyticsPlugin;
6277
+ }(BaseTelemetryPlugin));
6036
6278
 
6037
6279
  var BaseSendBuffer = /** @class */ (function () {
6038
6280
  function BaseSendBuffer(logger, config) {
@@ -6311,7 +6553,7 @@
6311
6553
  }
6312
6554
  }
6313
6555
  var EnvelopeCreator = {
6314
- Version: "2.8.0-beta.2203-03"
6556
+ Version: "2.8.0-beta.2203-06"
6315
6557
  };
6316
6558
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
6317
6559
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -6606,65 +6848,81 @@
6606
6848
  return Serializer;
6607
6849
  }());
6608
6850
 
6609
- var OfflineListener = /** @class */ (function () {
6610
- function OfflineListener() {
6611
- var _window = getWindow();
6612
- var _document = getDocument();
6613
- var isListening = false;
6614
- var _onlineStatus = true;
6615
- dynamicProto(OfflineListener, this, function (_self) {
6616
- try {
6617
- if (_window) {
6618
- if (attachEvent(_window, "online", _setOnline)) {
6619
- attachEvent(_window, "offline", _setOffline);
6620
- isListening = true;
6621
- }
6622
- }
6623
- if (_document) {
6624
- var target = _document.body || _document;
6625
- if (!isUndefined(target.ononline)) {
6626
- target.ononline = _setOnline;
6627
- target.onoffline = _setOffline;
6628
- isListening = true;
6629
- }
6630
- }
6631
- if (isListening) {
6632
- var _navigator = getNavigator();
6633
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6634
- _onlineStatus = _navigator.onLine;
6635
- }
6851
+ function _disableEvents(target, evtNamespace) {
6852
+ eventOff(target, null, null, evtNamespace);
6853
+ }
6854
+ function createOfflineListener(parentEvtNamespace) {
6855
+ var _document = getDocument();
6856
+ var _navigator = getNavigator();
6857
+ var _isListening = false;
6858
+ var _onlineStatus = true;
6859
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
6860
+ try {
6861
+ if (_enableEvents(getWindow())) {
6862
+ _isListening = true;
6863
+ }
6864
+ if (_document) {
6865
+ var target = _document.body || _document;
6866
+ if (target.ononline) {
6867
+ if (_enableEvents(target)) {
6868
+ _isListening = true;
6636
6869
  }
6637
6870
  }
6638
- catch (e) {
6639
- isListening = false;
6871
+ }
6872
+ if (_isListening) {
6873
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6874
+ _onlineStatus = _navigator.onLine;
6640
6875
  }
6641
- _self.isListening = isListening;
6642
- _self.isOnline = function () {
6643
- var result = true;
6644
- var _navigator = getNavigator();
6645
- if (isListening) {
6646
- result = _onlineStatus;
6647
- }
6648
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6649
- result = _navigator.onLine;
6650
- }
6651
- return result;
6652
- };
6653
- _self.isOffline = function () {
6654
- return !_self.isOnline();
6655
- };
6656
- function _setOnline() {
6657
- _onlineStatus = true;
6876
+ }
6877
+ }
6878
+ catch (e) {
6879
+ _isListening = false;
6880
+ }
6881
+ function _enableEvents(target) {
6882
+ var enabled = false;
6883
+ if (target) {
6884
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
6885
+ if (enabled) {
6886
+ eventOn(target, "offline", _setOffline, _evtNamespace);
6658
6887
  }
6659
- function _setOffline() {
6660
- _onlineStatus = false;
6888
+ }
6889
+ return enabled;
6890
+ }
6891
+ function _setOnline() {
6892
+ _onlineStatus = true;
6893
+ }
6894
+ function _setOffline() {
6895
+ _onlineStatus = false;
6896
+ }
6897
+ function _isOnline() {
6898
+ var result = true;
6899
+ if (_isListening) {
6900
+ result = _onlineStatus;
6901
+ }
6902
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6903
+ result = _navigator.onLine;
6904
+ }
6905
+ return result;
6906
+ }
6907
+ function _unload() {
6908
+ var win = getWindow();
6909
+ if (win && _isListening) {
6910
+ _disableEvents(win, _evtNamespace);
6911
+ if (_document) {
6912
+ var target = _document.body || _document;
6913
+ if (!isUndefined(target.ononline)) {
6914
+ _disableEvents(target, _evtNamespace);
6915
+ }
6661
6916
  }
6662
- });
6917
+ _isListening = false;
6918
+ }
6663
6919
  }
6664
- OfflineListener.Offline = new OfflineListener;
6665
- return OfflineListener;
6666
- }());
6667
- var Offline = OfflineListener.Offline;
6920
+ return {
6921
+ isOnline: _isOnline,
6922
+ isListening: function () { return _isListening; },
6923
+ unload: _unload
6924
+ };
6925
+ }
6668
6926
 
6669
6927
  var MIN_INPUT_LENGTH = 8;
6670
6928
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -6792,22 +7050,22 @@
6792
7050
  var _this = _super.call(this) || this;
6793
7051
  _this.priority = 1001;
6794
7052
  _this.identifier = BreezeChannelIdentifier;
7053
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
6795
7054
  var _consecutiveErrors;
6796
7055
  var _retryAt;
6797
7056
  var _lastSend;
6798
- var _paused = false;
7057
+ var _paused;
6799
7058
  var _timeoutHandle;
6800
7059
  var _serializer;
6801
7060
  var _stamp_specific_redirects;
6802
- var _headers = {};
7061
+ var _headers;
6803
7062
  var _syncFetchPayload = 0;
6804
7063
  var _fallbackSender;
6805
7064
  var _syncUnloadSender;
6806
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
7065
+ var _offlineListener;
7066
+ var _evtNamespace;
6807
7067
  dynamicProto(Sender, _this, function (_self, _base) {
6808
- function _notImplemented() {
6809
- throwError("Method not implemented.");
6810
- }
7068
+ _initDefaults();
6811
7069
  _self.pause = function () {
6812
7070
  _clearScheduledTimer();
6813
7071
  _paused = true;
@@ -6830,7 +7088,7 @@
6830
7088
  _self.triggerSend(isAsync, null, sendReason || 1 );
6831
7089
  }
6832
7090
  catch (e) {
6833
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7091
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6834
7092
  }
6835
7093
  }
6836
7094
  };
@@ -6841,7 +7099,7 @@
6841
7099
  _self.triggerSend(true, _doUnloadSend, 2 );
6842
7100
  }
6843
7101
  catch (e) {
6844
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7102
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6845
7103
  }
6846
7104
  }
6847
7105
  else {
@@ -6849,7 +7107,6 @@
6849
7107
  }
6850
7108
  }
6851
7109
  };
6852
- _self.teardown = _notImplemented;
6853
7110
  _self.addHeader = function (name, value) {
6854
7111
  _headers[name] = value;
6855
7112
  };
@@ -6864,6 +7121,8 @@
6864
7121
  _self._sender = null;
6865
7122
  _stamp_specific_redirects = 0;
6866
7123
  var diagLog = _self.diagLog();
7124
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
7125
+ _offlineListener = createOfflineListener(_evtNamespace);
6867
7126
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
6868
7127
  objForEachKey(defaultConfig, function (field, value) {
6869
7128
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -6872,7 +7131,7 @@
6872
7131
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
6873
7132
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
6874
7133
  if (!_validateInstrumentationKey(config)) {
6875
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
7134
+ _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
6876
7135
  }
6877
7136
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
6878
7137
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -6918,22 +7177,22 @@
6918
7177
  return;
6919
7178
  }
6920
7179
  if (!telemetryItem) {
6921
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
7180
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
6922
7181
  return;
6923
7182
  }
6924
7183
  if (telemetryItem.baseData && !telemetryItem.baseType) {
6925
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
7184
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
6926
7185
  return;
6927
7186
  }
6928
7187
  if (!telemetryItem.baseType) {
6929
7188
  telemetryItem.baseType = "EventData";
6930
7189
  }
6931
7190
  if (!_self._sender) {
6932
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
7191
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
6933
7192
  return;
6934
7193
  }
6935
7194
  if (!_isSampledIn(telemetryItem)) {
6936
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
7195
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
6937
7196
  return;
6938
7197
  }
6939
7198
  else {
@@ -6943,7 +7202,7 @@
6943
7202
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
6944
7203
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
6945
7204
  if (!aiEnvelope_1) {
6946
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
7205
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
6947
7206
  return;
6948
7207
  }
6949
7208
  var doNotSendItem_1 = false;
@@ -6956,7 +7215,7 @@
6956
7215
  }
6957
7216
  }
6958
7217
  catch (e) {
6959
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
7218
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
6960
7219
  }
6961
7220
  });
6962
7221
  delete telemetryItem.tags[ProcessLegacy];
@@ -6974,7 +7233,7 @@
6974
7233
  _setupTimer();
6975
7234
  }
6976
7235
  catch (e) {
6977
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7236
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
6978
7237
  }
6979
7238
  _self.processNext(telemetryItem, itemCtx);
6980
7239
  };
@@ -7009,13 +7268,18 @@
7009
7268
  catch (e) {
7010
7269
  var ieVer = getIEVersion();
7011
7270
  if (!ieVer || ieVer > 9) {
7012
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7271
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7013
7272
  }
7014
7273
  }
7015
7274
  }
7016
7275
  };
7276
+ _self._doTeardown = function (unloadCtx, unloadState) {
7277
+ _self.onunloadFlush();
7278
+ _offlineListener.unload();
7279
+ _initDefaults();
7280
+ };
7017
7281
  _self._onError = function (payload, message, event) {
7018
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
7282
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
7019
7283
  _self._buffer.clearSent(payload);
7020
7284
  };
7021
7285
  _self._onPartialSuccess = function (payload, results) {
@@ -7040,7 +7304,7 @@
7040
7304
  }
7041
7305
  if (retry.length > 0) {
7042
7306
  _resendPayload(retry);
7043
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7307
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7044
7308
  "Delivered: " + payload.length + ", Failed: " + failed.length +
7045
7309
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
7046
7310
  }
@@ -7085,18 +7349,18 @@
7085
7349
  }
7086
7350
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
7087
7351
  _resendPayload(payload);
7088
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7352
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7089
7353
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
7090
7354
  }
7091
7355
  else {
7092
7356
  _self._onError(payload, errorMessage);
7093
7357
  }
7094
7358
  }
7095
- else if (Offline.isOffline()) {
7359
+ else if (_offlineListener && !_offlineListener.isOnline()) {
7096
7360
  if (!_self._senderConfig.isRetryDisabled()) {
7097
7361
  var offlineBackOffMultiplier = 10;
7098
7362
  _resendPayload(payload, offlineBackOffMultiplier);
7099
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(Offline.isOffline(), ". Will retry to send ").concat(payload.length, " items."));
7363
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(!_offlineListener.isOnline(), ". Will retry to send ").concat(payload.length, " items."));
7100
7364
  }
7101
7365
  }
7102
7366
  else {
@@ -7163,8 +7427,8 @@
7163
7427
  }
7164
7428
  }
7165
7429
  if (droppedPayload.length > 0) {
7166
- _fallbackSender(droppedPayload, true);
7167
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7430
+ _fallbackSender && _fallbackSender(droppedPayload, true);
7431
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7168
7432
  }
7169
7433
  }
7170
7434
  }
@@ -7205,7 +7469,7 @@
7205
7469
  }
7206
7470
  else {
7207
7471
  _fallbackSender && _fallbackSender(payload, true);
7208
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7472
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7209
7473
  }
7210
7474
  }
7211
7475
  }
@@ -7296,7 +7560,7 @@
7296
7560
  }
7297
7561
  }
7298
7562
  catch (e) {
7299
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7563
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7300
7564
  response: response
7301
7565
  });
7302
7566
  }
@@ -7367,7 +7631,7 @@
7367
7631
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
7368
7632
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
7369
7633
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
7370
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7634
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7371
7635
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
7372
7636
  buffer.clear();
7373
7637
  return;
@@ -7398,7 +7662,7 @@
7398
7662
  manager.eventsSendRequest(sendRequest, isAsync);
7399
7663
  }
7400
7664
  catch (e) {
7401
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7665
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7402
7666
  }
7403
7667
  }
7404
7668
  }
@@ -7411,6 +7675,25 @@
7411
7675
  var regexp = new RegExp(UUID_Regex);
7412
7676
  return regexp.test(config.instrumentationKey);
7413
7677
  }
7678
+ function _initDefaults() {
7679
+ _self._sender = null;
7680
+ _self._buffer = null;
7681
+ _self._appId = null;
7682
+ _self._sample = null;
7683
+ _headers = {};
7684
+ _offlineListener = null;
7685
+ _consecutiveErrors = 0;
7686
+ _retryAt = null;
7687
+ _lastSend = null;
7688
+ _paused = false;
7689
+ _timeoutHandle = null;
7690
+ _serializer = null;
7691
+ _stamp_specific_redirects = 0;
7692
+ _syncFetchPayload = 0;
7693
+ _fallbackSender = null;
7694
+ _syncUnloadSender = null;
7695
+ _evtNamespace = null;
7696
+ }
7414
7697
  });
7415
7698
  return _this;
7416
7699
  }
@@ -7580,7 +7863,7 @@
7580
7863
  return Device;
7581
7864
  }());
7582
7865
 
7583
- var Version = "2.8.0-beta.2203-03";
7866
+ var Version = "2.8.0-beta.2203-06";
7584
7867
  var Internal = /** @class */ (function () {
7585
7868
  function Internal(config) {
7586
7869
  this.sdkVersion = (config.sdkExtension && config.sdkExtension() ? config.sdkExtension() + "_" : "") + "javascript:" + Version;
@@ -9003,7 +9286,7 @@
9003
9286
  config.endpointUrl = ingest ? "".concat(ingest, "/v2/track") : config.endpointUrl;
9004
9287
  config.instrumentationKey = cs.instrumentationkey || config.instrumentationKey;
9005
9288
  }
9006
- _self.appInsights = new ApplicationInsights();
9289
+ _self.appInsights = new AnalyticsPlugin();
9007
9290
  _self.properties = new PropertiesPlugin$1();
9008
9291
  _self.dependencies = new AjaxMonitor();
9009
9292
  _self.core = new AppInsightsCore();
@@ -9428,7 +9711,7 @@
9428
9711
  }());
9429
9712
 
9430
9713
  exports.AppInsightsCore = AppInsightsCore;
9431
- exports.ApplicationAnalytics = ApplicationInsights;
9714
+ exports.ApplicationAnalytics = AnalyticsPlugin;
9432
9715
  exports.ApplicationInsights = Initialization;
9433
9716
  exports.ApplicationInsightsContainer = ApplicationInsightsContainer;
9434
9717
  exports.BaseCore = BaseCore;