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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/browser/applicationinsights-analytics-js.integrity.json +9 -9
  2. package/browser/applicationinsights-analytics-js.js +1621 -660
  3. package/browser/applicationinsights-analytics-js.js.map +1 -1
  4. package/browser/applicationinsights-analytics-js.min.js +2 -2
  5. package/browser/applicationinsights-analytics-js.min.js.map +1 -1
  6. package/dist/applicationinsights-analytics-js.api.json +49 -184
  7. package/dist/applicationinsights-analytics-js.api.md +8 -18
  8. package/dist/applicationinsights-analytics-js.d.ts +9 -104
  9. package/dist/applicationinsights-analytics-js.js +1621 -660
  10. package/dist/applicationinsights-analytics-js.js.map +1 -1
  11. package/dist/applicationinsights-analytics-js.min.js +2 -2
  12. package/dist/applicationinsights-analytics-js.min.js.map +1 -1
  13. package/dist/applicationinsights-analytics-js.rollup.d.ts +9 -104
  14. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js +674 -0
  15. package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js.map +1 -0
  16. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js +21 -8
  17. package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +10 -10
  19. package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +5 -5
  21. package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Timing.js +39 -0
  23. package/dist-esm/JavaScriptSDK/Timing.js.map +1 -0
  24. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
  25. package/dist-esm/applicationinsights-analytics-js.js +2 -2
  26. package/dist-esm/applicationinsights-analytics-js.js.map +1 -1
  27. package/package.json +6 -6
  28. package/src/JavaScriptSDK/{ApplicationInsights.ts → AnalyticsPlugin.ts} +403 -325
  29. package/src/JavaScriptSDK/Telemetry/PageViewManager.ts +32 -13
  30. package/src/JavaScriptSDK/Telemetry/PageViewPerformanceManager.ts +6 -6
  31. package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +1 -1
  32. package/src/JavaScriptSDK/Timing.ts +46 -0
  33. package/src/applicationinsights-analytics-js.ts +1 -1
  34. package/types/JavaScriptSDK/{ApplicationInsights.d.ts → AnalyticsPlugin.d.ts} +12 -16
  35. package/types/JavaScriptSDK/Telemetry/PageViewManager.d.ts +2 -1
  36. package/types/JavaScriptSDK/Telemetry/PageViewPerformanceManager.d.ts +9 -9
  37. package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +4 -4
  38. package/types/JavaScriptSDK/Timing.d.ts +18 -0
  39. package/types/applicationinsights-analytics-js.d.ts +1 -1
  40. package/types/tsdoc-metadata.json +1 -1
  41. package/dist-esm/JavaScriptSDK/ApplicationInsights.js +0 -606
  42. package/dist-esm/JavaScriptSDK/ApplicationInsights.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Web Analytics, 2.7.5-nightly.2203-02
2
+ * Application Insights JavaScript SDK - Web Analytics, 2.7.5-nightly.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -75,7 +75,9 @@
75
75
  var __assignFn = ObjAssign || __objAssignFnImpl;
76
76
  var extendStaticsFn = function (d, b) {
77
77
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
78
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
78
+ ({ __proto__: [] } instanceof Array && function (d, b) {
79
+ d.__proto__ = b;
80
+ }) ||
79
81
  function (d, b) {
80
82
  for (var p in b) {
81
83
  if (b[strShimHasOwnProperty](p)) {
@@ -90,7 +92,9 @@
90
92
  throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
91
93
  }
92
94
  extendStaticsFn(d, b);
93
- function __() { this.constructor = d; }
95
+ function __() {
96
+ this.constructor = d;
97
+ }
94
98
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
95
99
  }
96
100
 
@@ -109,11 +113,11 @@
109
113
  var DynAllowInstChkTag = DynInstChkTag;
110
114
  var DynProtoDefaultOptions = '_dfOpts';
111
115
  var UnknownValue = '_unknown_';
112
- var str__Proto = "__proto__";
116
+ var str__Proto$1 = "__proto__";
113
117
  var strUseBaseInst = 'useBaseInst';
114
118
  var strSetInstFuncs = 'setInstFuncs';
115
119
  var Obj = Object;
116
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
120
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
117
121
  var _dynamicNames = 0;
118
122
  function _hasOwnProperty(obj, prop) {
119
123
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -124,12 +128,12 @@
124
128
  function _isObjectArrayOrFunctionPrototype(target) {
125
129
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
126
130
  }
127
- function _getObjProto(target) {
131
+ function _getObjProto$1(target) {
128
132
  if (target) {
129
- if (_objGetPrototypeOf) {
130
- return _objGetPrototypeOf(target);
133
+ if (_objGetPrototypeOf$1) {
134
+ return _objGetPrototypeOf$1(target);
131
135
  }
132
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
136
+ var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
133
137
  if (newProto) {
134
138
  return newProto;
135
139
  }
@@ -195,16 +199,16 @@
195
199
  _forEachProp(instFuncs, function (name) {
196
200
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
197
201
  });
198
- var baseProto = _getObjProto(classProto);
202
+ var baseProto = _getObjProto$1(classProto);
199
203
  var visited = [];
200
204
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
201
205
  _forEachProp(baseProto, function (name) {
202
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
206
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
203
207
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
204
208
  }
205
209
  });
206
210
  visited.push(baseProto);
207
- baseProto = _getObjProto(baseProto);
211
+ baseProto = _getObjProto$1(baseProto);
208
212
  }
209
213
  return baseFuncs;
210
214
  }
@@ -218,7 +222,7 @@
218
222
  }
219
223
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
220
224
  var canAddInst = !_hasOwnProperty(target, funcName);
221
- var objProto = _getObjProto(target);
225
+ var objProto = _getObjProto$1(target);
222
226
  var visited = [];
223
227
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
224
228
  var protoFunc = objProto[funcName];
@@ -227,7 +231,7 @@
227
231
  break;
228
232
  }
229
233
  visited.push(objProto);
230
- objProto = _getObjProto(objProto);
234
+ objProto = _getObjProto$1(objProto);
231
235
  }
232
236
  try {
233
237
  if (canAddInst) {
@@ -245,7 +249,7 @@
245
249
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
246
250
  var protoFunc = proto[funcName];
247
251
  if (protoFunc === currentDynProtoProxy) {
248
- protoFunc = _getObjProto(proto)[funcName];
252
+ protoFunc = _getObjProto$1(proto)[funcName];
249
253
  }
250
254
  if (typeof protoFunc !== strFunction) {
251
255
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -279,15 +283,15 @@
279
283
  }
280
284
  }
281
285
  function _checkPrototype(classProto, thisTarget) {
282
- if (_objGetPrototypeOf) {
286
+ if (_objGetPrototypeOf$1) {
283
287
  var visited = [];
284
- var thisProto = _getObjProto(thisTarget);
288
+ var thisProto = _getObjProto$1(thisTarget);
285
289
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
286
290
  if (thisProto === classProto) {
287
291
  return true;
288
292
  }
289
293
  visited.push(thisProto);
290
- thisProto = _getObjProto(thisProto);
294
+ thisProto = _getObjProto$1(thisProto);
291
295
  }
292
296
  }
293
297
  return false;
@@ -323,7 +327,7 @@
323
327
  var instFuncs = _getInstanceFuncs(target);
324
328
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
325
329
  delegateFunc(target, baseFuncs);
326
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
330
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
327
331
  if (setInstanceFunc && options) {
328
332
  setInstanceFunc = !!options[strSetInstFuncs];
329
333
  }
@@ -335,102 +339,25 @@
335
339
  };
336
340
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
337
341
 
338
- var LoggingSeverity;
339
- (function (LoggingSeverity) {
340
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
341
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
342
- })(LoggingSeverity || (LoggingSeverity = {}));
343
- var _InternalMessageId = {
344
- BrowserDoesNotSupportLocalStorage: 0,
345
- BrowserCannotReadLocalStorage: 1,
346
- BrowserCannotReadSessionStorage: 2,
347
- BrowserCannotWriteLocalStorage: 3,
348
- BrowserCannotWriteSessionStorage: 4,
349
- BrowserFailedRemovalFromLocalStorage: 5,
350
- BrowserFailedRemovalFromSessionStorage: 6,
351
- CannotSendEmptyTelemetry: 7,
352
- ClientPerformanceMathError: 8,
353
- ErrorParsingAISessionCookie: 9,
354
- ErrorPVCalc: 10,
355
- ExceptionWhileLoggingError: 11,
356
- FailedAddingTelemetryToBuffer: 12,
357
- FailedMonitorAjaxAbort: 13,
358
- FailedMonitorAjaxDur: 14,
359
- FailedMonitorAjaxOpen: 15,
360
- FailedMonitorAjaxRSC: 16,
361
- FailedMonitorAjaxSend: 17,
362
- FailedMonitorAjaxGetCorrelationHeader: 18,
363
- FailedToAddHandlerForOnBeforeUnload: 19,
364
- FailedToSendQueuedTelemetry: 20,
365
- FailedToReportDataLoss: 21,
366
- FlushFailed: 22,
367
- MessageLimitPerPVExceeded: 23,
368
- MissingRequiredFieldSpecification: 24,
369
- NavigationTimingNotSupported: 25,
370
- OnError: 26,
371
- SessionRenewalDateIsZero: 27,
372
- SenderNotInitialized: 28,
373
- StartTrackEventFailed: 29,
374
- StopTrackEventFailed: 30,
375
- StartTrackFailed: 31,
376
- StopTrackFailed: 32,
377
- TelemetrySampledAndNotSent: 33,
378
- TrackEventFailed: 34,
379
- TrackExceptionFailed: 35,
380
- TrackMetricFailed: 36,
381
- TrackPVFailed: 37,
382
- TrackPVFailedCalc: 38,
383
- TrackTraceFailed: 39,
384
- TransmissionFailed: 40,
385
- FailedToSetStorageBuffer: 41,
386
- FailedToRestoreStorageBuffer: 42,
387
- InvalidBackendResponse: 43,
388
- FailedToFixDepricatedValues: 44,
389
- InvalidDurationValue: 45,
390
- TelemetryEnvelopeInvalid: 46,
391
- CreateEnvelopeError: 47,
392
- CannotSerializeObject: 48,
393
- CannotSerializeObjectNonSerializable: 49,
394
- CircularReferenceDetected: 50,
395
- ClearAuthContextFailed: 51,
396
- ExceptionTruncated: 52,
397
- IllegalCharsInName: 53,
398
- ItemNotInArray: 54,
399
- MaxAjaxPerPVExceeded: 55,
400
- MessageTruncated: 56,
401
- NameTooLong: 57,
402
- SampleRateOutOfRange: 58,
403
- SetAuthContextFailed: 59,
404
- SetAuthContextFailedAccountName: 60,
405
- StringValueTooLong: 61,
406
- StartCalledMoreThanOnce: 62,
407
- StopCalledWithoutStart: 63,
408
- TelemetryInitializerFailed: 64,
409
- TrackArgumentsNotSpecified: 65,
410
- UrlTooLong: 66,
411
- SessionStorageBufferFull: 67,
412
- CannotAccessCookie: 68,
413
- IdTooLong: 69,
414
- InvalidEvent: 70,
415
- FailedMonitorAjaxSetRequestHeader: 71,
416
- SendBrowserInfoOnUserInit: 72,
417
- PluginException: 73,
418
- NotificationException: 74,
419
- SnippetScriptLoadFailure: 99,
420
- InvalidInstrumentationKey: 100,
421
- CannotParseAiBlobValue: 101,
422
- InvalidContentBlob: 102,
423
- TrackPageActionEventFailed: 103,
424
- FailedAddingCustomDefinedRequestContext: 104,
425
- InMemoryStorageBufferFull: 105
426
- };
342
+ var strEmpty$1 = "";
343
+ var strSetNextPlugin = "setNextPlugin";
344
+ var strIsInitialized = "isInitialized";
345
+ var strTeardown = "teardown";
346
+ var strCore = "core";
347
+ var strUpdate = "update";
348
+ var strDisabled = "disabled";
349
+ var strDoTeardown = "_doTeardown";
427
350
 
428
351
  var strToISOString = "toISOString";
429
352
  var cStrEndsWith = "endsWith";
430
353
  var strMap = "map";
431
354
  var cStrTrim = "trim";
432
355
  var strToString = "toString";
433
- var _objDefineProperty = ObjDefineProperty;
356
+ var str__Proto = "__proto__";
357
+ var strConstructor = "constructor";
358
+ var _objDefineProperty$1 = ObjDefineProperty;
359
+ var _objFreeze = ObjClass.freeze;
360
+ var _objKeys = ObjClass.keys;
434
361
  var StringProto = String[strShimPrototype];
435
362
  var _strTrim = StringProto[cStrTrim];
436
363
  var _strEndsWith = StringProto[cStrEndsWith];
@@ -439,7 +366,23 @@
439
366
  var _isArray = Array.isArray;
440
367
  var _objToString = ObjProto[strToString];
441
368
  var _fnToString = ObjHasOwnProperty[strToString];
442
- _fnToString.call(ObjClass);
369
+ var _objFunctionString = _fnToString.call(ObjClass);
370
+ var rCamelCase = /-([a-z])/g;
371
+ var rNormalizeInvalid = /([^\w\d_$])/g;
372
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
373
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
374
+ function _getObjProto(target) {
375
+ if (target) {
376
+ if (_objGetPrototypeOf) {
377
+ return _objGetPrototypeOf(target);
378
+ }
379
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
380
+ if (newProto) {
381
+ return newProto;
382
+ }
383
+ }
384
+ return null;
385
+ }
443
386
  function isUndefined(value) {
444
387
  return value === undefined || typeof value === strShimUndefined;
445
388
  }
@@ -449,12 +392,28 @@
449
392
  function isNotNullOrUndefined(value) {
450
393
  return !isNullOrUndefined(value);
451
394
  }
395
+ function hasOwnProperty(obj, prop) {
396
+ return !!(obj && ObjHasOwnProperty.call(obj, prop));
397
+ }
452
398
  function isObject(value) {
453
399
  return !!(value && typeof value === strShimObject);
454
400
  }
455
401
  function isFunction(value) {
456
402
  return !!(value && typeof value === strShimFunction);
457
403
  }
404
+ function normalizeJsName(name) {
405
+ var value = name;
406
+ if (value && isString(value)) {
407
+ value = value.replace(rCamelCase, function (_all, letter) {
408
+ return letter.toUpperCase();
409
+ });
410
+ value = value.replace(rNormalizeInvalid, "_");
411
+ value = value.replace(rLeadingNumeric, function (_all, match) {
412
+ return "_" + match;
413
+ });
414
+ }
415
+ return value;
416
+ }
458
417
  function objForEachKey(target, callbackfn) {
459
418
  if (target) {
460
419
  for (var prop in target) {
@@ -503,6 +462,25 @@
503
462
  function isString(value) {
504
463
  return typeof value === "string";
505
464
  }
465
+ function isBoolean(value) {
466
+ return typeof value === "boolean";
467
+ }
468
+ function isPlainObject(value) {
469
+ var result = false;
470
+ if (value && typeof value === "object") {
471
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
472
+ if (!proto) {
473
+ result = true;
474
+ }
475
+ else {
476
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
477
+ proto = proto[strConstructor];
478
+ }
479
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
480
+ }
481
+ }
482
+ return result;
483
+ }
506
484
  function toISOString(date) {
507
485
  if (date) {
508
486
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -568,8 +546,42 @@
568
546
  }
569
547
  return str;
570
548
  }
549
+ var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
550
+ var _objKeysDontEnums = [
551
+ "toString",
552
+ "toLocaleString",
553
+ "valueOf",
554
+ "hasOwnProperty",
555
+ "isPrototypeOf",
556
+ "propertyIsEnumerable",
557
+ "constructor"
558
+ ];
559
+ function objKeys(obj) {
560
+ var objType = typeof obj;
561
+ if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
562
+ throwTypeError("objKeys called on non-object");
563
+ }
564
+ if (!_objKeysHasDontEnumBug && _objKeys) {
565
+ return _objKeys(obj);
566
+ }
567
+ var result = [];
568
+ for (var prop in obj) {
569
+ if (obj && ObjHasOwnProperty.call(obj, prop)) {
570
+ result.push(prop);
571
+ }
572
+ }
573
+ if (_objKeysHasDontEnumBug) {
574
+ var dontEnumsLength = _objKeysDontEnums.length;
575
+ for (var lp = 0; lp < dontEnumsLength; lp++) {
576
+ if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
577
+ result.push(_objKeysDontEnums[lp]);
578
+ }
579
+ }
580
+ }
581
+ return result;
582
+ }
571
583
  function objDefineAccessors(target, prop, getProp, setProp) {
572
- if (_objDefineProperty) {
584
+ if (_objDefineProperty$1) {
573
585
  try {
574
586
  var descriptor = {
575
587
  enumerable: true,
@@ -581,7 +593,7 @@
581
593
  if (setProp) {
582
594
  descriptor.set = setProp;
583
595
  }
584
- _objDefineProperty(target, prop, descriptor);
596
+ _objDefineProperty$1(target, prop, descriptor);
585
597
  return true;
586
598
  }
587
599
  catch (e) {
@@ -589,6 +601,10 @@
589
601
  }
590
602
  return false;
591
603
  }
604
+ function _doNothing(value) {
605
+ return value;
606
+ }
607
+ var objFreeze = _objFreeze || _doNothing;
592
608
  function dateNow() {
593
609
  var dt = Date;
594
610
  return dt.now ? dt.now() : new dt().getTime();
@@ -597,7 +613,7 @@
597
613
  if (isError(object)) {
598
614
  return object.name;
599
615
  }
600
- return "";
616
+ return strEmpty$1;
601
617
  }
602
618
  function setValue(target, field, value, valChk, srcChk) {
603
619
  var theValue = value;
@@ -616,6 +632,88 @@
616
632
  function throwError(message) {
617
633
  throw new Error(message);
618
634
  }
635
+ function _createProxyFunction(source, funcName) {
636
+ var srcFunc = null;
637
+ var src = null;
638
+ if (isFunction(source)) {
639
+ srcFunc = source;
640
+ }
641
+ else {
642
+ src = source;
643
+ }
644
+ return function () {
645
+ var originalArguments = arguments;
646
+ if (srcFunc) {
647
+ src = srcFunc();
648
+ }
649
+ if (src) {
650
+ return src[funcName].apply(src, originalArguments);
651
+ }
652
+ };
653
+ }
654
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
655
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
656
+ if (target && name && source) {
657
+ if (overwriteTarget || isUndefined(target[name])) {
658
+ target[name] = _createProxyFunction(source, theFunc);
659
+ }
660
+ }
661
+ }
662
+ function createEnumStyle(values) {
663
+ var enumClass = {};
664
+ objForEachKey(values, function (field, value) {
665
+ enumClass[field] = value;
666
+ if (!isUndefined(enumClass[value])) {
667
+ throwError("[" + value + "] exists for " + field);
668
+ }
669
+ enumClass[value] = field;
670
+ });
671
+ return objFreeze(enumClass);
672
+ }
673
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
674
+ var theArgs = arguments;
675
+ var extended = theArgs[0] || {};
676
+ var argLen = theArgs.length;
677
+ var deep = false;
678
+ var idx = 1;
679
+ if (argLen > 0 && isBoolean(extended)) {
680
+ deep = extended;
681
+ extended = theArgs[idx] || {};
682
+ idx++;
683
+ }
684
+ if (!isObject(extended)) {
685
+ extended = {};
686
+ }
687
+ for (; idx < argLen; idx++) {
688
+ var arg = theArgs[idx];
689
+ var isArgArray = isArray(arg);
690
+ var isArgObj = isObject(arg);
691
+ for (var prop in arg) {
692
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
693
+ if (!propOk) {
694
+ continue;
695
+ }
696
+ var newValue = arg[prop];
697
+ var isNewArray = void 0;
698
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
699
+ var clone = extended[prop];
700
+ if (isNewArray) {
701
+ if (!isArray(clone)) {
702
+ clone = [];
703
+ }
704
+ }
705
+ else if (!isPlainObject(clone)) {
706
+ clone = {};
707
+ }
708
+ newValue = objExtend(deep, clone, newValue);
709
+ }
710
+ if (newValue !== undefined) {
711
+ extended[prop] = newValue;
712
+ }
713
+ }
714
+ }
715
+ return extended;
716
+ }
619
717
 
620
718
  var strWindow = "window";
621
719
  var strDocument = "document";
@@ -718,14 +816,14 @@
718
816
  var nav = getNavigator();
719
817
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
720
818
  _navUserAgentCheck = nav.userAgent;
721
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
819
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
722
820
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
723
821
  }
724
822
  return _isTrident;
725
823
  }
726
824
  function dumpObj(object) {
727
825
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
728
- var propertyValueDump = "";
826
+ var propertyValueDump = strEmpty$1;
729
827
  if (objectTypeDump === "[object Error]") {
730
828
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
731
829
  }
@@ -758,9 +856,9 @@
758
856
  var strWarnToConsole = "warnToConsole";
759
857
  function _sanitizeDiagnosticText(text) {
760
858
  if (text) {
761
- return "\"" + text.replace(/\"/g, "") + "\"";
859
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
762
860
  }
763
- return "";
861
+ return strEmpty$1;
764
862
  }
765
863
  function _logToConsole(func, message) {
766
864
  var theConsole = getConsole();
@@ -782,12 +880,12 @@
782
880
  _self.message =
783
881
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
784
882
  msgId;
785
- var strProps = "";
883
+ var strProps = strEmpty$1;
786
884
  if (hasJSON()) {
787
885
  strProps = getJSON().stringify(properties);
788
886
  }
789
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
790
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
887
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
888
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
791
889
  _self.message += diagnosticText;
792
890
  }
793
891
  _InternalLogMessage.dataType = "MessageData";
@@ -817,7 +915,7 @@
817
915
  throw message;
818
916
  }
819
917
  else {
820
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
918
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
821
919
  if (!isUndefined(message.message)) {
822
920
  var logLevel = _self.consoleLoggingLevel();
823
921
  if (isUserAct) {
@@ -835,7 +933,7 @@
835
933
  _self.logInternalMessage(severity, message);
836
934
  }
837
935
  else {
838
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
936
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
839
937
  }
840
938
  }
841
939
  };
@@ -867,13 +965,13 @@
867
965
  if (severity <= _self.telemetryLoggingLevel()) {
868
966
  _self.queue.push(message);
869
967
  _messageCount++;
870
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
968
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
871
969
  }
872
970
  if (_messageCount === _self.maxInternalMessageLimit()) {
873
971
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
874
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
972
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
875
973
  _self.queue.push(throttleMessage);
876
- if (severity === LoggingSeverity.CRITICAL) {
974
+ if (severity === 1 ) {
877
975
  _self.errorToConsole(throttleLimitMessage);
878
976
  }
879
977
  else {
@@ -902,6 +1000,10 @@
902
1000
  }
903
1001
  return DiagnosticLogger;
904
1002
  }());
1003
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1004
+ if (isUserAct === void 0) { isUserAct = false; }
1005
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1006
+ }
905
1007
 
906
1008
  var strExecutionContextKey = "ctx";
907
1009
  var PerfEvent = /** @class */ (function () {
@@ -1015,252 +1117,495 @@
1015
1117
  return func();
1016
1118
  }
1017
1119
 
1018
- var TelemetryPluginChain = /** @class */ (function () {
1019
- function TelemetryPluginChain(plugin, defItemCtx) {
1020
- var _self = this;
1021
- var _nextProxy = null;
1022
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1023
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1024
- _self._hasRun = false;
1025
- _self.getPlugin = function () {
1026
- return plugin;
1027
- };
1028
- _self.getNext = function () {
1029
- return _nextProxy;
1030
- };
1031
- _self.setNext = function (nextPlugin) {
1032
- _nextProxy = nextPlugin;
1033
- };
1034
- _self.processTelemetry = function (env, itemCtx) {
1035
- if (!itemCtx) {
1036
- itemCtx = defItemCtx;
1037
- }
1038
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1039
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1040
- if (plugin && _hasProcessTelemetry) {
1041
- _self._hasRun = true;
1042
- try {
1043
- itemCtx.setNext(_nextProxy);
1044
- if (_hasSetNext) {
1045
- plugin.setNextPlugin(_nextProxy);
1046
- }
1047
- _nextProxy && (_nextProxy._hasRun = false);
1048
- plugin.processTelemetry(env, itemCtx);
1049
- }
1050
- catch (error) {
1051
- var hasRun = _nextProxy && _nextProxy._hasRun;
1052
- if (!_nextProxy || !hasRun) {
1053
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1054
- }
1055
- if (_nextProxy && !hasRun) {
1056
- _nextProxy.processTelemetry(env, itemCtx);
1057
- }
1058
- }
1059
- }
1060
- else if (_nextProxy) {
1061
- _self._hasRun = true;
1062
- _nextProxy.processTelemetry(env, itemCtx);
1063
- }
1064
- }, function () { return ({ item: env }); }, !(env.sync));
1065
- };
1120
+ var UInt32Mask = 0x100000000;
1121
+ var MaxUInt32 = 0xffffffff;
1122
+ var _mwcSeeded = false;
1123
+ var _mwcW = 123456789;
1124
+ var _mwcZ = 987654321;
1125
+ function _mwcSeed(seedValue) {
1126
+ if (seedValue < 0) {
1127
+ seedValue >>>= 0;
1066
1128
  }
1067
- return TelemetryPluginChain;
1068
- }());
1129
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1130
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1131
+ _mwcSeeded = true;
1132
+ }
1133
+ function _autoSeedMwc() {
1134
+ try {
1135
+ var now = dateNow() & 0x7fffffff;
1136
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1137
+ }
1138
+ catch (e) {
1139
+ }
1140
+ }
1141
+ function random32(signed) {
1142
+ var value = 0;
1143
+ var c = getCrypto() || getMsCrypto();
1144
+ if (c && c.getRandomValues) {
1145
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1146
+ }
1147
+ if (value === 0 && isIE()) {
1148
+ if (!_mwcSeeded) {
1149
+ _autoSeedMwc();
1150
+ }
1151
+ value = mwcRandom32() & MaxUInt32;
1152
+ }
1153
+ if (value === 0) {
1154
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1155
+ }
1156
+ if (!signed) {
1157
+ value >>>= 0;
1158
+ }
1159
+ return value;
1160
+ }
1161
+ function mwcRandom32(signed) {
1162
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1163
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1164
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1165
+ if (!signed) {
1166
+ value >>>= 0;
1167
+ }
1168
+ return value;
1169
+ }
1170
+ function newId(maxLength) {
1171
+ if (maxLength === void 0) { maxLength = 22; }
1172
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1173
+ var number = random32() >>> 0;
1174
+ var chars = 0;
1175
+ var result = strEmpty$1;
1176
+ while (result.length < maxLength) {
1177
+ chars++;
1178
+ result += base64chars.charAt(number & 0x3F);
1179
+ number >>>= 6;
1180
+ if (chars === 5) {
1181
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1182
+ chars = 0;
1183
+ }
1184
+ }
1185
+ return result;
1186
+ }
1069
1187
 
1070
- function _createProxyChain(plugins, itemCtx) {
1071
- var proxies = [];
1072
- if (plugins && plugins.length > 0) {
1073
- var lastProxy = null;
1074
- for (var idx = 0; idx < plugins.length; idx++) {
1075
- var thePlugin = plugins[idx];
1076
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1077
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1078
- proxies.push(newProxy);
1079
- if (lastProxy) {
1080
- lastProxy.setNext(newProxy);
1188
+ var _objDefineProperty = ObjDefineProperty;
1189
+ var version = "2.7.5-nightly.2203-03";
1190
+ var instanceName = "." + newId(6);
1191
+ var _dataUid = 0;
1192
+ function _createAccessor(target, prop, value) {
1193
+ if (_objDefineProperty) {
1194
+ try {
1195
+ _objDefineProperty(target, prop, {
1196
+ value: value,
1197
+ enumerable: false,
1198
+ configurable: true
1199
+ });
1200
+ return true;
1201
+ }
1202
+ catch (e) {
1203
+ }
1204
+ }
1205
+ return false;
1206
+ }
1207
+ function _canAcceptData(target) {
1208
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1209
+ }
1210
+ function _getCache(data, target) {
1211
+ var theCache = target[data.id];
1212
+ if (!theCache) {
1213
+ theCache = {};
1214
+ try {
1215
+ if (_canAcceptData(target)) {
1216
+ if (!_createAccessor(target, data.id, theCache)) {
1217
+ target[data.id] = theCache;
1081
1218
  }
1082
- lastProxy = newProxy;
1083
1219
  }
1084
1220
  }
1221
+ catch (e) {
1222
+ }
1085
1223
  }
1086
- return proxies.length > 0 ? proxies[0] : null;
1224
+ return theCache;
1087
1225
  }
1088
- function _copyProxyChain(proxy, itemCtx, startAt) {
1089
- var plugins = [];
1090
- var add = startAt ? false : true;
1091
- if (proxy) {
1092
- while (proxy) {
1093
- var thePlugin = proxy.getPlugin();
1094
- if (add || thePlugin === startAt) {
1095
- add = true;
1096
- plugins.push(thePlugin);
1226
+ function createUniqueNamespace(name, includeVersion) {
1227
+ if (includeVersion === void 0) { includeVersion = false; }
1228
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1229
+ }
1230
+ function createElmNodeData(name) {
1231
+ var data = {
1232
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1233
+ accept: function (target) {
1234
+ return _canAcceptData(target);
1235
+ },
1236
+ get: function (target, name, defValue, addDefault) {
1237
+ var theCache = target[data.id];
1238
+ if (!theCache) {
1239
+ if (addDefault) {
1240
+ theCache = _getCache(data, target);
1241
+ theCache[normalizeJsName(name)] = defValue;
1242
+ }
1243
+ return defValue;
1244
+ }
1245
+ return theCache[normalizeJsName(name)];
1246
+ },
1247
+ kill: function (target, name) {
1248
+ if (target && target[name]) {
1249
+ try {
1250
+ delete target[name];
1251
+ }
1252
+ catch (e) {
1253
+ }
1097
1254
  }
1098
- proxy = proxy.getNext();
1255
+ }
1256
+ };
1257
+ return data;
1258
+ }
1259
+
1260
+ var pluginStateData = createElmNodeData("plugin");
1261
+ function _getPluginState(plugin) {
1262
+ return pluginStateData.get(plugin, "state", {}, true);
1263
+ }
1264
+
1265
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1266
+ var strHasRunFlags = "_hasRun";
1267
+ var strGetTelCtx = "_getTelCtx";
1268
+ var _chainId = 0;
1269
+ function _getNextProxyStart(proxy, config, core, startAt) {
1270
+ while (proxy) {
1271
+ if (proxy.getPlugin() === startAt) {
1272
+ return proxy;
1273
+ }
1274
+ proxy = proxy.getNext();
1275
+ }
1276
+ return createTelemetryProxyChain([startAt], config, core);
1277
+ }
1278
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1279
+ var _nextProxy = null;
1280
+ var _onComplete = [];
1281
+ if (startAt !== null) {
1282
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1283
+ }
1284
+ var context = {
1285
+ _next: _moveNext,
1286
+ ctx: {
1287
+ core: function () {
1288
+ return core;
1289
+ },
1290
+ diagLog: function () {
1291
+ return safeGetLogger(core, config);
1292
+ },
1293
+ getCfg: function () {
1294
+ return config;
1295
+ },
1296
+ getExtCfg: _getExtCfg,
1297
+ getConfig: _getConfig,
1298
+ hasNext: function () {
1299
+ return !!_nextProxy;
1300
+ },
1301
+ getNext: function () {
1302
+ return _nextProxy;
1303
+ },
1304
+ setNext: function (nextPlugin) {
1305
+ _nextProxy = nextPlugin;
1306
+ },
1307
+ iterate: _iterateChain,
1308
+ onComplete: _addOnComplete
1309
+ }
1310
+ };
1311
+ function _addOnComplete(onComplete, that) {
1312
+ var args = [];
1313
+ for (var _i = 2; _i < arguments.length; _i++) {
1314
+ args[_i - 2] = arguments[_i];
1315
+ }
1316
+ if (onComplete) {
1317
+ _onComplete.push({
1318
+ func: onComplete,
1319
+ self: !isUndefined(that) ? that : context.ctx,
1320
+ args: args
1321
+ });
1099
1322
  }
1100
1323
  }
1101
- if (!add) {
1102
- plugins.push(startAt);
1324
+ function _moveNext() {
1325
+ var nextProxy = _nextProxy;
1326
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1327
+ if (!nextProxy) {
1328
+ var onComplete = _onComplete;
1329
+ if (onComplete && onComplete.length > 0) {
1330
+ arrForEach(onComplete, function (completeDetails) {
1331
+ try {
1332
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1333
+ }
1334
+ catch (e) {
1335
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1336
+ }
1337
+ });
1338
+ _onComplete = [];
1339
+ }
1340
+ }
1341
+ return nextProxy;
1342
+ }
1343
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1344
+ if (defaultValue === void 0) { defaultValue = {}; }
1345
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1346
+ var theConfig;
1347
+ if (config) {
1348
+ var extConfig = config.extensionConfig;
1349
+ if (extConfig && identifier) {
1350
+ theConfig = extConfig[identifier];
1351
+ }
1352
+ }
1353
+ if (!theConfig) {
1354
+ theConfig = defaultValue;
1355
+ }
1356
+ else if (isObject(defaultValue)) {
1357
+ if (mergeDefault !== 0 ) {
1358
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1359
+ if (config && mergeDefault === 2 ) {
1360
+ objForEachKey(defaultValue, function (field) {
1361
+ if (isNullOrUndefined(newConfig_1[field])) {
1362
+ var cfgValue = config[field];
1363
+ if (!isNullOrUndefined(cfgValue)) {
1364
+ newConfig_1[field] = cfgValue;
1365
+ }
1366
+ }
1367
+ });
1368
+ }
1369
+ }
1370
+ }
1371
+ return theConfig;
1372
+ }
1373
+ function _getConfig(identifier, field, defaultValue) {
1374
+ if (defaultValue === void 0) { defaultValue = false; }
1375
+ var theValue;
1376
+ var extConfig = _getExtCfg(identifier, null);
1377
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1378
+ theValue = extConfig[field];
1379
+ }
1380
+ else if (config && !isNullOrUndefined(config[field])) {
1381
+ theValue = config[field];
1382
+ }
1383
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1384
+ }
1385
+ function _iterateChain(cb) {
1386
+ var nextPlugin;
1387
+ while (!!(nextPlugin = context._next())) {
1388
+ var plugin = nextPlugin.getPlugin();
1389
+ if (plugin) {
1390
+ cb(plugin);
1391
+ }
1392
+ }
1103
1393
  }
1104
- return _createProxyChain(plugins, itemCtx);
1394
+ return context;
1105
1395
  }
1106
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1107
- var plugins = srcPlugins;
1108
- var add = false;
1109
- if (startAt && srcPlugins) {
1110
- plugins = [];
1111
- arrForEach(srcPlugins, function (thePlugin) {
1112
- if (add || thePlugin === startAt) {
1113
- add = true;
1114
- plugins.push(thePlugin);
1396
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1397
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1398
+ var context = internalContext.ctx;
1399
+ function _processNext(env) {
1400
+ var nextPlugin = internalContext._next();
1401
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1402
+ return !nextPlugin;
1403
+ }
1404
+ function _createNew(plugins, startAt) {
1405
+ if (plugins === void 0) { plugins = null; }
1406
+ if (isArray(plugins)) {
1407
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1408
+ }
1409
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1410
+ }
1411
+ context.processNext = _processNext;
1412
+ context.createNew = _createNew;
1413
+ return context;
1414
+ }
1415
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1416
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1417
+ var context = internalContext.ctx;
1418
+ function _processNext(unloadState) {
1419
+ var nextPlugin = internalContext._next();
1420
+ nextPlugin && nextPlugin.unload(context, unloadState);
1421
+ return !nextPlugin;
1422
+ }
1423
+ function _createNew(plugins, startAt) {
1424
+ if (plugins === void 0) { plugins = null; }
1425
+ if (isArray(plugins)) {
1426
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1427
+ }
1428
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1429
+ }
1430
+ context.processNext = _processNext;
1431
+ context.createNew = _createNew;
1432
+ return context;
1433
+ }
1434
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1435
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1436
+ var context = internalContext.ctx;
1437
+ function _processNext(updateState) {
1438
+ return context.iterate(function (plugin) {
1439
+ if (isFunction(plugin[strUpdate])) {
1440
+ plugin[strUpdate](context, updateState);
1115
1441
  }
1116
1442
  });
1117
1443
  }
1118
- if (startAt && !add) {
1119
- if (!plugins) {
1120
- plugins = [];
1444
+ function _createNew(plugins, startAt) {
1445
+ if (plugins === void 0) { plugins = null; }
1446
+ if (isArray(plugins)) {
1447
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1121
1448
  }
1122
- plugins.push(startAt);
1449
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1123
1450
  }
1124
- return _createProxyChain(plugins, itemCtx);
1451
+ context.processNext = _processNext;
1452
+ context.createNew = _createNew;
1453
+ return context;
1125
1454
  }
1126
- var ProcessTelemetryContext = /** @class */ (function () {
1127
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1128
- var _self = this;
1129
- var _nextProxy = null;
1130
- if (startAt !== null) {
1131
- if (plugins && isFunction(plugins.getPlugin)) {
1132
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1455
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1456
+ var firstProxy = null;
1457
+ var add = startAt ? false : true;
1458
+ if (isArray(plugins) && plugins.length > 0) {
1459
+ var lastProxy_1 = null;
1460
+ arrForEach(plugins, function (thePlugin) {
1461
+ if (!add && startAt === thePlugin) {
1462
+ add = true;
1133
1463
  }
1134
- else {
1135
- if (startAt) {
1136
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1464
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1465
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1466
+ if (!firstProxy) {
1467
+ firstProxy = newProxy;
1137
1468
  }
1138
- else if (isUndefined(startAt)) {
1139
- _nextProxy = _createProxyChain(plugins, _self);
1469
+ if (lastProxy_1) {
1470
+ lastProxy_1._setNext(newProxy);
1140
1471
  }
1472
+ lastProxy_1 = newProxy;
1141
1473
  }
1474
+ });
1475
+ }
1476
+ if (startAt && !firstProxy) {
1477
+ return createTelemetryProxyChain([startAt], config, core);
1478
+ }
1479
+ return firstProxy;
1480
+ }
1481
+ function createTelemetryPluginProxy(plugin, config, core) {
1482
+ var nextProxy = null;
1483
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1484
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1485
+ var chainId;
1486
+ if (plugin) {
1487
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1488
+ }
1489
+ else {
1490
+ chainId = "Unknown-0-" + _chainId++;
1491
+ }
1492
+ var proxyChain = {
1493
+ getPlugin: function () {
1494
+ return plugin;
1495
+ },
1496
+ getNext: function () {
1497
+ return nextProxy;
1498
+ },
1499
+ processTelemetry: _processTelemetry,
1500
+ unload: _unloadPlugin,
1501
+ update: _updatePlugin,
1502
+ _id: chainId,
1503
+ _setNext: function (nextPlugin) {
1504
+ nextProxy = nextPlugin;
1142
1505
  }
1143
- _self.core = function () {
1144
- return core;
1145
- };
1146
- _self.diagLog = function () {
1147
- return safeGetLogger(core, config);
1148
- };
1149
- _self.getCfg = function () {
1150
- return config;
1151
- };
1152
- _self.getExtCfg = function (identifier, defaultValue) {
1153
- if (defaultValue === void 0) { defaultValue = {}; }
1154
- var theConfig;
1155
- if (config) {
1156
- var extConfig = config.extensionConfig;
1157
- if (extConfig && identifier) {
1158
- theConfig = extConfig[identifier];
1506
+ };
1507
+ function _getTelCtx() {
1508
+ var itemCtx;
1509
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1510
+ itemCtx = plugin[strGetTelCtx]();
1511
+ }
1512
+ if (!itemCtx) {
1513
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1514
+ }
1515
+ return itemCtx;
1516
+ }
1517
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1518
+ var hasRun = false;
1519
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1520
+ var hasRunContext = itemCtx[strHasRunFlags];
1521
+ if (!hasRunContext) {
1522
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1523
+ }
1524
+ itemCtx.setNext(nextProxy);
1525
+ if (plugin) {
1526
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1527
+ hasRunContext[chainId] = true;
1528
+ try {
1529
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1530
+ if (nextId) {
1531
+ hasRunContext[nextId] = false;
1532
+ }
1533
+ hasRun = processPluginFn(itemCtx);
1159
1534
  }
1535
+ catch (error) {
1536
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1537
+ if (hasNextRun) {
1538
+ hasRun = true;
1539
+ }
1540
+ if (!nextProxy || !hasNextRun) {
1541
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1542
+ }
1543
+ }
1544
+ }, details, isAsync);
1545
+ }
1546
+ return hasRun;
1547
+ }
1548
+ function _processTelemetry(env, itemCtx) {
1549
+ itemCtx = itemCtx || _getTelCtx();
1550
+ function _callProcessTelemetry(itemCtx) {
1551
+ if (!plugin || !hasProcessTelemetry) {
1552
+ return false;
1160
1553
  }
1161
- return (theConfig ? theConfig : defaultValue);
1162
- };
1163
- _self.getConfig = function (identifier, field, defaultValue) {
1164
- if (defaultValue === void 0) { defaultValue = false; }
1165
- var theValue;
1166
- var extConfig = _self.getExtCfg(identifier, null);
1167
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1168
- theValue = extConfig[field];
1169
- }
1170
- else if (config && !isNullOrUndefined(config[field])) {
1171
- theValue = config[field];
1554
+ var pluginState = _getPluginState(plugin);
1555
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1556
+ return false;
1172
1557
  }
1173
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1174
- };
1175
- _self.hasNext = function () {
1176
- return _nextProxy != null;
1177
- };
1178
- _self.getNext = function () {
1179
- return _nextProxy;
1180
- };
1181
- _self.setNext = function (nextPlugin) {
1182
- _nextProxy = nextPlugin;
1183
- };
1184
- _self.processNext = function (env) {
1185
- var nextPlugin = _nextProxy;
1186
- if (nextPlugin) {
1187
- _nextProxy = nextPlugin.getNext();
1188
- nextPlugin.processTelemetry(env, _self);
1558
+ if (hasSetNext) {
1559
+ plugin.setNextPlugin(nextProxy);
1189
1560
  }
1190
- };
1191
- _self.createNew = function (plugins, startAt) {
1192
- if (plugins === void 0) { plugins = null; }
1193
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1194
- };
1561
+ plugin.processTelemetry(env, itemCtx);
1562
+ return true;
1563
+ }
1564
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1565
+ itemCtx.processNext(env);
1566
+ }
1195
1567
  }
1196
- return ProcessTelemetryContext;
1197
- }());
1198
-
1199
- var strExtensionConfig = "extensionConfig";
1200
-
1201
- var strGetPlugin = "getPlugin";
1202
- var BaseTelemetryPlugin = /** @class */ (function () {
1203
- function BaseTelemetryPlugin() {
1204
- var _self = this;
1205
- var _isinitialized = false;
1206
- var _rootCtx = null;
1207
- var _nextPlugin = null;
1208
- _self.core = null;
1209
- _self.diagLog = function (itemCtx) {
1210
- return _self._getTelCtx(itemCtx).diagLog();
1211
- };
1212
- _self.isInitialized = function () {
1213
- return _isinitialized;
1214
- };
1215
- _self.setInitialized = function (isInitialized) {
1216
- _isinitialized = isInitialized;
1217
- };
1218
- _self.setNextPlugin = function (next) {
1219
- _nextPlugin = next;
1220
- };
1221
- _self.processNext = function (env, itemCtx) {
1222
- if (itemCtx) {
1223
- itemCtx.processNext(env);
1224
- }
1225
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1226
- _nextPlugin.processTelemetry(env, null);
1227
- }
1228
- };
1229
- _self._getTelCtx = function (currentCtx) {
1230
- if (currentCtx === void 0) { currentCtx = null; }
1231
- var itemCtx = currentCtx;
1232
- if (!itemCtx) {
1233
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1234
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1235
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1236
- }
1237
- else {
1238
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1568
+ function _unloadPlugin(unloadCtx, unloadState) {
1569
+ function _callTeardown() {
1570
+ var hasRun = false;
1571
+ if (plugin) {
1572
+ var pluginState = _getPluginState(plugin);
1573
+ var pluginCore = plugin[strCore] || pluginState.core;
1574
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1575
+ pluginState[strCore] = null;
1576
+ pluginState[strTeardown] = true;
1577
+ pluginState[strIsInitialized] = false;
1578
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1579
+ hasRun = true;
1580
+ }
1239
1581
  }
1240
1582
  }
1241
- return itemCtx;
1242
- };
1243
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1244
- if (config) {
1245
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1246
- }
1247
- if (!pluginChain && core) {
1248
- pluginChain = core.getProcessTelContext().getNext();
1249
- }
1250
- var nextPlugin = _nextPlugin;
1251
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1252
- nextPlugin = _nextPlugin[strGetPlugin]();
1583
+ return hasRun;
1584
+ }
1585
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1586
+ unloadCtx.processNext(unloadState);
1587
+ }
1588
+ }
1589
+ function _updatePlugin(updateCtx, updateState) {
1590
+ function _callUpdate() {
1591
+ var hasRun = false;
1592
+ if (plugin) {
1593
+ var pluginState = _getPluginState(plugin);
1594
+ var pluginCore = plugin[strCore] || pluginState.core;
1595
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1596
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1597
+ hasRun = true;
1598
+ }
1599
+ }
1253
1600
  }
1254
- _self.core = core;
1255
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1256
- _isinitialized = true;
1257
- };
1601
+ return hasRun;
1602
+ }
1603
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1604
+ updateCtx.processNext(updateState);
1605
+ }
1258
1606
  }
1259
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1260
- this._baseTelInit(config, core, extensions, pluginChain);
1261
- };
1262
- return BaseTelemetryPlugin;
1263
- }());
1607
+ return objFreeze(proxyChain);
1608
+ }
1264
1609
 
1265
1610
  var strToGMTString = "toGMTString";
1266
1611
  var strToUTCString = "toUTCString";
@@ -1270,7 +1615,6 @@
1270
1615
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1271
1616
  var strDisableCookiesUsage = "disableCookiesUsage";
1272
1617
  var strConfigCookieMgr = "_ckMgr";
1273
- var strEmpty = "";
1274
1618
  var _supportsCookies = null;
1275
1619
  var _allowUaSameSite = null;
1276
1620
  var _parsedCookieValue = null;
@@ -1347,7 +1691,7 @@
1347
1691
  var result = false;
1348
1692
  if (_isMgrEnabled(cookieMgr)) {
1349
1693
  var values = {};
1350
- var theValue = strTrim(value || strEmpty);
1694
+ var theValue = strTrim(value || strEmpty$1);
1351
1695
  var idx = theValue.indexOf(";");
1352
1696
  if (idx !== -1) {
1353
1697
  theValue = strTrim(value.substring(0, idx));
@@ -1362,11 +1706,11 @@
1362
1706
  if (expireMs > 0) {
1363
1707
  var expiry = new Date();
1364
1708
  expiry.setTime(expireMs);
1365
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
1709
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1366
1710
  }
1367
1711
  }
1368
1712
  if (!_isIE) {
1369
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
1713
+ setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1370
1714
  }
1371
1715
  }
1372
1716
  var location_1 = getLocation();
@@ -1387,7 +1731,7 @@
1387
1731
  return result;
1388
1732
  },
1389
1733
  get: function (name) {
1390
- var value = strEmpty;
1734
+ var value = strEmpty$1;
1391
1735
  if (_isMgrEnabled(cookieMgr)) {
1392
1736
  value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1393
1737
  }
@@ -1412,7 +1756,7 @@
1412
1756
  values["max-age"] = "0";
1413
1757
  }
1414
1758
  var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1415
- delCookie(name, _formatCookieValue(strEmpty, values));
1759
+ delCookie(name, _formatCookieValue(strEmpty$1, values));
1416
1760
  result = true;
1417
1761
  }
1418
1762
  return result;
@@ -1429,7 +1773,7 @@
1429
1773
  _supportsCookies = doc[strCookie] !== undefined;
1430
1774
  }
1431
1775
  catch (e) {
1432
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1776
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1433
1777
  }
1434
1778
  }
1435
1779
  return _supportsCookies;
@@ -1439,7 +1783,7 @@
1439
1783
  if (theValue && theValue.length) {
1440
1784
  var parts = strTrim(theValue).split(";");
1441
1785
  arrForEach(parts, function (thePart) {
1442
- thePart = strTrim(thePart || strEmpty);
1786
+ thePart = strTrim(thePart || strEmpty$1);
1443
1787
  if (thePart) {
1444
1788
  var idx = thePart.indexOf("=");
1445
1789
  if (idx === -1) {
@@ -1460,21 +1804,21 @@
1460
1804
  return null;
1461
1805
  }
1462
1806
  function _formatCookieValue(value, values) {
1463
- var cookieValue = value || strEmpty;
1807
+ var cookieValue = value || strEmpty$1;
1464
1808
  objForEachKey(values, function (name, theValue) {
1465
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
1809
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1466
1810
  });
1467
1811
  return cookieValue;
1468
1812
  }
1469
1813
  function _getCookieValue(name) {
1470
- var cookieValue = strEmpty;
1814
+ var cookieValue = strEmpty$1;
1471
1815
  if (_doc) {
1472
- var theCookie = _doc[strCookie] || strEmpty;
1816
+ var theCookie = _doc[strCookie] || strEmpty$1;
1473
1817
  if (_parsedCookieValue !== theCookie) {
1474
1818
  _cookieCache = _extractParts(theCookie);
1475
1819
  _parsedCookieValue = theCookie;
1476
1820
  }
1477
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
1821
+ cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1478
1822
  }
1479
1823
  return cookieValue;
1480
1824
  }
@@ -1505,63 +1849,354 @@
1505
1849
  if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
1506
1850
  return true;
1507
1851
  }
1508
- return false;
1852
+ return false;
1853
+ }
1854
+
1855
+ var strExtensionConfig = "extensionConfig";
1856
+
1857
+ function createUnloadHandlerContainer() {
1858
+ var handlers = [];
1859
+ function _addHandler(handler) {
1860
+ if (handler) {
1861
+ handlers.push(handler);
1862
+ }
1863
+ }
1864
+ function _runHandlers(unloadCtx, unloadState) {
1865
+ arrForEach(handlers, function (handler) {
1866
+ try {
1867
+ handler(unloadCtx, unloadState);
1868
+ }
1869
+ catch (e) {
1870
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1871
+ }
1872
+ });
1873
+ handlers = [];
1874
+ }
1875
+ return {
1876
+ add: _addHandler,
1877
+ run: _runHandlers
1878
+ };
1879
+ }
1880
+
1881
+ var strGetPlugin = "getPlugin";
1882
+ var BaseTelemetryPlugin = /** @class */ (function () {
1883
+ function BaseTelemetryPlugin() {
1884
+ var _self = this;
1885
+ var _isinitialized;
1886
+ var _rootCtx;
1887
+ var _nextPlugin;
1888
+ var _unloadHandlerContainer;
1889
+ var _hooks;
1890
+ _initDefaults();
1891
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1892
+ _self.initialize = function (config, core, extensions, pluginChain) {
1893
+ _setDefaults(config, core, pluginChain);
1894
+ _isinitialized = true;
1895
+ };
1896
+ _self.teardown = function (unloadCtx, unloadState) {
1897
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1898
+ return;
1899
+ }
1900
+ var result;
1901
+ var unloadDone = false;
1902
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1903
+ var theUnloadState = unloadState || {
1904
+ reason: 0 ,
1905
+ isAsync: false
1906
+ };
1907
+ function _unloadCallback() {
1908
+ if (!unloadDone) {
1909
+ unloadDone = true;
1910
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1911
+ arrForEach(_hooks, function (fn) {
1912
+ fn.rm();
1913
+ });
1914
+ _hooks = [];
1915
+ if (result === true) {
1916
+ theUnloadCtx.processNext(theUnloadState);
1917
+ }
1918
+ _initDefaults();
1919
+ }
1920
+ }
1921
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1922
+ _unloadCallback();
1923
+ }
1924
+ else {
1925
+ result = true;
1926
+ }
1927
+ return result;
1928
+ };
1929
+ _self.update = function (updateCtx, updateState) {
1930
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
1931
+ return;
1932
+ }
1933
+ var result;
1934
+ var updateDone = false;
1935
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1936
+ var theUpdateState = updateState || {
1937
+ reason: 0
1938
+ };
1939
+ function _updateCallback() {
1940
+ if (!updateDone) {
1941
+ updateDone = true;
1942
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1943
+ }
1944
+ }
1945
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1946
+ _updateCallback();
1947
+ }
1948
+ else {
1949
+ result = true;
1950
+ }
1951
+ return result;
1952
+ };
1953
+ _self._addHook = function (hooks) {
1954
+ if (hooks) {
1955
+ if (isArray(hooks)) {
1956
+ _hooks = _hooks.concat(hooks);
1957
+ }
1958
+ else {
1959
+ _hooks.push(hooks);
1960
+ }
1961
+ }
1962
+ };
1963
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1964
+ });
1965
+ _self.diagLog = function (itemCtx) {
1966
+ return _getTelCtx(itemCtx).diagLog();
1967
+ };
1968
+ _self[strIsInitialized] = function () {
1969
+ return _isinitialized;
1970
+ };
1971
+ _self.setInitialized = function (isInitialized) {
1972
+ _isinitialized = isInitialized;
1973
+ };
1974
+ _self[strSetNextPlugin] = function (next) {
1975
+ _nextPlugin = next;
1976
+ };
1977
+ _self.processNext = function (env, itemCtx) {
1978
+ if (itemCtx) {
1979
+ itemCtx.processNext(env);
1980
+ }
1981
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1982
+ _nextPlugin.processTelemetry(env, null);
1983
+ }
1984
+ };
1985
+ _self._getTelCtx = _getTelCtx;
1986
+ function _getTelCtx(currentCtx) {
1987
+ if (currentCtx === void 0) { currentCtx = null; }
1988
+ var itemCtx = currentCtx;
1989
+ if (!itemCtx) {
1990
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1991
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1992
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1993
+ }
1994
+ else {
1995
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
1996
+ }
1997
+ }
1998
+ return itemCtx;
1999
+ }
2000
+ function _setDefaults(config, core, pluginChain) {
2001
+ if (config) {
2002
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2003
+ }
2004
+ if (!pluginChain && core) {
2005
+ pluginChain = core.getProcessTelContext().getNext();
2006
+ }
2007
+ var nextPlugin = _nextPlugin;
2008
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2009
+ nextPlugin = _nextPlugin[strGetPlugin]();
2010
+ }
2011
+ _self.core = core;
2012
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
2013
+ }
2014
+ function _initDefaults() {
2015
+ _isinitialized = false;
2016
+ _self.core = null;
2017
+ _rootCtx = null;
2018
+ _nextPlugin = null;
2019
+ _hooks = [];
2020
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2021
+ }
2022
+ }
2023
+ return BaseTelemetryPlugin;
2024
+ }());
2025
+
2026
+ var strOnPrefix = "on";
2027
+ var strAttachEvent = "attachEvent";
2028
+ var strAddEventHelper = "addEventListener";
2029
+ var strDetachEvent = "detachEvent";
2030
+ var strRemoveEventListener = "removeEventListener";
2031
+ var strEvents = "events";
2032
+ createUniqueNamespace("aiEvtPageHide");
2033
+ createUniqueNamespace("aiEvtPageShow");
2034
+ var rRemoveEmptyNs = /\.[\.]+/g;
2035
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
2036
+ var _guid = 1;
2037
+ var elmNodeData = createElmNodeData("events");
2038
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
2039
+ function _normalizeNamespace(name) {
2040
+ if (name && name.replace) {
2041
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
2042
+ }
2043
+ return name;
2044
+ }
2045
+ function _getEvtNamespace(eventName, evtNamespace) {
2046
+ if (evtNamespace) {
2047
+ var theNamespace_1 = "";
2048
+ if (isArray(evtNamespace)) {
2049
+ theNamespace_1 = "";
2050
+ arrForEach(evtNamespace, function (name) {
2051
+ name = _normalizeNamespace(name);
2052
+ if (name) {
2053
+ if (name[0] !== ".") {
2054
+ name = "." + name;
2055
+ }
2056
+ theNamespace_1 += name;
2057
+ }
2058
+ });
2059
+ }
2060
+ else {
2061
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
2062
+ }
2063
+ if (theNamespace_1) {
2064
+ if (theNamespace_1[0] !== ".") {
2065
+ theNamespace_1 = "." + theNamespace_1;
2066
+ }
2067
+ eventName = (eventName || "") + theNamespace_1;
2068
+ }
2069
+ }
2070
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
2071
+ return {
2072
+ type: parsedEvent[1],
2073
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
2074
+ };
2075
+ }
2076
+ function _getRegisteredEvents(target, evtName, addDefault) {
2077
+ if (addDefault === void 0) { addDefault = true; }
2078
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
2079
+ var registeredEvents = aiEvts[evtName];
2080
+ if (!registeredEvents) {
2081
+ registeredEvents = aiEvts[evtName] = [];
2082
+ }
2083
+ return registeredEvents;
2084
+ }
2085
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
2086
+ if (obj && evtName && evtName.type) {
2087
+ if (obj[strRemoveEventListener]) {
2088
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
2089
+ }
2090
+ else if (obj[strDetachEvent]) {
2091
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
2092
+ }
2093
+ }
2094
+ }
2095
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
2096
+ var result = false;
2097
+ if (obj && evtName && evtName.type && handlerRef) {
2098
+ if (obj[strAddEventHelper]) {
2099
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
2100
+ result = true;
2101
+ }
2102
+ else if (obj[strAttachEvent]) {
2103
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
2104
+ result = true;
2105
+ }
2106
+ }
2107
+ return result;
1509
2108
  }
1510
-
1511
- var UInt32Mask = 0x100000000;
1512
- var MaxUInt32 = 0xffffffff;
1513
- var _mwcSeeded = false;
1514
- var _mwcW = 123456789;
1515
- var _mwcZ = 987654321;
1516
- function _mwcSeed(seedValue) {
1517
- if (seedValue < 0) {
1518
- seedValue >>>= 0;
2109
+ function _doUnregister(target, events, evtName, unRegFn) {
2110
+ var idx = events.length;
2111
+ while (idx--) {
2112
+ var theEvent = events[idx];
2113
+ if (theEvent) {
2114
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
2115
+ if (!unRegFn || unRegFn(theEvent)) {
2116
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
2117
+ events.splice(idx, 1);
2118
+ }
2119
+ }
2120
+ }
1519
2121
  }
1520
- _mwcW = (123456789 + seedValue) & MaxUInt32;
1521
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
1522
- _mwcSeeded = true;
1523
2122
  }
1524
- function _autoSeedMwc() {
1525
- try {
1526
- var now = dateNow() & 0x7fffffff;
1527
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2123
+ function _unregisterEvents(target, evtName, unRegFn) {
2124
+ if (evtName.type) {
2125
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1528
2126
  }
1529
- catch (e) {
2127
+ else {
2128
+ var eventCache = elmNodeData.get(target, strEvents, {});
2129
+ objForEachKey(eventCache, function (evtType, events) {
2130
+ _doUnregister(target, events, evtName, unRegFn);
2131
+ });
2132
+ if (objKeys(eventCache).length === 0) {
2133
+ elmNodeData.kill(target, strEvents);
2134
+ }
1530
2135
  }
1531
2136
  }
1532
- function random32(signed) {
1533
- var value;
1534
- var c = getCrypto() || getMsCrypto();
1535
- if (c && c.getRandomValues) {
1536
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1537
- }
1538
- else if (isIE()) {
1539
- if (!_mwcSeeded) {
1540
- _autoSeedMwc();
2137
+ function mergeEvtNamespace(theNamespace, namespaces) {
2138
+ var newNamespaces;
2139
+ if (namespaces) {
2140
+ if (isArray(namespaces)) {
2141
+ newNamespaces = [theNamespace].concat(namespaces);
1541
2142
  }
1542
- value = mwcRandom32() & MaxUInt32;
2143
+ else {
2144
+ newNamespaces = [theNamespace, namespaces];
2145
+ }
2146
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1543
2147
  }
1544
2148
  else {
1545
- value = Math.floor((UInt32Mask * Math.random()) | 0);
2149
+ newNamespaces = theNamespace;
1546
2150
  }
1547
- if (!signed) {
1548
- value >>>= 0;
2151
+ return newNamespaces;
2152
+ }
2153
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
2154
+ if (useCapture === void 0) { useCapture = false; }
2155
+ var result = false;
2156
+ if (target) {
2157
+ try {
2158
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
2159
+ result = _doAttach(target, evtName, handlerRef, useCapture);
2160
+ if (result && elmNodeData.accept(target)) {
2161
+ var registeredEvent = {
2162
+ guid: _guid++,
2163
+ evtName: evtName,
2164
+ handler: handlerRef,
2165
+ capture: useCapture
2166
+ };
2167
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
2168
+ }
2169
+ }
2170
+ catch (e) {
2171
+ }
1549
2172
  }
1550
- return value;
2173
+ return result;
1551
2174
  }
1552
- function mwcRandom32(signed) {
1553
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1554
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1555
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1556
- if (!signed) {
1557
- value >>>= 0;
2175
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
2176
+ if (useCapture === void 0) { useCapture = false; }
2177
+ if (target) {
2178
+ try {
2179
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
2180
+ var found_1 = false;
2181
+ _unregisterEvents(target, evtName_1, function (regEvent) {
2182
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
2183
+ found_1 = true;
2184
+ return true;
2185
+ }
2186
+ return false;
2187
+ });
2188
+ if (!found_1) {
2189
+ _doDetach(target, evtName_1, handlerRef, useCapture);
2190
+ }
2191
+ }
2192
+ catch (e) {
2193
+ }
1558
2194
  }
1559
- return value;
1560
2195
  }
1561
2196
 
1562
2197
  function generateW3CId() {
1563
2198
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1564
- var oct = "", tmp;
2199
+ var oct = strEmpty$1, tmp;
1565
2200
  for (var a = 0; a < 4; a++) {
1566
2201
  tmp = random32();
1567
2202
  oct +=
@@ -1578,6 +2213,232 @@
1578
2213
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1579
2214
  }
1580
2215
 
2216
+ var LoggingSeverity = createEnumStyle({
2217
+ CRITICAL: 1 ,
2218
+ WARNING: 2
2219
+ });
2220
+ var _InternalMessageId = createEnumStyle({
2221
+ BrowserDoesNotSupportLocalStorage: 0 ,
2222
+ BrowserCannotReadLocalStorage: 1 ,
2223
+ BrowserCannotReadSessionStorage: 2 ,
2224
+ BrowserCannotWriteLocalStorage: 3 ,
2225
+ BrowserCannotWriteSessionStorage: 4 ,
2226
+ BrowserFailedRemovalFromLocalStorage: 5 ,
2227
+ BrowserFailedRemovalFromSessionStorage: 6 ,
2228
+ CannotSendEmptyTelemetry: 7 ,
2229
+ ClientPerformanceMathError: 8 ,
2230
+ ErrorParsingAISessionCookie: 9 ,
2231
+ ErrorPVCalc: 10 ,
2232
+ ExceptionWhileLoggingError: 11 ,
2233
+ FailedAddingTelemetryToBuffer: 12 ,
2234
+ FailedMonitorAjaxAbort: 13 ,
2235
+ FailedMonitorAjaxDur: 14 ,
2236
+ FailedMonitorAjaxOpen: 15 ,
2237
+ FailedMonitorAjaxRSC: 16 ,
2238
+ FailedMonitorAjaxSend: 17 ,
2239
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
2240
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
2241
+ FailedToSendQueuedTelemetry: 20 ,
2242
+ FailedToReportDataLoss: 21 ,
2243
+ FlushFailed: 22 ,
2244
+ MessageLimitPerPVExceeded: 23 ,
2245
+ MissingRequiredFieldSpecification: 24 ,
2246
+ NavigationTimingNotSupported: 25 ,
2247
+ OnError: 26 ,
2248
+ SessionRenewalDateIsZero: 27 ,
2249
+ SenderNotInitialized: 28 ,
2250
+ StartTrackEventFailed: 29 ,
2251
+ StopTrackEventFailed: 30 ,
2252
+ StartTrackFailed: 31 ,
2253
+ StopTrackFailed: 32 ,
2254
+ TelemetrySampledAndNotSent: 33 ,
2255
+ TrackEventFailed: 34 ,
2256
+ TrackExceptionFailed: 35 ,
2257
+ TrackMetricFailed: 36 ,
2258
+ TrackPVFailed: 37 ,
2259
+ TrackPVFailedCalc: 38 ,
2260
+ TrackTraceFailed: 39 ,
2261
+ TransmissionFailed: 40 ,
2262
+ FailedToSetStorageBuffer: 41 ,
2263
+ FailedToRestoreStorageBuffer: 42 ,
2264
+ InvalidBackendResponse: 43 ,
2265
+ FailedToFixDepricatedValues: 44 ,
2266
+ InvalidDurationValue: 45 ,
2267
+ TelemetryEnvelopeInvalid: 46 ,
2268
+ CreateEnvelopeError: 47 ,
2269
+ CannotSerializeObject: 48 ,
2270
+ CannotSerializeObjectNonSerializable: 49 ,
2271
+ CircularReferenceDetected: 50 ,
2272
+ ClearAuthContextFailed: 51 ,
2273
+ ExceptionTruncated: 52 ,
2274
+ IllegalCharsInName: 53 ,
2275
+ ItemNotInArray: 54 ,
2276
+ MaxAjaxPerPVExceeded: 55 ,
2277
+ MessageTruncated: 56 ,
2278
+ NameTooLong: 57 ,
2279
+ SampleRateOutOfRange: 58 ,
2280
+ SetAuthContextFailed: 59 ,
2281
+ SetAuthContextFailedAccountName: 60 ,
2282
+ StringValueTooLong: 61 ,
2283
+ StartCalledMoreThanOnce: 62 ,
2284
+ StopCalledWithoutStart: 63 ,
2285
+ TelemetryInitializerFailed: 64 ,
2286
+ TrackArgumentsNotSpecified: 65 ,
2287
+ UrlTooLong: 66 ,
2288
+ SessionStorageBufferFull: 67 ,
2289
+ CannotAccessCookie: 68 ,
2290
+ IdTooLong: 69 ,
2291
+ InvalidEvent: 70 ,
2292
+ FailedMonitorAjaxSetRequestHeader: 71 ,
2293
+ SendBrowserInfoOnUserInit: 72 ,
2294
+ PluginException: 73 ,
2295
+ NotificationException: 74 ,
2296
+ SnippetScriptLoadFailure: 99 ,
2297
+ InvalidInstrumentationKey: 100 ,
2298
+ CannotParseAiBlobValue: 101 ,
2299
+ InvalidContentBlob: 102 ,
2300
+ TrackPageActionEventFailed: 103 ,
2301
+ FailedAddingCustomDefinedRequestContext: 104 ,
2302
+ InMemoryStorageBufferFull: 105
2303
+ });
2304
+
2305
+ var aiInstrumentHooks = "_aiHooks";
2306
+ var cbNames = [
2307
+ "req", "rsp", "hkErr", "fnErr"
2308
+ ];
2309
+ function _arrLoop(arr, fn) {
2310
+ if (arr) {
2311
+ for (var lp = 0; lp < arr.length; lp++) {
2312
+ if (fn(arr[lp], lp)) {
2313
+ break;
2314
+ }
2315
+ }
2316
+ }
2317
+ }
2318
+ function _doCallbacks(hooks, callDetails, cbArgs, hookCtx, type) {
2319
+ if (type >= 0 && type <= 2 ) {
2320
+ _arrLoop(hooks, function (hook, idx) {
2321
+ var cbks = hook.cbks;
2322
+ var cb = cbks[cbNames[type]];
2323
+ if (cb) {
2324
+ callDetails.ctx = function () {
2325
+ var ctx = hookCtx[idx] = (hookCtx[idx] || {});
2326
+ return ctx;
2327
+ };
2328
+ try {
2329
+ cb.apply(callDetails.inst, cbArgs);
2330
+ }
2331
+ catch (err) {
2332
+ var orgEx = callDetails.err;
2333
+ try {
2334
+ var hookErrorCb = cbks[cbNames[2 ]];
2335
+ if (hookErrorCb) {
2336
+ callDetails.err = err;
2337
+ hookErrorCb.apply(callDetails.inst, cbArgs);
2338
+ }
2339
+ }
2340
+ catch (e) {
2341
+ }
2342
+ finally {
2343
+ callDetails.err = orgEx;
2344
+ }
2345
+ }
2346
+ }
2347
+ });
2348
+ }
2349
+ }
2350
+ function _createFunctionHook(aiHook) {
2351
+ return function () {
2352
+ var funcThis = this;
2353
+ var orgArgs = arguments;
2354
+ var hooks = aiHook.h;
2355
+ var funcArgs = {
2356
+ name: aiHook.n,
2357
+ inst: funcThis,
2358
+ ctx: null,
2359
+ set: _replaceArg
2360
+ };
2361
+ var hookCtx = [];
2362
+ var cbArgs = _createArgs([funcArgs], orgArgs);
2363
+ funcArgs.evt = getGlobalInst("event");
2364
+ function _createArgs(target, theArgs) {
2365
+ _arrLoop(theArgs, function (arg) {
2366
+ target.push(arg);
2367
+ });
2368
+ return target;
2369
+ }
2370
+ function _replaceArg(idx, value) {
2371
+ orgArgs = _createArgs([], orgArgs);
2372
+ orgArgs[idx] = value;
2373
+ cbArgs = _createArgs([funcArgs], orgArgs);
2374
+ }
2375
+ _doCallbacks(hooks, funcArgs, cbArgs, hookCtx, 0 );
2376
+ var theFunc = aiHook.f;
2377
+ try {
2378
+ funcArgs.rslt = theFunc.apply(funcThis, orgArgs);
2379
+ }
2380
+ catch (err) {
2381
+ funcArgs.err = err;
2382
+ _doCallbacks(hooks, funcArgs, cbArgs, hookCtx, 3 );
2383
+ throw err;
2384
+ }
2385
+ _doCallbacks(hooks, funcArgs, cbArgs, hookCtx, 1 );
2386
+ return funcArgs.rslt;
2387
+ };
2388
+ }
2389
+ function _getOwner(target, name, checkPrototype) {
2390
+ var owner = null;
2391
+ if (target) {
2392
+ if (hasOwnProperty(target, name)) {
2393
+ owner = target;
2394
+ }
2395
+ else if (checkPrototype) {
2396
+ owner = _getOwner(_getObjProto(target), name, false);
2397
+ }
2398
+ }
2399
+ return owner;
2400
+ }
2401
+ function InstrumentFunc(target, funcName, callbacks, checkPrototype) {
2402
+ if (checkPrototype === void 0) { checkPrototype = true; }
2403
+ if (target && funcName && callbacks) {
2404
+ var owner = _getOwner(target, funcName, checkPrototype);
2405
+ if (owner) {
2406
+ var fn = owner[funcName];
2407
+ if (typeof fn === strShimFunction) {
2408
+ var aiHook_1 = fn[aiInstrumentHooks];
2409
+ if (!aiHook_1) {
2410
+ aiHook_1 = {
2411
+ i: 0,
2412
+ n: funcName,
2413
+ f: fn,
2414
+ h: []
2415
+ };
2416
+ var newFunc = _createFunctionHook(aiHook_1);
2417
+ newFunc[aiInstrumentHooks] = aiHook_1;
2418
+ owner[funcName] = newFunc;
2419
+ }
2420
+ var theHook = {
2421
+ id: aiHook_1.i,
2422
+ cbks: callbacks,
2423
+ rm: function () {
2424
+ var id = this.id;
2425
+ _arrLoop(aiHook_1.h, function (hook, idx) {
2426
+ if (hook.id === id) {
2427
+ aiHook_1.h.splice(idx, 1);
2428
+ return 1;
2429
+ }
2430
+ });
2431
+ }
2432
+ };
2433
+ aiHook_1.i++;
2434
+ aiHook_1.h.push(theHook);
2435
+ return theHook;
2436
+ }
2437
+ }
2438
+ }
2439
+ return null;
2440
+ }
2441
+
1581
2442
  function dataSanitizeKeyAndAddUniqueness(logger, key, map) {
1582
2443
  var origLength = key.length;
1583
2444
  var field = dataSanitizeKey(logger, key);
@@ -1598,7 +2459,7 @@
1598
2459
  name = strTrim(name.toString());
1599
2460
  if (name.length > 150 ) {
1600
2461
  nameTrunc = name.substring(0, 150 );
1601
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2462
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1602
2463
  }
1603
2464
  }
1604
2465
  return nameTrunc || name;
@@ -1611,7 +2472,7 @@
1611
2472
  value = strTrim(value);
1612
2473
  if (value.toString().length > maxLength) {
1613
2474
  valueTrunc = value.toString().substring(0, maxLength);
1614
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2475
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1615
2476
  }
1616
2477
  }
1617
2478
  return valueTrunc || value;
@@ -1624,7 +2485,7 @@
1624
2485
  if (message) {
1625
2486
  if (message.length > 32768 ) {
1626
2487
  messageTrunc = message.substring(0, 32768 );
1627
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
2488
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
1628
2489
  }
1629
2490
  }
1630
2491
  return messageTrunc || message;
@@ -1635,7 +2496,7 @@
1635
2496
  var value = "" + exception;
1636
2497
  if (value.length > 32768 ) {
1637
2498
  exceptionTrunc = value.substring(0, 32768 );
1638
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
2499
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
1639
2500
  }
1640
2501
  }
1641
2502
  return exceptionTrunc || exception;
@@ -1649,7 +2510,7 @@
1649
2510
  value = getJSON().stringify(value);
1650
2511
  }
1651
2512
  catch (e) {
1652
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2513
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1653
2514
  }
1654
2515
  }
1655
2516
  value = dataSanitizeString(logger, value, 8192 );
@@ -1680,7 +2541,7 @@
1680
2541
  input = strTrim(input);
1681
2542
  if (input.length > maxLength) {
1682
2543
  inputTrunc = input.substring(0, maxLength);
1683
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2544
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1684
2545
  }
1685
2546
  }
1686
2547
  return inputTrunc || input;
@@ -1705,6 +2566,7 @@
1705
2566
  return event;
1706
2567
  }
1707
2568
 
2569
+ var strEmpty = "";
1708
2570
  function stringToBoolOrDefault(str, defaultValue) {
1709
2571
  if (defaultValue === void 0) { defaultValue = false; }
1710
2572
  if (str === undefined || str === null) {
@@ -1717,16 +2579,16 @@
1717
2579
  totalms = 0;
1718
2580
  }
1719
2581
  totalms = Math.round(totalms);
1720
- var ms = "" + totalms % 1000;
1721
- var sec = "" + Math.floor(totalms / 1000) % 60;
1722
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1723
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2582
+ var ms = strEmpty + totalms % 1000;
2583
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2584
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2585
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1724
2586
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
1725
2587
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
1726
2588
  sec = sec.length < 2 ? "0" + sec : sec;
1727
2589
  min = min.length < 2 ? "0" + min : min;
1728
2590
  hour = hour.length < 2 ? "0" + hour : hour;
1729
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2591
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1730
2592
  }
1731
2593
  function isCrossOriginError(message, url, lineNumber, columnNumber, error) {
1732
2594
  return !error && isString(message) && (message === "Script error." || message === "Script error");
@@ -1735,18 +2597,17 @@
1735
2597
  var strNotSpecified = "not_specified";
1736
2598
  var strIkey = "iKey";
1737
2599
 
1738
- var StorageType;
1739
- (function (StorageType) {
1740
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1741
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1742
- })(StorageType || (StorageType = {}));
1743
- var DistributedTracingModes;
1744
- (function (DistributedTracingModes) {
1745
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1746
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1747
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1748
- })(DistributedTracingModes || (DistributedTracingModes = {}));
2600
+ var StorageType = createEnumStyle({
2601
+ LocalStorage: 0 ,
2602
+ SessionStorage: 1
2603
+ });
2604
+ createEnumStyle({
2605
+ AI: 0 ,
2606
+ AI_AND_W3C: 1 ,
2607
+ W3C: 2
2608
+ });
1749
2609
 
2610
+ var _canUseLocalStorage = undefined;
1750
2611
  var _canUseSessionStorage = undefined;
1751
2612
  function _getVerifiedStorageObject(storageType) {
1752
2613
  try {
@@ -1773,10 +2634,21 @@
1773
2634
  return null;
1774
2635
  }
1775
2636
  function utlDisableStorage() {
2637
+ _canUseLocalStorage = false;
1776
2638
  _canUseSessionStorage = false;
1777
2639
  }
1778
- function utlCanUseSessionStorage() {
1779
- if (_canUseSessionStorage === undefined) {
2640
+ function utlEnableStorage() {
2641
+ _canUseLocalStorage = utlCanUseLocalStorage(true);
2642
+ _canUseSessionStorage = utlCanUseSessionStorage(true);
2643
+ }
2644
+ function utlCanUseLocalStorage(reset) {
2645
+ if (reset || _canUseLocalStorage === undefined) {
2646
+ _canUseLocalStorage = !!_getVerifiedStorageObject(StorageType.LocalStorage);
2647
+ }
2648
+ return _canUseLocalStorage;
2649
+ }
2650
+ function utlCanUseSessionStorage(reset) {
2651
+ if (reset || _canUseSessionStorage === undefined) {
1780
2652
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
1781
2653
  }
1782
2654
  return _canUseSessionStorage;
@@ -1789,7 +2661,7 @@
1789
2661
  }
1790
2662
  catch (e) {
1791
2663
  _canUseSessionStorage = false;
1792
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2664
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
1793
2665
  }
1794
2666
  }
1795
2667
  return null;
@@ -1803,7 +2675,7 @@
1803
2675
  }
1804
2676
  catch (e) {
1805
2677
  _canUseSessionStorage = false;
1806
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2678
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
1807
2679
  }
1808
2680
  }
1809
2681
  return false;
@@ -1817,7 +2689,7 @@
1817
2689
  }
1818
2690
  catch (e) {
1819
2691
  _canUseSessionStorage = false;
1820
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
2692
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
1821
2693
  }
1822
2694
  }
1823
2695
  return false;
@@ -2729,11 +3601,9 @@
2729
3601
  if (core) {
2730
3602
  _logger = core.logger;
2731
3603
  }
2732
- function _flushChannels() {
3604
+ function _flushChannels(isAsync) {
2733
3605
  if (core) {
2734
- arrForEach(core.getTransmissionControls(), function (queues) {
2735
- arrForEach(queues, function (q) { return q.flush(true); });
2736
- });
3606
+ core.flush(isAsync);
2737
3607
  }
2738
3608
  }
2739
3609
  function _addQueue(cb) {
@@ -2756,7 +3626,7 @@
2756
3626
  intervalHandle = null;
2757
3627
  }
2758
3628
  if (doFlush) {
2759
- _flushChannels();
3629
+ _flushChannels(true);
2760
3630
  }
2761
3631
  }), 100);
2762
3632
  }
@@ -2774,7 +3644,7 @@
2774
3644
  }
2775
3645
  if (!pageViewPerformanceManager.isPerformanceTimingSupported()) {
2776
3646
  appInsights.sendPageViewInternal(pageView, customProperties);
2777
- _flushChannels();
3647
+ _flushChannels(true);
2778
3648
  _logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NavigationTimingNotSupported, "trackPageView: navigation timing API used for calculation of page duration is not supported in this browser. This page view will be collected without duration and timing info.");
2779
3649
  return;
2780
3650
  }
@@ -2800,7 +3670,7 @@
2800
3670
  customProperties["duration"] = customDuration;
2801
3671
  }
2802
3672
  appInsights.sendPageViewInternal(pageView, customProperties);
2803
- _flushChannels();
3673
+ _flushChannels(true);
2804
3674
  pageViewSent = true;
2805
3675
  }
2806
3676
  var maxDurationLimit = 60000;
@@ -2846,6 +3716,17 @@
2846
3716
  return processed;
2847
3717
  });
2848
3718
  };
3719
+ _self.teardown = function (unloadCtx, unloadState) {
3720
+ if (intervalHandle) {
3721
+ clearInterval(intervalHandle);
3722
+ intervalHandle = null;
3723
+ var allItems = itemQueue.slice(0);
3724
+ itemQueue = [];
3725
+ arrForEach(allItems, function (item) {
3726
+ if (item()) ;
3727
+ });
3728
+ }
3729
+ };
2849
3730
  });
2850
3731
  }
2851
3732
  return PageViewManager;
@@ -3040,6 +3921,33 @@
3040
3921
  return PageViewPerformanceManager;
3041
3922
  }());
3042
3923
 
3924
+ var Timing = /** @class */ (function () {
3925
+ function Timing(logger, name) {
3926
+ var _self = this;
3927
+ var _events = {};
3928
+ _self.start = function (name) {
3929
+ if (typeof _events[name] !== "undefined") {
3930
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
3931
+ }
3932
+ _events[name] = +new Date;
3933
+ };
3934
+ _self.stop = function (name, url, properties, measurements) {
3935
+ var start = _events[name];
3936
+ if (isNaN(start)) {
3937
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
3938
+ }
3939
+ else {
3940
+ var end = +new Date;
3941
+ var duration = dateTimeUtilsDuration(start, end);
3942
+ _self.action(name, url, duration, properties, measurements);
3943
+ }
3944
+ delete _events[name];
3945
+ _events[name] = undefined;
3946
+ };
3947
+ }
3948
+ return Timing;
3949
+ }());
3950
+
3043
3951
  var durationProperty = "duration";
3044
3952
  var strEvent = "event";
3045
3953
  function _dispatchEvent(target, evnt) {
@@ -3057,47 +3965,78 @@
3057
3965
  }
3058
3966
  return error || "";
3059
3967
  }
3060
- var ApplicationInsights = /** @class */ (function (_super) {
3061
- __extendsFn(ApplicationInsights, _super);
3062
- function ApplicationInsights() {
3968
+ var MinMilliSeconds = 60000;
3969
+ function _configMilliseconds(value, defValue) {
3970
+ value = value || defValue;
3971
+ if (value < MinMilliSeconds) {
3972
+ value = MinMilliSeconds;
3973
+ }
3974
+ return value;
3975
+ }
3976
+ function _getDefaultConfig(config) {
3977
+ if (!config) {
3978
+ config = {};
3979
+ }
3980
+ config.sessionRenewalMs = _configMilliseconds(config.sessionRenewalMs, 30 * 60 * 1000);
3981
+ config.sessionExpirationMs = _configMilliseconds(config.sessionExpirationMs, 24 * 60 * 60 * 1000);
3982
+ config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
3983
+ config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
3984
+ config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
3985
+ config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
3986
+ if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
3987
+ config.samplingPercentage = 100;
3988
+ }
3989
+ config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
3990
+ config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
3991
+ config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
3992
+ config.namePrefix = config.namePrefix || "";
3993
+ config.enableDebug = stringToBoolOrDefault(config.enableDebug);
3994
+ config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
3995
+ config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
3996
+ return config;
3997
+ }
3998
+ function _updateStorageUsage(extConfig) {
3999
+ if (!isUndefined(extConfig.isStorageUseDisabled)) {
4000
+ if (extConfig.isStorageUseDisabled) {
4001
+ utlDisableStorage();
4002
+ }
4003
+ else {
4004
+ utlEnableStorage();
4005
+ }
4006
+ }
4007
+ }
4008
+ var AnalyticsPlugin = /** @class */ (function (_super) {
4009
+ __extendsFn(AnalyticsPlugin, _super);
4010
+ function AnalyticsPlugin() {
3063
4011
  var _this = _super.call(this) || this;
3064
4012
  _this.identifier = AnalyticsPluginIdentifier;
3065
4013
  _this.priority = 180;
3066
4014
  _this.autoRoutePVDelay = 500;
3067
4015
  var _eventTracking;
3068
4016
  var _pageTracking;
3069
- var _properties;
4017
+ var _pageViewManager;
4018
+ var _pageViewPerformanceManager;
4019
+ var _pageVisitTimeManager;
4020
+ var _preInitTelemetryInitializers;
4021
+ var _isBrowserLinkTrackingEnabled;
4022
+ var _browserLinkInitializerAdded;
4023
+ var _enableAutoRouteTracking;
4024
+ var _historyListenerAdded;
4025
+ var _disableExceptionTracking;
4026
+ var _autoExceptionInstrumented;
4027
+ var _enableUnhandledPromiseRejectionTracking;
4028
+ var _autoUnhandledPromiseInstrumented;
3070
4029
  var _prevUri;
3071
4030
  var _currUri;
3072
- dynamicProto(ApplicationInsights, _this, function (_self, _base) {
3073
- var location = getLocation(true);
3074
- _prevUri = location && location.href || "";
4031
+ var _evtNamespace;
4032
+ dynamicProto(AnalyticsPlugin, _this, function (_self, _base) {
4033
+ var _addHook = _base._addHook;
4034
+ _initDefaults();
3075
4035
  _self.getCookieMgr = function () {
3076
4036
  return safeGetCookieMgr(_self.core);
3077
4037
  };
3078
4038
  _self.processTelemetry = function (env, itemCtx) {
3079
- doPerf(_self.core, function () { return _self.identifier + ":processTelemetry"; }, function () {
3080
- var doNotSendItem = false;
3081
- var telemetryInitializersCount = _self._telemetryInitializers.length;
3082
- itemCtx = _self._getTelCtx(itemCtx);
3083
- for (var i = 0; i < telemetryInitializersCount; ++i) {
3084
- var telemetryInitializer = _self._telemetryInitializers[i];
3085
- if (telemetryInitializer) {
3086
- try {
3087
- if (telemetryInitializer.apply(null, [env]) === false) {
3088
- doNotSendItem = true;
3089
- break;
3090
- }
3091
- }
3092
- catch (e) {
3093
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
3094
- }
3095
- }
3096
- }
3097
- if (!doNotSendItem) {
3098
- _self.processNext(env, itemCtx);
3099
- }
3100
- }, function () { return ({ item: env }); }, !(env.sync));
4039
+ _self.processNext(env, itemCtx);
3101
4040
  };
3102
4041
  _self.trackEvent = function (event, customProperties) {
3103
4042
  try {
@@ -3105,7 +4044,7 @@
3105
4044
  _self.core.track(telemetryItem);
3106
4045
  }
3107
4046
  catch (e) {
3108
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4047
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3109
4048
  }
3110
4049
  };
3111
4050
  _self.startTrackEvent = function (name) {
@@ -3113,7 +4052,7 @@
3113
4052
  _eventTracking.start(name);
3114
4053
  }
3115
4054
  catch (e) {
3116
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4055
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3117
4056
  }
3118
4057
  };
3119
4058
  _self.stopTrackEvent = function (name, properties, measurements) {
@@ -3121,7 +4060,7 @@
3121
4060
  _eventTracking.stop(name, undefined, properties);
3122
4061
  }
3123
4062
  catch (e) {
3124
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4063
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3125
4064
  }
3126
4065
  };
3127
4066
  _self.trackTrace = function (trace, customProperties) {
@@ -3130,7 +4069,7 @@
3130
4069
  _self.core.track(telemetryItem);
3131
4070
  }
3132
4071
  catch (e) {
3133
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4072
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3134
4073
  }
3135
4074
  };
3136
4075
  _self.trackMetric = function (metric, customProperties) {
@@ -3139,19 +4078,19 @@
3139
4078
  _self.core.track(telemetryItem);
3140
4079
  }
3141
4080
  catch (e) {
3142
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4081
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3143
4082
  }
3144
4083
  };
3145
4084
  _self.trackPageView = function (pageView, customProperties) {
3146
4085
  try {
3147
4086
  var inPv = pageView || {};
3148
- _self._pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
4087
+ _pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
3149
4088
  if (_self.config.autoTrackPageVisitTime) {
3150
- _self._pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
4089
+ _pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
3151
4090
  }
3152
4091
  }
3153
4092
  catch (e) {
3154
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4093
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3155
4094
  }
3156
4095
  };
3157
4096
  _self.sendPageViewInternal = function (pageView, properties, systemProperties) {
@@ -3167,12 +4106,13 @@
3167
4106
  _self.core.track(telemetryItem);
3168
4107
  };
3169
4108
  _self.trackPageViewPerformance = function (pageViewPerformance, customProperties) {
4109
+ var inPvp = pageViewPerformance || {};
3170
4110
  try {
3171
- _self._pageViewPerformanceManager.populatePageViewPerformanceEvent(pageViewPerformance);
3172
- _self.sendPageViewPerformanceInternal(pageViewPerformance, customProperties);
4111
+ _pageViewPerformanceManager.populatePageViewPerformanceEvent(inPvp);
4112
+ _self.sendPageViewPerformanceInternal(inPvp, customProperties);
3173
4113
  }
3174
4114
  catch (e) {
3175
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4115
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3176
4116
  }
3177
4117
  };
3178
4118
  _self.startTrackPage = function (name) {
@@ -3184,7 +4124,7 @@
3184
4124
  _pageTracking.start(name);
3185
4125
  }
3186
4126
  catch (e) {
3187
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4127
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3188
4128
  }
3189
4129
  };
3190
4130
  _self.stopTrackPage = function (name, url, properties, measurement) {
@@ -3199,11 +4139,11 @@
3199
4139
  }
3200
4140
  _pageTracking.stop(name, url, properties, measurement);
3201
4141
  if (_self.config.autoTrackPageVisitTime) {
3202
- _self._pageVisitTimeManager.trackPreviousPageVisit(name, url);
4142
+ _pageVisitTimeManager.trackPreviousPageVisit(name, url);
3203
4143
  }
3204
4144
  }
3205
4145
  catch (e) {
3206
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4146
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3207
4147
  }
3208
4148
  };
3209
4149
  _self.sendExceptionInternal = function (exception, customProperties, systemProperties) {
@@ -3213,11 +4153,14 @@
3213
4153
  _self.core.track(telemetryItem);
3214
4154
  };
3215
4155
  _self.trackException = function (exception, customProperties) {
4156
+ if (exception && !exception.exception && exception.error) {
4157
+ exception.exception = exception.error;
4158
+ }
3216
4159
  try {
3217
4160
  _self.sendExceptionInternal(exception, customProperties);
3218
4161
  }
3219
4162
  catch (e) {
3220
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4163
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3221
4164
  }
3222
4165
  };
3223
4166
  _self._onerror = function (exception) {
@@ -3251,158 +4194,98 @@
3251
4194
  }
3252
4195
  catch (e) {
3253
4196
  var errorString = error ? (error.name + ", " + error.message) : "null";
3254
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
4197
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
3255
4198
  + getExceptionName(e), { exception: dumpObj(e), errorString: errorString });
3256
4199
  }
3257
4200
  };
3258
4201
  _self.addTelemetryInitializer = function (telemetryInitializer) {
3259
- _self._telemetryInitializers.push(telemetryInitializer);
4202
+ if (_self.core) {
4203
+ return _self.core.addTelemetryInitializer(telemetryInitializer);
4204
+ }
4205
+ if (!_preInitTelemetryInitializers) {
4206
+ _preInitTelemetryInitializers = [];
4207
+ }
4208
+ _preInitTelemetryInitializers.push(telemetryInitializer);
3260
4209
  };
3261
4210
  _self.initialize = function (config, core, extensions, pluginChain) {
3262
4211
  if (_self.isInitialized()) {
3263
4212
  return;
3264
4213
  }
3265
4214
  if (isNullOrUndefined(core)) {
3266
- throw Error("Error initializing");
4215
+ throwError("Error initializing");
3267
4216
  }
3268
4217
  _base.initialize(config, core, extensions, pluginChain);
3269
- _self.setInitialized(false);
3270
- var ctx = _self._getTelCtx();
3271
- var identifier = _self.identifier;
3272
- _self.config = ctx.getExtCfg(identifier);
3273
- var defaults = ApplicationInsights.getDefaultConfig(config);
3274
- if (defaults !== undefined) {
3275
- objForEachKey(defaults, function (field, value) {
3276
- _self.config[field] = ctx.getConfig(identifier, field, value);
3277
- if (_self.config[field] === undefined) {
3278
- _self.config[field] = value;
3279
- }
3280
- });
3281
- }
3282
- if (_self.config.isStorageUseDisabled) {
3283
- utlDisableStorage();
3284
- }
3285
- var configGetters = {
3286
- instrumentationKey: function () { return config.instrumentationKey; },
3287
- accountId: function () { return _self.config.accountId || config.accountId; },
3288
- sessionRenewalMs: function () { return _self.config.sessionRenewalMs || config.sessionRenewalMs; },
3289
- sessionExpirationMs: function () { return _self.config.sessionExpirationMs || config.sessionExpirationMs; },
3290
- sampleRate: function () { return _self.config.samplingPercentage || config.samplingPercentage; },
3291
- sdkExtension: function () { return _self.config.sdkExtension || config.sdkExtension; },
3292
- isBrowserLinkTrackingEnabled: function () { return _self.config.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled; },
3293
- appId: function () { return _self.config.appId || config.appId; }
3294
- };
3295
- _self._pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
3296
- _self._pageViewManager = new PageViewManager(_this, _self.config.overridePageViewDuration, _self.core, _self._pageViewPerformanceManager);
3297
- _self._pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
3298
- _self._telemetryInitializers = _self._telemetryInitializers || [];
3299
- _addDefaultTelemetryInitializers(configGetters);
3300
- _eventTracking = new Timing(_self.diagLog(), "trackEvent");
3301
- _eventTracking.action =
3302
- function (name, url, duration, properties) {
3303
- if (!properties) {
4218
+ try {
4219
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
4220
+ if (_preInitTelemetryInitializers) {
4221
+ arrForEach(_preInitTelemetryInitializers, function (initializer) {
4222
+ core.addTelemetryInitializer(initializer);
4223
+ });
4224
+ _preInitTelemetryInitializers = null;
4225
+ }
4226
+ var extConfig = _populateDefaults(config);
4227
+ _updateStorageUsage(extConfig);
4228
+ _pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
4229
+ _pageViewManager = new PageViewManager(_this, extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
4230
+ _pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
4231
+ _updateBrowserLinkTracking(extConfig, config);
4232
+ _eventTracking = new Timing(_self.diagLog(), "trackEvent");
4233
+ _eventTracking.action =
4234
+ function (name, url, duration, properties) {
4235
+ if (!properties) {
4236
+ properties = {};
4237
+ }
4238
+ properties[durationProperty] = duration.toString();
4239
+ _self.trackEvent({ name: name, properties: properties });
4240
+ };
4241
+ _pageTracking = new Timing(_self.diagLog(), "trackPageView");
4242
+ _pageTracking.action = function (name, url, duration, properties, measurements) {
4243
+ if (isNullOrUndefined(properties)) {
3304
4244
  properties = {};
3305
4245
  }
3306
4246
  properties[durationProperty] = duration.toString();
3307
- _self.trackEvent({ name: name, properties: properties });
4247
+ var pageViewItem = {
4248
+ name: name,
4249
+ uri: url,
4250
+ properties: properties,
4251
+ measurements: measurements
4252
+ };
4253
+ _self.sendPageViewInternal(pageViewItem, properties);
3308
4254
  };
3309
- _pageTracking = new Timing(_self.diagLog(), "trackPageView");
3310
- _pageTracking.action = function (name, url, duration, properties, measurements) {
3311
- if (isNullOrUndefined(properties)) {
3312
- properties = {};
4255
+ if (hasWindow()) {
4256
+ _updateExceptionTracking(extConfig);
4257
+ _updateLocationChange(extConfig);
3313
4258
  }
3314
- properties[durationProperty] = duration.toString();
3315
- var pageViewItem = {
3316
- name: name,
3317
- uri: url,
3318
- properties: properties,
3319
- measurements: measurements
3320
- };
3321
- _self.sendPageViewInternal(pageViewItem, properties);
3322
- };
3323
- var _window = getWindow();
3324
- var _history = getHistory();
3325
- var _location = getLocation(true);
3326
- var instance = _this;
3327
- if (_self.config.disableExceptionTracking === false &&
3328
- !_self.config.autoExceptionInstrumented && _window) {
3329
- var onerror_1 = "onerror";
3330
- var originalOnError_1 = _window[onerror_1];
3331
- _window.onerror = function (message, url, lineNumber, columnNumber, error) {
3332
- var evt = _window[strEvent];
3333
- var handled = originalOnError_1 && originalOnError_1(message, url, lineNumber, columnNumber, error);
3334
- if (handled !== true) {
3335
- instance._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, evt));
3336
- }
3337
- return handled;
3338
- };
3339
- _self.config.autoExceptionInstrumented = true;
3340
- }
3341
- if (_self.config.disableExceptionTracking === false &&
3342
- _self.config.enableUnhandledPromiseRejectionTracking === true &&
3343
- !_self.config.autoUnhandledPromiseInstrumented && _window) {
3344
- var onunhandledrejection_1 = "onunhandledrejection";
3345
- var originalOnUnhandledRejection_1 = _window[onunhandledrejection_1];
3346
- _window[onunhandledrejection_1] = function (error) {
3347
- var evt = _window[strEvent];
3348
- var handled = originalOnUnhandledRejection_1 && originalOnUnhandledRejection_1.call(_window, error);
3349
- if (handled !== true) {
3350
- instance._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, evt));
3351
- }
3352
- return handled;
3353
- };
3354
- _self.config.autoUnhandledPromiseInstrumented = true;
3355
- }
3356
- if (_self.config.enableAutoRouteTracking === true
3357
- && _history && isFunction(_history.pushState) && isFunction(_history.replaceState)
3358
- && _window
3359
- && typeof Event !== "undefined") {
3360
- var _self_1 = _this;
3361
- arrForEach(extensions, function (extension) {
3362
- if (extension.identifier === PropertiesPluginIdentifier) {
3363
- _properties = extension;
4259
+ }
4260
+ catch (e) {
4261
+ _self.setInitialized(false);
4262
+ throw e;
4263
+ }
4264
+ };
4265
+ _self._doTeardown = function (unloadCtx, unloadState) {
4266
+ _pageViewManager && _pageViewManager.teardown(unloadCtx, unloadState);
4267
+ eventOff(window, null, null, _evtNamespace);
4268
+ _initDefaults();
4269
+ };
4270
+ function _populateDefaults(config) {
4271
+ var ctx = createProcessTelemetryContext(null, config, _self.core);
4272
+ var identifier = _self.identifier;
4273
+ var defaults = _getDefaultConfig(config);
4274
+ var extConfig = _self.config = ctx.getExtCfg(identifier);
4275
+ if (defaults !== undefined) {
4276
+ objForEachKey(defaults, function (field, value) {
4277
+ extConfig[field] = ctx.getConfig(identifier, field, value);
4278
+ if (extConfig[field] === undefined) {
4279
+ extConfig = value;
3364
4280
  }
3365
4281
  });
3366
- _history.pushState = (function (f) { return function pushState() {
3367
- var ret = f.apply(this, arguments);
3368
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "pushState"));
3369
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
3370
- return ret;
3371
- }; })(_history.pushState);
3372
- _history.replaceState = (function (f) { return function replaceState() {
3373
- var ret = f.apply(this, arguments);
3374
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "replaceState"));
3375
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
3376
- return ret;
3377
- }; })(_history.replaceState);
3378
- if (_window.addEventListener) {
3379
- _window.addEventListener(_self_1.config.namePrefix + "popstate", function () {
3380
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
3381
- });
3382
- _window.addEventListener(_self_1.config.namePrefix + "locationchange", function () {
3383
- if (_properties && _properties.context && _properties.context.telemetryTrace) {
3384
- _properties.context.telemetryTrace.traceID = generateW3CId();
3385
- var traceLocationName = "_unknown_";
3386
- if (_location && _location.pathname) {
3387
- traceLocationName = _location.pathname + (_location.hash || "");
3388
- }
3389
- _properties.context.telemetryTrace.name = dataSanitizeString(_self_1.diagLog(), traceLocationName);
3390
- }
3391
- if (_currUri) {
3392
- _prevUri = _currUri;
3393
- _currUri = _location && _location.href || "";
3394
- }
3395
- else {
3396
- _currUri = _location && _location.href || "";
3397
- }
3398
- setTimeout((function (uri) {
3399
- _self_1.trackPageView({ refUri: uri, properties: { duration: 0 } });
3400
- }).bind(_this, _prevUri), _self_1.autoRoutePVDelay);
3401
- });
3402
- }
3403
4282
  }
3404
- _self.setInitialized(true);
3405
- };
4283
+ return extConfig;
4284
+ }
4285
+ function _updateBrowserLinkTracking(extConfig, config) {
4286
+ _isBrowserLinkTrackingEnabled = extConfig.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled;
4287
+ _addDefaultTelemetryInitializers();
4288
+ }
3406
4289
  function trackPageVisitTime(pageName, pageUrl, pageVisitTime) {
3407
4290
  var properties = { PageName: pageName, PageUrl: pageUrl };
3408
4291
  _self.trackMetric({
@@ -3413,11 +4296,11 @@
3413
4296
  sampleCount: 1
3414
4297
  }, properties);
3415
4298
  }
3416
- function _addDefaultTelemetryInitializers(configGetters) {
3417
- if (!configGetters.isBrowserLinkTrackingEnabled()) {
4299
+ function _addDefaultTelemetryInitializers() {
4300
+ if (!_browserLinkInitializerAdded && _isBrowserLinkTrackingEnabled) {
3418
4301
  var browserLinkPaths_1 = ["/browserLinkSignalR/", "/__browserLink/"];
3419
4302
  var dropBrowserLinkRequests = function (envelope) {
3420
- if (envelope.baseType === RemoteDependencyData.dataType) {
4303
+ if (_isBrowserLinkTrackingEnabled && envelope.baseType === RemoteDependencyData.dataType) {
3421
4304
  var remoteData = envelope.baseData;
3422
4305
  if (remoteData) {
3423
4306
  for (var i = 0; i < browserLinkPaths_1.length; i++) {
@@ -3429,72 +4312,150 @@
3429
4312
  }
3430
4313
  return true;
3431
4314
  };
3432
- _addTelemetryInitializer(dropBrowserLinkRequests);
4315
+ _self.addTelemetryInitializer(dropBrowserLinkRequests);
4316
+ _browserLinkInitializerAdded = true;
3433
4317
  }
3434
4318
  }
3435
- function _addTelemetryInitializer(telemetryInitializer) {
3436
- _self._telemetryInitializers.push(telemetryInitializer);
3437
- }
3438
4319
  function _sendCORSException(exception, properties) {
3439
4320
  var telemetryItem = TelemetryItemCreator.create(exception, Exception.dataType, Exception.envelopeType, _self.diagLog(), properties);
3440
4321
  _self.core.track(telemetryItem);
3441
4322
  }
3442
- });
3443
- return _this;
3444
- }
3445
- ApplicationInsights.getDefaultConfig = function (config) {
3446
- if (!config) {
3447
- config = {};
3448
- }
3449
- config.sessionRenewalMs = 30 * 60 * 1000;
3450
- config.sessionExpirationMs = 24 * 60 * 60 * 1000;
3451
- config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
3452
- config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
3453
- config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
3454
- config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
3455
- if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
3456
- config.samplingPercentage = 100;
3457
- }
3458
- config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
3459
- config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
3460
- config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
3461
- config.namePrefix = config.namePrefix || "";
3462
- config.enableDebug = stringToBoolOrDefault(config.enableDebug);
3463
- config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
3464
- config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
3465
- return config;
3466
- };
3467
- ApplicationInsights.Version = "2.7.5-nightly.2203-02";
3468
- return ApplicationInsights;
3469
- }(BaseTelemetryPlugin));
3470
- var Timing = /** @class */ (function () {
3471
- function Timing(logger, name) {
3472
- var _self = this;
3473
- var _events = {};
3474
- _self.start = function (name) {
3475
- if (typeof _events[name] !== "undefined") {
3476
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
4323
+ function _updateExceptionTracking(extConfig) {
4324
+ var _window = getWindow();
4325
+ var locn = getLocation(true);
4326
+ _disableExceptionTracking = extConfig.disableExceptionTracking;
4327
+ if (!_disableExceptionTracking && !_autoExceptionInstrumented && !extConfig.autoExceptionInstrumented) {
4328
+ _addHook(InstrumentFunc(_window, "onerror", {
4329
+ ns: _evtNamespace,
4330
+ rsp: function (callDetails, message, url, lineNumber, columnNumber, error) {
4331
+ if (!_disableExceptionTracking && callDetails.rslt !== true) {
4332
+ _self._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, callDetails.evt));
4333
+ }
4334
+ }
4335
+ }));
4336
+ _autoExceptionInstrumented = true;
4337
+ }
4338
+ _addUnhandledPromiseRejectionTracking(extConfig, _window, locn);
3477
4339
  }
3478
- _events[name] = +new Date;
3479
- };
3480
- _self.stop = function (name, url, properties, measurements) {
3481
- var start = _events[name];
3482
- if (isNaN(start)) {
3483
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
4340
+ function _updateLocationChange(extConfig) {
4341
+ var win = getWindow();
4342
+ var locn = getLocation(true);
4343
+ _enableAutoRouteTracking = extConfig.enableAutoRouteTracking === true;
4344
+ if (win && _enableAutoRouteTracking && hasHistory()) {
4345
+ var _history = getHistory();
4346
+ if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strShimUndefined) {
4347
+ _addHistoryListener(extConfig, win, _history, locn);
4348
+ }
4349
+ }
3484
4350
  }
3485
- else {
3486
- var end = +new Date;
3487
- var duration = dateTimeUtilsDuration(start, end);
3488
- _self.action(name, url, duration, properties, measurements);
4351
+ function _addHistoryListener(extConfig, win, history, locn) {
4352
+ function _popstateHandler() {
4353
+ if (_enableAutoRouteTracking) {
4354
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
4355
+ }
4356
+ }
4357
+ function _locationChangeHandler() {
4358
+ if (_currUri) {
4359
+ _prevUri = _currUri;
4360
+ _currUri = locn && locn.href || "";
4361
+ }
4362
+ else {
4363
+ _currUri = locn && locn.href || "";
4364
+ }
4365
+ if (_enableAutoRouteTracking) {
4366
+ var properties = _self.core.getPlugin(PropertiesPluginIdentifier);
4367
+ if (properties) {
4368
+ var context = properties.plugin.context;
4369
+ if (context && context.telemetryTrace) {
4370
+ context.telemetryTrace.traceID = generateW3CId();
4371
+ var traceLocationName = "_unknown_";
4372
+ if (locn && locn.pathname) {
4373
+ traceLocationName = locn.pathname + (locn.hash || "");
4374
+ }
4375
+ context.telemetryTrace.name = dataSanitizeString(_self.diagLog(), traceLocationName);
4376
+ }
4377
+ }
4378
+ setTimeout((function (uri) {
4379
+ _self.trackPageView({ refUri: uri, properties: { duration: 0 } });
4380
+ }).bind(this, _prevUri), _self.autoRoutePVDelay);
4381
+ }
4382
+ }
4383
+ if (!_historyListenerAdded) {
4384
+ _addHook(InstrumentFunc(history, "pushState", {
4385
+ ns: _evtNamespace,
4386
+ rsp: function () {
4387
+ if (_enableAutoRouteTracking) {
4388
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "pushState"));
4389
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
4390
+ }
4391
+ }
4392
+ }));
4393
+ _addHook(InstrumentFunc(history, "replaceState", {
4394
+ ns: _evtNamespace,
4395
+ rsp: function () {
4396
+ if (_enableAutoRouteTracking) {
4397
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "replaceState"));
4398
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
4399
+ }
4400
+ }
4401
+ }));
4402
+ eventOn(win, extConfig.namePrefix + "popstate", _popstateHandler, _evtNamespace);
4403
+ eventOn(win, extConfig.namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
4404
+ _historyListenerAdded = true;
4405
+ }
3489
4406
  }
3490
- delete _events[name];
3491
- _events[name] = undefined;
3492
- };
4407
+ function _addUnhandledPromiseRejectionTracking(extConfig, _window, _location) {
4408
+ _enableUnhandledPromiseRejectionTracking = extConfig.enableUnhandledPromiseRejectionTracking === true;
4409
+ if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
4410
+ _addHook(InstrumentFunc(_window, "onunhandledrejection", {
4411
+ ns: _evtNamespace,
4412
+ rsp: function (callDetails, error) {
4413
+ if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) {
4414
+ _self._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, callDetails.evt));
4415
+ }
4416
+ }
4417
+ }));
4418
+ _autoUnhandledPromiseInstrumented = true;
4419
+ extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented;
4420
+ }
4421
+ }
4422
+ function _throwInternal(severity, msgId, msg, properties, isUserAct) {
4423
+ _self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
4424
+ }
4425
+ function _initDefaults() {
4426
+ _eventTracking = null;
4427
+ _pageTracking = null;
4428
+ _pageViewManager = null;
4429
+ _pageViewPerformanceManager = null;
4430
+ _pageVisitTimeManager = null;
4431
+ _preInitTelemetryInitializers = null;
4432
+ _isBrowserLinkTrackingEnabled = false;
4433
+ _browserLinkInitializerAdded = false;
4434
+ _enableAutoRouteTracking = false;
4435
+ _historyListenerAdded = false;
4436
+ _disableExceptionTracking = false;
4437
+ _autoExceptionInstrumented = false;
4438
+ _enableUnhandledPromiseRejectionTracking = false;
4439
+ _autoUnhandledPromiseInstrumented = false;
4440
+ var location = getLocation(true);
4441
+ _prevUri = location && location.href || "";
4442
+ _currUri = null;
4443
+ _evtNamespace = null;
4444
+ }
4445
+ objDefineAccessors(_self, "_pageViewManager", function () { return _pageViewManager; });
4446
+ objDefineAccessors(_self, "_pageViewPerformanceManager", function () { return _pageViewPerformanceManager; });
4447
+ objDefineAccessors(_self, "_pageVisitTimeManager", function () { return _pageVisitTimeManager; });
4448
+ objDefineAccessors(_self, "_evtNamespace", function () { return "." + _evtNamespace; });
4449
+ });
4450
+ return _this;
3493
4451
  }
3494
- return Timing;
3495
- }());
4452
+ AnalyticsPlugin.Version = "2.7.5-nightly.2203-03";
4453
+ AnalyticsPlugin.getDefaultConfig = _getDefaultConfig;
4454
+ return AnalyticsPlugin;
4455
+ }(BaseTelemetryPlugin));
3496
4456
 
3497
- exports.ApplicationInsights = ApplicationInsights;
4457
+ exports.AnalyticsPlugin = AnalyticsPlugin;
4458
+ exports.ApplicationInsights = AnalyticsPlugin;
3498
4459
 
3499
4460
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
3500
4461