Translation and fix for editing project task
[wsti_pai.git] / Projects / Scripts / ai.0.15.0-build58334.js
1 var Microsoft;
2 (function (Microsoft) {
3     var ApplicationInsights;
4     (function (ApplicationInsights) {
5         (function (LoggingSeverity) {
6             LoggingSeverity[LoggingSeverity["CRITICAL"] = 0] = "CRITICAL";
7             LoggingSeverity[LoggingSeverity["WARNING"] = 1] = "WARNING";
8         })(ApplicationInsights.LoggingSeverity || (ApplicationInsights.LoggingSeverity = {}));
9         var LoggingSeverity = ApplicationInsights.LoggingSeverity;
10         var _InternalLogging = (function () {
11             function _InternalLogging() {
12             }
13             _InternalLogging.throwInternalNonUserActionable = function (severity, message) {
14                 if (this.enableDebugExceptions()) {
15                     throw message;
16                 }
17                 else {
18                     this.warnToConsole(message);
19                     this.logInternalMessage(severity, this.AiNonUserActionablePrefix + message);
20                 }
21             };
22             _InternalLogging.throwInternalUserActionable = function (severity, message) {
23                 if (this.enableDebugExceptions()) {
24                     throw message;
25                 }
26                 else {
27                     this.warnToConsole(message);
28                     this.logInternalMessage(severity, this.AiUserActionablePrefix + message);
29                 }
30             };
31             _InternalLogging.warnToConsole = function (message) {
32                 if (typeof console !== "undefined" && !!console) {
33                     if (typeof console.warn === "function") {
34                         console.warn(message);
35                     }
36                     else if (typeof console.log === "function") {
37                         console.log(message);
38                     }
39                 }
40             };
41             _InternalLogging.resetInternalMessageCount = function () {
42                 this._messageCount = 0;
43             };
44             _InternalLogging.setMaxInternalMessageLimit = function (limit) {
45                 if (!limit) {
46                     throw new Error('limit cannot be undefined.');
47                 }
48                 this.MAX_INTERNAL_MESSAGE_LIMIT = limit;
49             };
50             _InternalLogging.logInternalMessage = function (severity, message) {
51                 if (this._areInternalMessagesThrottled()) {
52                     return;
53                 }
54                 if (this.verboseLogging() || severity === 0 /* CRITICAL */) {
55                     this.queue.push(message);
56                     this._messageCount++;
57                 }
58                 if (this._messageCount == this.MAX_INTERNAL_MESSAGE_LIMIT) {
59                     var throttleLimitMessage = this.AiNonUserActionablePrefix + "Internal events throttle limit per PageView reached for this app.";
60                     this.queue.push(throttleLimitMessage);
61                     this.warnToConsole(throttleLimitMessage);
62                 }
63             };
64             _InternalLogging._areInternalMessagesThrottled = function () {
65                 return this._messageCount >= this.MAX_INTERNAL_MESSAGE_LIMIT;
66             };
67             _InternalLogging.AiUserActionablePrefix = "AI: ";
68             _InternalLogging.AiNonUserActionablePrefix = "AI (Internal): ";
69             _InternalLogging.enableDebugExceptions = function () { return false; };
70             _InternalLogging.verboseLogging = function () { return false; };
71             _InternalLogging.queue = [];
72             _InternalLogging.MAX_INTERNAL_MESSAGE_LIMIT = 25;
73             _InternalLogging._messageCount = 0;
74             return _InternalLogging;
75         })();
76         ApplicationInsights._InternalLogging = _InternalLogging;
77     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
78 })(Microsoft || (Microsoft = {}));
79 var Microsoft;
80 (function (Microsoft) {
81     var ApplicationInsights;
82     (function (ApplicationInsights) {
83         var Util = (function () {
84             function Util() {
85             }
86             Util._getStorageObject = function () {
87                 try {
88                     if (window.localStorage) {
89                         return window.localStorage;
90                     }
91                     else {
92                         return null;
93                     }
94                 }
95                 catch (e) {
96                     ApplicationInsights._InternalLogging.warnToConsole('Failed to get client localStorage: ' + e.message);
97                     return null;
98                 }
99             };
100             Util.canUseLocalStorage = function () {
101                 return !!Util._getStorageObject();
102             };
103             Util.getStorage = function (name) {
104                 var storage = Util._getStorageObject();
105                 if (storage !== null) {
106                     try {
107                         return storage.getItem(name);
108                     }
109                     catch (e) {
110                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed read of local storage." + Util.dump(e));
111                     }
112                 }
113                 return null;
114             };
115             Util.setStorage = function (name, data) {
116                 var storage = Util._getStorageObject();
117                 if (storage !== null) {
118                     try {
119                         storage.setItem(name, data);
120                         return true;
121                     }
122                     catch (e) {
123                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed write to local storage." + Util.dump(e));
124                     }
125                 }
126                 return false;
127             };
128             Util.removeStorage = function (name) {
129                 var storage = Util._getStorageObject();
130                 if (storage !== null) {
131                     try {
132                         storage.removeItem(name);
133                         return true;
134                     }
135                     catch (e) {
136                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed removal of local storage item." + Util.dump(e));
137                     }
138                 }
139                 return false;
140             };
141             Util._getSessionStorageObject = function () {
142                 try {
143                     if (window.sessionStorage) {
144                         return window.sessionStorage;
145                     }
146                     else {
147                         return null;
148                     }
149                 }
150                 catch (e) {
151                     ApplicationInsights._InternalLogging.warnToConsole('Failed to get client session storage: ' + e.message);
152                     return null;
153                 }
154             };
155             Util.canUseSessionStorage = function () {
156                 return !!Util._getSessionStorageObject();
157             };
158             Util.getSessionStorage = function (name) {
159                 var storage = Util._getSessionStorageObject();
160                 if (storage !== null) {
161                     try {
162                         return storage.getItem(name);
163                     }
164                     catch (e) {
165                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed read of session storage." + Util.dump(e));
166                     }
167                 }
168                 return null;
169             };
170             Util.setSessionStorage = function (name, data) {
171                 var storage = Util._getSessionStorageObject();
172                 if (storage !== null) {
173                     try {
174                         storage.setItem(name, data);
175                         return true;
176                     }
177                     catch (e) {
178                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed write to session storage." + Util.dump(e));
179                     }
180                 }
181                 return false;
182             };
183             Util.removeSessionStorage = function (name) {
184                 var storage = Util._getSessionStorageObject();
185                 if (storage !== null) {
186                     try {
187                         storage.removeItem(name);
188                         return true;
189                     }
190                     catch (e) {
191                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed removal of session storage item." + Util.dump(e));
192                     }
193                 }
194                 return false;
195             };
196             Util.setCookie = function (name, value) {
197                 Util.document.cookie = name + "=" + value + ";path=/";
198             };
199             Util.stringToBoolOrDefault = function (str) {
200                 if (!str) {
201                     return false;
202                 }
203                 return str.toString().toLowerCase() === "true";
204             };
205             Util.getCookie = function (name) {
206                 var value = "";
207                 if (name && name.length) {
208                     var cookieName = name + "=";
209                     var cookies = Util.document.cookie.split(";");
210                     for (var i = 0; i < cookies.length; i++) {
211                         var cookie = cookies[i];
212                         cookie = Util.trim(cookie);
213                         if (cookie && cookie.indexOf(cookieName) === 0) {
214                             value = cookie.substring(cookieName.length, cookies[i].length);
215                             break;
216                         }
217                     }
218                 }
219                 return value;
220             };
221             Util.deleteCookie = function (name) {
222                 Util.document.cookie = name + "=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
223             };
224             Util.trim = function (str) {
225                 if (typeof str !== "string")
226                     return str;
227                 return str.replace(/^\s+|\s+$/g, "");
228             };
229             Util.newGuid = function () {
230                 var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
231                 var oct = "", tmp;
232                 for (var a = 0; a < 4; a++) {
233                     tmp = (4294967296 * Math.random()) | 0;
234                     oct += hexValues[tmp & 0xF] + hexValues[tmp >> 4 & 0xF] + hexValues[tmp >> 8 & 0xF] + hexValues[tmp >> 12 & 0xF] + hexValues[tmp >> 16 & 0xF] + hexValues[tmp >> 20 & 0xF] + hexValues[tmp >> 24 & 0xF] + hexValues[tmp >> 28 & 0xF];
235                 }
236                 var clockSequenceHi = hexValues[8 + (Math.random() * 4) | 0];
237                 return oct.substr(0, 8) + "-" + oct.substr(9, 4) + "-4" + oct.substr(13, 3) + "-" + clockSequenceHi + oct.substr(16, 3) + "-" + oct.substr(19, 12);
238             };
239             Util.isArray = function (obj) {
240                 return Object.prototype.toString.call(obj) === "[object Array]";
241             };
242             Util.isError = function (obj) {
243                 return Object.prototype.toString.call(obj) === "[object Error]";
244             };
245             Util.isDate = function (obj) {
246                 return Object.prototype.toString.call(obj) === "[object Date]";
247             };
248             Util.toISOStringForIE8 = function (date) {
249                 if (Util.isDate(date)) {
250                     if (Date.prototype.toISOString) {
251                         return date.toISOString();
252                     }
253                     else {
254                         function pad(number) {
255                             var r = String(number);
256                             if (r.length === 1) {
257                                 r = "0" + r;
258                             }
259                             return r;
260                         }
261                         return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + "T" + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + "." + String((date.getUTCMilliseconds() / 1000).toFixed(3)).slice(2, 5) + "Z";
262                     }
263                 }
264             };
265             Util.msToTimeSpan = function (totalms) {
266                 if (isNaN(totalms) || totalms < 0) {
267                     totalms = 0;
268                 }
269                 var ms = "" + totalms % 1000;
270                 var sec = "" + Math.floor(totalms / 1000) % 60;
271                 var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
272                 var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
273                 ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
274                 sec = sec.length < 2 ? "0" + sec : sec;
275                 min = min.length < 2 ? "0" + min : min;
276                 hour = hour.length < 2 ? "0" + hour : hour;
277                 return hour + ":" + min + ":" + sec + "." + ms;
278             };
279             Util.isCrossOriginError = function (message, url, lineNumber, columnNumber, error) {
280                 return (message == "Script error." || message == "Script error") && url == "" && lineNumber == 0 && columnNumber == 0 && error == null;
281             };
282             Util.dump = function (object) {
283                 var objectTypeDump = Object.prototype.toString.call(object);
284                 var propertyValueDump = JSON.stringify(object);
285                 if (objectTypeDump === "[object Error]") {
286                     propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
287                 }
288                 return objectTypeDump + propertyValueDump;
289             };
290             Util.addEventHandler = function (eventName, callback) {
291                 if (!window || typeof eventName !== 'string' || typeof callback !== 'function') {
292                     return false;
293                 }
294                 var verbEventName = 'on' + eventName;
295                 if (window.addEventListener) {
296                     window.addEventListener(eventName, callback, false);
297                 }
298                 else if (window.attachEvent) {
299                     window.attachEvent(verbEventName, callback);
300                 }
301                 else {
302                     return false;
303                 }
304                 return true;
305             };
306             Util.document = typeof document !== "undefined" ? document : {};
307             Util.NotSpecified = "not_specified";
308             return Util;
309         })();
310         ApplicationInsights.Util = Util;
311     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
312 })(Microsoft || (Microsoft = {}));
313 var Microsoft;
314 (function (Microsoft) {
315     var ApplicationInsights;
316     (function (ApplicationInsights) {
317         "use strict";
318         var Serializer = (function () {
319             function Serializer() {
320             }
321             Serializer.serialize = function (input) {
322                 var output = Serializer._serializeObject(input, "root");
323                 return JSON.stringify(output);
324             };
325             Serializer._serializeObject = function (source, name) {
326                 var circularReferenceCheck = "__aiCircularRefCheck";
327                 var output = {};
328                 if (!source) {
329                     ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "cannot serialize " + name + " because it is null or undefined");
330                     return output;
331                 }
332                 if (source[circularReferenceCheck]) {
333                     ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Circular reference detected while serializing: '" + name);
334                     return output;
335                 }
336                 if (!source.aiDataContract) {
337                     if (name === "measurements") {
338                         output = Serializer._serializeStringMap(source, "number", name);
339                     }
340                     else if (name === "properties") {
341                         output = Serializer._serializeStringMap(source, "string", name);
342                     }
343                     else if (name === "tags") {
344                         output = Serializer._serializeStringMap(source, "string", name);
345                     }
346                     else if (ApplicationInsights.Util.isArray(source)) {
347                         output = Serializer._serializeArray(source, name);
348                     }
349                     else {
350                         ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Attempting to serialize an object which does not implement ISerializable: " + name);
351                         try {
352                             JSON.stringify(source);
353                             output = source;
354                         }
355                         catch (e) {
356                             ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, e && typeof e.toString === 'function' ? e.toString() : "Error serializing object");
357                         }
358                     }
359                     return output;
360                 }
361                 source[circularReferenceCheck] = true;
362                 for (var field in source.aiDataContract) {
363                     var isRequired = source.aiDataContract[field];
364                     var isArray = typeof isRequired !== "boolean";
365                     var isPresent = source[field] !== undefined;
366                     var isObject = typeof source[field] === "object" && source[field] !== null;
367                     if (isRequired && !isPresent && !isArray) {
368                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Missing required field specification: The field '" + field + "' on '" + name + "' is required but not present on source");
369                         continue;
370                     }
371                     var value;
372                     if (isObject) {
373                         if (isArray) {
374                             value = Serializer._serializeArray(source[field], field);
375                         }
376                         else {
377                             value = Serializer._serializeObject(source[field], field);
378                         }
379                     }
380                     else {
381                         value = source[field];
382                     }
383                     if (value !== undefined) {
384                         output[field] = value;
385                     }
386                 }
387                 delete source[circularReferenceCheck];
388                 return output;
389             };
390             Serializer._serializeArray = function (sources, name) {
391                 var output = undefined;
392                 if (!!sources) {
393                     if (!ApplicationInsights.Util.isArray(sources)) {
394                         ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "This field was specified as an array in the contract but the item is not an array.\r\n" + name);
395                     }
396                     else {
397                         output = [];
398                         for (var i = 0; i < sources.length; i++) {
399                             var source = sources[i];
400                             var item = Serializer._serializeObject(source, name + "[" + i + "]");
401                             output.push(item);
402                         }
403                     }
404                 }
405                 return output;
406             };
407             Serializer._serializeStringMap = function (map, expectedType, name) {
408                 var output = undefined;
409                 if (map) {
410                     output = {};
411                     for (var field in map) {
412                         var value = map[field];
413                         if (expectedType === "string") {
414                             if (value === undefined) {
415                                 output[field] = "undefined";
416                             }
417                             else if (value === null) {
418                                 output[field] = "null";
419                             }
420                             else if (!value.toString) {
421                                 output[field] = "invalid field: toString() is not defined.";
422                             }
423                             else {
424                                 output[field] = value.toString();
425                             }
426                         }
427                         else if (expectedType === "number") {
428                             if (value === undefined) {
429                                 output[field] = "undefined";
430                             }
431                             else if (value === null) {
432                                 output[field] = "null";
433                             }
434                             else {
435                                 var num = parseFloat(value);
436                                 if (isNaN(num)) {
437                                     output[field] = "NaN";
438                                 }
439                                 else {
440                                     output[field] = num;
441                                 }
442                             }
443                         }
444                         else {
445                             output[field] = "invalid field: " + name + " is of unknown type.";
446                             ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, output[field]);
447                         }
448                     }
449                 }
450                 return output;
451             };
452             return Serializer;
453         })();
454         ApplicationInsights.Serializer = Serializer;
455     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
456 })(Microsoft || (Microsoft = {}));
457 var Microsoft;
458 (function (Microsoft) {
459     var Telemetry;
460     (function (Telemetry) {
461         "use strict";
462         var Base = (function () {
463             function Base() {
464             }
465             return Base;
466         })();
467         Telemetry.Base = Base;
468     })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
469 })(Microsoft || (Microsoft = {}));
470 var Microsoft;
471 (function (Microsoft) {
472     var Telemetry;
473     (function (Telemetry) {
474         "use strict";
475         var Envelope = (function () {
476             function Envelope() {
477                 this.ver = 1;
478                 this.sampleRate = 100.0;
479                 this.tags = {};
480             }
481             return Envelope;
482         })();
483         Telemetry.Envelope = Envelope;
484     })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
485 })(Microsoft || (Microsoft = {}));
486 var __extends = this.__extends || function (d, b) {
487     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
488     function __() { this.constructor = d; }
489     __.prototype = b.prototype;
490     d.prototype = new __();
491 };
492 var Microsoft;
493 (function (Microsoft) {
494     var ApplicationInsights;
495     (function (ApplicationInsights) {
496         var Telemetry;
497         (function (Telemetry) {
498             var Common;
499             (function (Common) {
500                 "use strict";
501                 var Envelope = (function (_super) {
502                     __extends(Envelope, _super);
503                     function Envelope(data, name) {
504                         _super.call(this);
505                         this.name = name;
506                         this.data = data;
507                         this.time = ApplicationInsights.Util.toISOStringForIE8(new Date());
508                         this.aiDataContract = {
509                             time: true,
510                             iKey: true,
511                             name: true,
512                             tags: true,
513                             data: true
514                         };
515                     }
516                     return Envelope;
517                 })(Microsoft.Telemetry.Envelope);
518                 Common.Envelope = Envelope;
519             })(Common = Telemetry.Common || (Telemetry.Common = {}));
520         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
521     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
522 })(Microsoft || (Microsoft = {}));
523 var Microsoft;
524 (function (Microsoft) {
525     var ApplicationInsights;
526     (function (ApplicationInsights) {
527         var Telemetry;
528         (function (Telemetry) {
529             var Common;
530             (function (Common) {
531                 "use strict";
532                 var Base = (function (_super) {
533                     __extends(Base, _super);
534                     function Base() {
535                         _super.apply(this, arguments);
536                         this.aiDataContract = {};
537                     }
538                     return Base;
539                 })(Microsoft.Telemetry.Base);
540                 Common.Base = Base;
541             })(Common = Telemetry.Common || (Telemetry.Common = {}));
542         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
543     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
544 })(Microsoft || (Microsoft = {}));
545 var AI;
546 (function (AI) {
547     "use strict";
548     var ContextTagKeys = (function () {
549         function ContextTagKeys() {
550             this.applicationVersion = "ai.application.ver";
551             this.applicationBuild = "ai.application.build";
552             this.applicationTypeId = "ai.application.typeId";
553             this.deviceId = "ai.device.id";
554             this.deviceIp = "ai.device.ip";
555             this.deviceLanguage = "ai.device.language";
556             this.deviceLocale = "ai.device.locale";
557             this.deviceModel = "ai.device.model";
558             this.deviceNetwork = "ai.device.network";
559             this.deviceNetworkName = "ai.device.networkName";
560             this.deviceOEMName = "ai.device.oemName";
561             this.deviceOS = "ai.device.os";
562             this.deviceOSVersion = "ai.device.osVersion";
563             this.deviceRoleInstance = "ai.device.roleInstance";
564             this.deviceRoleName = "ai.device.roleName";
565             this.deviceScreenResolution = "ai.device.screenResolution";
566             this.deviceType = "ai.device.type";
567             this.deviceMachineName = "ai.device.machineName";
568             this.deviceVMName = "ai.device.vmName";
569             this.locationIp = "ai.location.ip";
570             this.operationId = "ai.operation.id";
571             this.operationName = "ai.operation.name";
572             this.operationParentId = "ai.operation.parentId";
573             this.operationRootId = "ai.operation.rootId";
574             this.operationSyntheticSource = "ai.operation.syntheticSource";
575             this.operationIsSynthetic = "ai.operation.isSynthetic";
576             this.sessionId = "ai.session.id";
577             this.sessionIsFirst = "ai.session.isFirst";
578             this.sessionIsNew = "ai.session.isNew";
579             this.userAccountAcquisitionDate = "ai.user.accountAcquisitionDate";
580             this.userAccountId = "ai.user.accountId";
581             this.userAgent = "ai.user.userAgent";
582             this.userId = "ai.user.id";
583             this.userStoreRegion = "ai.user.storeRegion";
584             this.userAuthUserId = "ai.user.authUserId";
585             this.userAnonymousUserAcquisitionDate = "ai.user.anonUserAcquisitionDate";
586             this.userAuthenticatedUserAcquisitionDate = "ai.user.authUserAcquisitionDate";
587             this.sampleRate = "ai.sample.sampleRate";
588             this.internalSdkVersion = "ai.internal.sdkVersion";
589             this.internalAgentVersion = "ai.internal.agentVersion";
590             this.internalDataCollectorReceivedTime = "ai.internal.dataCollectorReceivedTime";
591             this.internalProfileId = "ai.internal.profileId";
592             this.internalProfileClassId = "ai.internal.profileClassId";
593             this.internalAccountId = "ai.internal.accountId";
594             this.internalApplicationName = "ai.internal.applicationName";
595             this.internalInstrumentationKey = "ai.internal.instrumentationKey";
596             this.internalTelemetryItemId = "ai.internal.telemetryItemId";
597             this.internalApplicationType = "ai.internal.applicationType";
598             this.internalRequestSource = "ai.internal.requestSource";
599             this.internalFlowType = "ai.internal.flowType";
600             this.internalIsAudit = "ai.internal.isAudit";
601             this.internalTrackingSourceId = "ai.internal.trackingSourceId";
602             this.internalTrackingType = "ai.internal.trackingType";
603         }
604         return ContextTagKeys;
605     })();
606     AI.ContextTagKeys = ContextTagKeys;
607 })(AI || (AI = {}));
608 var Microsoft;
609 (function (Microsoft) {
610     var ApplicationInsights;
611     (function (ApplicationInsights) {
612         var Context;
613         (function (Context) {
614             "use strict";
615             var Application = (function () {
616                 function Application() {
617                 }
618                 return Application;
619             })();
620             Context.Application = Application;
621         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
622     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
623 })(Microsoft || (Microsoft = {}));
624 var Microsoft;
625 (function (Microsoft) {
626     var ApplicationInsights;
627     (function (ApplicationInsights) {
628         var Context;
629         (function (Context) {
630             "use strict";
631             var Device = (function () {
632                 function Device() {
633                     this.id = "browser";
634                     if (typeof screen !== "undefined" && screen.width && screen.height) {
635                         this.resolution = screen.width + "X" + screen.height;
636                     }
637                     this.locale = (typeof screen !== "undefined" && navigator.browserLanguage) ? navigator.browserLanguage : "unknown";
638                 }
639                 return Device;
640             })();
641             Context.Device = Device;
642         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
643     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
644 })(Microsoft || (Microsoft = {}));
645 var Microsoft;
646 (function (Microsoft) {
647     var ApplicationInsights;
648     (function (ApplicationInsights) {
649         var Context;
650         (function (Context) {
651             "use strict";
652             var Internal = (function () {
653                 function Internal() {
654                     this.sdkVersion = "JavaScript:" + ApplicationInsights.Version;
655                 }
656                 return Internal;
657             })();
658             Context.Internal = Internal;
659         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
660     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
661 })(Microsoft || (Microsoft = {}));
662 var Microsoft;
663 (function (Microsoft) {
664     var ApplicationInsights;
665     (function (ApplicationInsights) {
666         var Context;
667         (function (Context) {
668             "use strict";
669             var Location = (function () {
670                 function Location() {
671                 }
672                 return Location;
673             })();
674             Context.Location = Location;
675         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
676     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
677 })(Microsoft || (Microsoft = {}));
678 var Microsoft;
679 (function (Microsoft) {
680     var ApplicationInsights;
681     (function (ApplicationInsights) {
682         var Context;
683         (function (Context) {
684             "use strict";
685             var Operation = (function () {
686                 function Operation() {
687                     this.id = ApplicationInsights.Util.newGuid();
688                 }
689                 return Operation;
690             })();
691             Context.Operation = Operation;
692         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
693     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
694 })(Microsoft || (Microsoft = {}));
695 var Microsoft;
696 (function (Microsoft) {
697     var ApplicationInsights;
698     (function (ApplicationInsights) {
699         var SamplingScoreGenerator = (function () {
700             function SamplingScoreGenerator() {
701             }
702             SamplingScoreGenerator.getScore = function (envelope) {
703                 var tagKeys = new AI.ContextTagKeys();
704                 var score = 0;
705                 if (envelope.tags[tagKeys.userId]) {
706                     score = SamplingScoreGenerator.getSamplingHashCode(envelope.tags[tagKeys.userId]) / SamplingScoreGenerator.INT_MAX_VALUE;
707                 }
708                 else if (envelope.tags[tagKeys.operationId]) {
709                     score = SamplingScoreGenerator.getSamplingHashCode(envelope.tags[tagKeys.operationId]) / SamplingScoreGenerator.INT_MAX_VALUE;
710                 }
711                 else {
712                     score = Math.random();
713                 }
714                 return score * 100;
715             };
716             SamplingScoreGenerator.getSamplingHashCode = function (input) {
717                 if (input == "") {
718                     return 0;
719                 }
720                 var hash = 5381;
721                 for (var i = 0; i < input.length; ++i) {
722                     hash = ((hash << 5) + hash) + input.charCodeAt(i);
723                     hash = hash & hash;
724                 }
725                 return Math.abs(hash);
726             };
727             SamplingScoreGenerator.INT_MAX_VALUE = 2147483647;
728             return SamplingScoreGenerator;
729         })();
730         ApplicationInsights.SamplingScoreGenerator = SamplingScoreGenerator;
731     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
732 })(Microsoft || (Microsoft = {}));
733 var Microsoft;
734 (function (Microsoft) {
735     var ApplicationInsights;
736     (function (ApplicationInsights) {
737         var Context;
738         (function (Context) {
739             "use strict";
740             var Sample = (function () {
741                 function Sample(sampleRate) {
742                     this.INT_MAX_VALUE = 2147483647;
743                     if (sampleRate > 100 || sampleRate < 0) {
744                         ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Sampling rate is out of range (0..100): '" + sampleRate + "'. Sampling will be disabled, you may be sending too much data which may affect your AI service level.");
745                         this.sampleRate = 100;
746                     }
747                     this.sampleRate = sampleRate;
748                 }
749                 Sample.prototype.isSampledIn = function (envelope) {
750                     if (this.sampleRate == 100)
751                         return true;
752                     var score = ApplicationInsights.SamplingScoreGenerator.getScore(envelope);
753                     return score < this.sampleRate;
754                 };
755                 return Sample;
756             })();
757             Context.Sample = Sample;
758         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
759     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
760 })(Microsoft || (Microsoft = {}));
761 var AI;
762 (function (AI) {
763     "use strict";
764     (function (SessionState) {
765         SessionState[SessionState["Start"] = 0] = "Start";
766         SessionState[SessionState["End"] = 1] = "End";
767     })(AI.SessionState || (AI.SessionState = {}));
768     var SessionState = AI.SessionState;
769 })(AI || (AI = {}));
770 var Microsoft;
771 (function (Microsoft) {
772     var ApplicationInsights;
773     (function (ApplicationInsights) {
774         var Context;
775         (function (Context) {
776             "use strict";
777             var Session = (function () {
778                 function Session() {
779                 }
780                 return Session;
781             })();
782             Context.Session = Session;
783             var _SessionManager = (function () {
784                 function _SessionManager(config, sessionHandler) {
785                     if (!config) {
786                         config = {};
787                     }
788                     if (!(typeof config.sessionExpirationMs === "function")) {
789                         config.sessionExpirationMs = function () { return _SessionManager.acquisitionSpan; };
790                     }
791                     if (!(typeof config.sessionRenewalMs === "function")) {
792                         config.sessionRenewalMs = function () { return _SessionManager.renewalSpan; };
793                     }
794                     this.config = config;
795                     this._sessionHandler = sessionHandler;
796                     this.automaticSession = new Session();
797                 }
798                 _SessionManager.prototype.update = function () {
799                     if (!this.automaticSession.id) {
800                         this.initializeAutomaticSession();
801                     }
802                     var now = +new Date;
803                     var acquisitionExpired = now - this.automaticSession.acquisitionDate > this.config.sessionExpirationMs();
804                     var renewalExpired = now - this.automaticSession.renewalDate > this.config.sessionRenewalMs();
805                     if (acquisitionExpired || renewalExpired) {
806                         if (typeof this._sessionHandler === "function") {
807                             this._sessionHandler(1 /* End */, this.automaticSession.renewalDate);
808                         }
809                         this.automaticSession.isFirst = undefined;
810                         this.renew();
811                     }
812                     else {
813                         this.automaticSession.renewalDate = +new Date;
814                         this.setCookie(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
815                     }
816                 };
817                 _SessionManager.prototype.backup = function () {
818                     this.setStorage(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
819                 };
820                 _SessionManager.prototype.initializeAutomaticSession = function () {
821                     var cookie = ApplicationInsights.Util.getCookie('ai_session');
822                     if (cookie && typeof cookie.split === "function") {
823                         this.initializeAutomaticSessionWithData(cookie);
824                     }
825                     else {
826                         var storage = ApplicationInsights.Util.getStorage('ai_session');
827                         if (storage) {
828                             this.initializeAutomaticSessionWithData(storage);
829                         }
830                     }
831                     if (!this.automaticSession.id) {
832                         this.automaticSession.isFirst = true;
833                         this.renew();
834                     }
835                 };
836                 _SessionManager.prototype.initializeAutomaticSessionWithData = function (sessionData) {
837                     var params = sessionData.split("|");
838                     if (params.length > 0) {
839                         this.automaticSession.id = params[0];
840                     }
841                     try {
842                         if (params.length > 1) {
843                             var acq = +params[1];
844                             this.automaticSession.acquisitionDate = +new Date(acq);
845                             this.automaticSession.acquisitionDate = this.automaticSession.acquisitionDate > 0 ? this.automaticSession.acquisitionDate : 0;
846                         }
847                         if (params.length > 2) {
848                             var renewal = +params[2];
849                             this.automaticSession.renewalDate = +new Date(renewal);
850                             this.automaticSession.renewalDate = this.automaticSession.renewalDate > 0 ? this.automaticSession.renewalDate : 0;
851                         }
852                     }
853                     catch (e) {
854                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Error parsing ai_session cookie, session will be reset: " + ApplicationInsights.Util.dump(e));
855                     }
856                     if (this.automaticSession.renewalDate == 0) {
857                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "AI session renewal date is 0, session will be reset.");
858                     }
859                 };
860                 _SessionManager.prototype.renew = function () {
861                     var now = +new Date;
862                     this.automaticSession.id = ApplicationInsights.Util.newGuid();
863                     this.automaticSession.acquisitionDate = now;
864                     this.automaticSession.renewalDate = now;
865                     this.setCookie(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
866                     if (typeof this._sessionHandler === "function") {
867                         this._sessionHandler(0 /* Start */, now);
868                     }
869                     if (!ApplicationInsights.Util.canUseLocalStorage()) {
870                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser does not support local storage. Session durations will be inaccurate.");
871                     }
872                 };
873                 _SessionManager.prototype.setCookie = function (guid, acq, renewal) {
874                     var acquisitionExpiry = acq + this.config.sessionExpirationMs();
875                     var renewalExpiry = renewal + this.config.sessionRenewalMs();
876                     var cookieExpiry = new Date();
877                     var cookie = [guid, acq, renewal];
878                     if (acquisitionExpiry < renewalExpiry) {
879                         cookieExpiry.setTime(acquisitionExpiry);
880                     }
881                     else {
882                         cookieExpiry.setTime(renewalExpiry);
883                     }
884                     ApplicationInsights.Util.setCookie('ai_session', cookie.join('|') + ';expires=' + cookieExpiry.toUTCString());
885                 };
886                 _SessionManager.prototype.setStorage = function (guid, acq, renewal) {
887                     ApplicationInsights.Util.setStorage('ai_session', [guid, acq, renewal].join('|'));
888                 };
889                 _SessionManager.acquisitionSpan = 86400000;
890                 _SessionManager.renewalSpan = 1800000;
891                 return _SessionManager;
892             })();
893             Context._SessionManager = _SessionManager;
894         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
895     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
896 })(Microsoft || (Microsoft = {}));
897 var Microsoft;
898 (function (Microsoft) {
899     var ApplicationInsights;
900     (function (ApplicationInsights) {
901         var Context;
902         (function (Context) {
903             "use strict";
904             var User = (function () {
905                 function User(accountId) {
906                     var cookie = ApplicationInsights.Util.getCookie(User.userCookieName);
907                     if (cookie) {
908                         var params = cookie.split(User.cookieSeparator);
909                         if (params.length > 0) {
910                             this.id = params[0];
911                         }
912                     }
913                     if (!this.id) {
914                         this.id = ApplicationInsights.Util.newGuid();
915                         var date = new Date();
916                         var acqStr = ApplicationInsights.Util.toISOStringForIE8(date);
917                         this.accountAcquisitionDate = acqStr;
918                         date.setTime(date.getTime() + 31536000000);
919                         var newCookie = [this.id, acqStr];
920                         ApplicationInsights.Util.setCookie(User.userCookieName, newCookie.join(User.cookieSeparator) + ';expires=' + date.toUTCString());
921                         ApplicationInsights.Util.removeStorage('ai_session');
922                     }
923                     this.accountId = accountId;
924                     var authCookie = ApplicationInsights.Util.getCookie(User.authUserCookieName);
925                     if (authCookie) {
926                         authCookie = decodeURI(authCookie);
927                         var authCookieString = authCookie.split(User.cookieSeparator);
928                         if (authCookieString[0]) {
929                             this.authenticatedId = authCookieString[0];
930                         }
931                         if (authCookieString.length > 1 && authCookieString[1]) {
932                             this.accountId = authCookieString[1];
933                         }
934                     }
935                 }
936                 User.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId) {
937                     var isInvalidInput = !this.validateUserInput(authenticatedUserId) || (accountId && !this.validateUserInput(accountId));
938                     if (isInvalidInput) {
939                         ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Setting auth user context failed. " + "User auth/account id should be of type string, and not contain commas, semi-colons, equal signs, spaces, or vertical-bars.");
940                         return;
941                     }
942                     this.authenticatedId = authenticatedUserId;
943                     var authCookie = this.authenticatedId;
944                     if (accountId) {
945                         this.accountId = accountId;
946                         authCookie = [this.authenticatedId, this.accountId].join(User.cookieSeparator);
947                     }
948                     ApplicationInsights.Util.setCookie(User.authUserCookieName, encodeURI(authCookie));
949                 };
950                 User.prototype.clearAuthenticatedUserContext = function () {
951                     this.authenticatedId = null;
952                     this.accountId = null;
953                     ApplicationInsights.Util.deleteCookie(User.authUserCookieName);
954                 };
955                 User.prototype.validateUserInput = function (id) {
956                     if (typeof id !== 'string' || !id || id.match(/,|;|=| |\|/)) {
957                         return false;
958                     }
959                     return true;
960                 };
961                 User.cookieSeparator = '|';
962                 User.userCookieName = 'ai_user';
963                 User.authUserCookieName = 'ai_authUser';
964                 return User;
965             })();
966             Context.User = User;
967         })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
968     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
969 })(Microsoft || (Microsoft = {}));
970 var Microsoft;
971 (function (Microsoft) {
972     var ApplicationInsights;
973     (function (ApplicationInsights) {
974         "use strict";
975         var Sender = (function () {
976             function Sender(config) {
977                 this._buffer = [];
978                 this._lastSend = 0;
979                 this._config = config;
980                 this._sender = null;
981                 if (typeof XMLHttpRequest != "undefined") {
982                     var testXhr = new XMLHttpRequest();
983                     if ("withCredentials" in testXhr) {
984                         this._sender = this._xhrSender;
985                     }
986                     else if (typeof XDomainRequest !== "undefined") {
987                         this._sender = this._xdrSender;
988                     }
989                 }
990             }
991             Sender.prototype.send = function (envelope) {
992                 var _this = this;
993                 try {
994                     if (this._config.disableTelemetry()) {
995                         return;
996                     }
997                     if (!envelope) {
998                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Cannot send empty telemetry");
999                         return;
1000                     }
1001                     if (!this._sender) {
1002                         ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Sender was not initialized");
1003                         return;
1004                     }
1005                     var payload = ApplicationInsights.Serializer.serialize(envelope);
1006                     if (this._getSizeInBytes(this._buffer) + payload.length > this._config.maxBatchSizeInBytes()) {
1007                         this.triggerSend();
1008                     }
1009                     this._buffer.push(payload);
1010                     if (!this._timeoutHandle) {
1011                         this._timeoutHandle = setTimeout(function () {
1012                             _this._timeoutHandle = null;
1013                             _this.triggerSend();
1014                         }, this._config.maxBatchInterval());
1015                     }
1016                 }
1017                 catch (e) {
1018                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + ApplicationInsights.Util.dump(e));
1019                 }
1020             };
1021             Sender.prototype._getSizeInBytes = function (list) {
1022                 var size = 0;
1023                 if (list && list.length) {
1024                     for (var i = 0; i < list.length; i++) {
1025                         var item = list[i];
1026                         if (item && item.length) {
1027                             size += item.length;
1028                         }
1029                     }
1030                 }
1031                 return size;
1032             };
1033             Sender.prototype.triggerSend = function (async) {
1034                 var isAsync = true;
1035                 if (typeof async === 'boolean') {
1036                     isAsync = async;
1037                 }
1038                 try {
1039                     if (!this._config.disableTelemetry()) {
1040                         if (this._buffer.length) {
1041                             var batch = this._config.emitLineDelimitedJson() ? this._buffer.join("\n") : "[" + this._buffer.join(",") + "]";
1042                             this._sender(batch, isAsync);
1043                         }
1044                         this._lastSend = +new Date;
1045                     }
1046                     this._buffer.length = 0;
1047                     clearTimeout(this._timeoutHandle);
1048                     this._timeoutHandle = null;
1049                 }
1050                 catch (e) {
1051                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Telemetry transmission failed, some telemetry will be lost: " + ApplicationInsights.Util.dump(e));
1052                 }
1053             };
1054             Sender.prototype._xhrSender = function (payload, isAsync) {
1055                 var xhr = new XMLHttpRequest();
1056                 xhr.open("POST", this._config.endpointUrl(), isAsync);
1057                 xhr.setRequestHeader("Content-type", "application/json");
1058                 xhr.onreadystatechange = function () { return Sender._xhrReadyStateChange(xhr, payload); };
1059                 xhr.onerror = function (event) { return Sender._onError(payload, xhr.responseText || xhr.response || "", event); };
1060                 xhr.send(payload);
1061             };
1062             Sender.prototype._xdrSender = function (payload, isAsync) {
1063                 var xdr = new XDomainRequest();
1064                 xdr.onload = function () { return Sender._xdrOnLoad(xdr, payload); };
1065                 xdr.onerror = function (event) { return Sender._onError(payload, xdr.responseText || "", event); };
1066                 xdr.open('POST', this._config.endpointUrl());
1067                 xdr.send(payload);
1068             };
1069             Sender._xhrReadyStateChange = function (xhr, payload) {
1070                 if (xhr.readyState === 4) {
1071                     if ((xhr.status < 200 || xhr.status >= 300) && xhr.status !== 0) {
1072                         Sender._onError(payload, xhr.responseText || xhr.response || "");
1073                     }
1074                     else {
1075                         Sender._onSuccess(payload);
1076                     }
1077                 }
1078             };
1079             Sender._xdrOnLoad = function (xdr, payload) {
1080                 if (xdr && (xdr.responseText + "" === "200" || xdr.responseText === "")) {
1081                     Sender._onSuccess(payload);
1082                 }
1083                 else {
1084                     Sender._onError(payload, xdr && xdr.responseText || "");
1085                 }
1086             };
1087             Sender._onError = function (payload, message, event) {
1088                 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Failed to send telemetry:\n" + message);
1089             };
1090             Sender._onSuccess = function (payload) {
1091             };
1092             return Sender;
1093         })();
1094         ApplicationInsights.Sender = Sender;
1095     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1096 })(Microsoft || (Microsoft = {}));
1097 var Microsoft;
1098 (function (Microsoft) {
1099     var Telemetry;
1100     (function (Telemetry) {
1101         "use strict";
1102         var Domain = (function () {
1103             function Domain() {
1104             }
1105             return Domain;
1106         })();
1107         Telemetry.Domain = Domain;
1108     })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
1109 })(Microsoft || (Microsoft = {}));
1110 var AI;
1111 (function (AI) {
1112     "use strict";
1113     (function (SeverityLevel) {
1114         SeverityLevel[SeverityLevel["Verbose"] = 0] = "Verbose";
1115         SeverityLevel[SeverityLevel["Information"] = 1] = "Information";
1116         SeverityLevel[SeverityLevel["Warning"] = 2] = "Warning";
1117         SeverityLevel[SeverityLevel["Error"] = 3] = "Error";
1118         SeverityLevel[SeverityLevel["Critical"] = 4] = "Critical";
1119     })(AI.SeverityLevel || (AI.SeverityLevel = {}));
1120     var SeverityLevel = AI.SeverityLevel;
1121 })(AI || (AI = {}));
1122 var AI;
1123 (function (AI) {
1124     "use strict";
1125     var MessageData = (function (_super) {
1126         __extends(MessageData, _super);
1127         function MessageData() {
1128             this.ver = 2;
1129             this.properties = {};
1130             _super.call(this);
1131         }
1132         return MessageData;
1133     })(Microsoft.Telemetry.Domain);
1134     AI.MessageData = MessageData;
1135 })(AI || (AI = {}));
1136 var Microsoft;
1137 (function (Microsoft) {
1138     var ApplicationInsights;
1139     (function (ApplicationInsights) {
1140         var Telemetry;
1141         (function (Telemetry) {
1142             var Common;
1143             (function (Common) {
1144                 "use strict";
1145                 var DataSanitizer = (function () {
1146                     function DataSanitizer() {
1147                     }
1148                     DataSanitizer.sanitizeKeyAndAddUniqueness = function (key, map) {
1149                         var origLength = key.length;
1150                         var field = DataSanitizer.sanitizeKey(key);
1151                         if (field.length !== origLength) {
1152                             var i = 0;
1153                             var uniqueField = field;
1154                             while (map[uniqueField] !== undefined) {
1155                                 i++;
1156                                 uniqueField = field.substring(0, DataSanitizer.MAX_NAME_LENGTH - 3) + DataSanitizer.padNumber(i);
1157                             }
1158                             field = uniqueField;
1159                         }
1160                         return field;
1161                     };
1162                     DataSanitizer.sanitizeKey = function (name) {
1163                         if (name) {
1164                             name = ApplicationInsights.Util.trim(name.toString());
1165                             if (name.search(/[^0-9a-zA-Z-._()\/ ]/g) >= 0) {
1166                                 name = name.replace(/[^0-9a-zA-Z-._()\/ ]/g, "_");
1167                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "name contains illegal characters. Illgeal character have been replaced with '_'. new name: " + name);
1168                             }
1169                             if (name.length > DataSanitizer.MAX_NAME_LENGTH) {
1170                                 name = name.substring(0, DataSanitizer.MAX_NAME_LENGTH);
1171                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "name is too long.  It has been truncated to " + DataSanitizer.MAX_NAME_LENGTH + " characters.  name: " + name);
1172                             }
1173                         }
1174                         return name;
1175                     };
1176                     DataSanitizer.sanitizeString = function (value) {
1177                         if (value) {
1178                             value = ApplicationInsights.Util.trim(value);
1179                             if (value.toString().length > DataSanitizer.MAX_STRING_LENGTH) {
1180                                 value = value.substring(0, DataSanitizer.MAX_STRING_LENGTH);
1181                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "string value is too long. It has been truncated to " + DataSanitizer.MAX_STRING_LENGTH + " characters. value: " + value);
1182                             }
1183                         }
1184                         return value;
1185                     };
1186                     DataSanitizer.sanitizeUrl = function (url) {
1187                         if (url) {
1188                             if (url.length > DataSanitizer.MAX_URL_LENGTH) {
1189                                 url = url.substring(0, DataSanitizer.MAX_URL_LENGTH);
1190                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "url is too long, it has been trucated to " + DataSanitizer.MAX_URL_LENGTH + " characters. url: " + url);
1191                             }
1192                         }
1193                         return url;
1194                     };
1195                     DataSanitizer.sanitizeMessage = function (message) {
1196                         if (message) {
1197                             if (message.length > DataSanitizer.MAX_MESSAGE_LENGTH) {
1198                                 message = message.substring(0, DataSanitizer.MAX_MESSAGE_LENGTH);
1199                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "message is too long, it has been trucated to " + DataSanitizer.MAX_MESSAGE_LENGTH + " characters.  message: " + message);
1200                             }
1201                         }
1202                         return message;
1203                     };
1204                     DataSanitizer.sanitizeException = function (exception) {
1205                         if (exception) {
1206                             if (exception.length > DataSanitizer.MAX_EXCEPTION_LENGTH) {
1207                                 exception = exception.substring(0, DataSanitizer.MAX_EXCEPTION_LENGTH);
1208                                 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "exception is too long, iit has been trucated to " + DataSanitizer.MAX_EXCEPTION_LENGTH + " characters.  exception: " + exception);
1209                             }
1210                         }
1211                         return exception;
1212                     };
1213                     DataSanitizer.sanitizeProperties = function (properties) {
1214                         if (properties) {
1215                             var tempProps = {};
1216                             for (var prop in properties) {
1217                                 var value = DataSanitizer.sanitizeString(properties[prop]);
1218                                 prop = DataSanitizer.sanitizeKeyAndAddUniqueness(prop, tempProps);
1219                                 tempProps[prop] = value;
1220                             }
1221                             properties = tempProps;
1222                         }
1223                         return properties;
1224                     };
1225                     DataSanitizer.sanitizeMeasurements = function (measurements) {
1226                         if (measurements) {
1227                             var tempMeasurements = {};
1228                             for (var measure in measurements) {
1229                                 var value = measurements[measure];
1230                                 measure = DataSanitizer.sanitizeKeyAndAddUniqueness(measure, tempMeasurements);
1231                                 tempMeasurements[measure] = value;
1232                             }
1233                             measurements = tempMeasurements;
1234                         }
1235                         return measurements;
1236                     };
1237                     DataSanitizer.padNumber = function (num) {
1238                         var s = "00" + num;
1239                         return s.substr(s.length - 3);
1240                     };
1241                     DataSanitizer.MAX_NAME_LENGTH = 150;
1242                     DataSanitizer.MAX_STRING_LENGTH = 1024;
1243                     DataSanitizer.MAX_URL_LENGTH = 2048;
1244                     DataSanitizer.MAX_MESSAGE_LENGTH = 32768;
1245                     DataSanitizer.MAX_EXCEPTION_LENGTH = 32768;
1246                     return DataSanitizer;
1247                 })();
1248                 Common.DataSanitizer = DataSanitizer;
1249             })(Common = Telemetry.Common || (Telemetry.Common = {}));
1250         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1251     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1252 })(Microsoft || (Microsoft = {}));
1253 var Microsoft;
1254 (function (Microsoft) {
1255     var ApplicationInsights;
1256     (function (ApplicationInsights) {
1257         var Telemetry;
1258         (function (Telemetry) {
1259             "use strict";
1260             var Trace = (function (_super) {
1261                 __extends(Trace, _super);
1262                 function Trace(message, properties) {
1263                     _super.call(this);
1264                     this.aiDataContract = {
1265                         ver: true,
1266                         message: true,
1267                         severityLevel: false,
1268                         measurements: false,
1269                         properties: false
1270                     };
1271                     message = message || ApplicationInsights.Util.NotSpecified;
1272                     this.message = Telemetry.Common.DataSanitizer.sanitizeMessage(message);
1273                     this.properties = Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1274                 }
1275                 Trace.envelopeType = "Microsoft.ApplicationInsights.Message";
1276                 Trace.dataType = "MessageData";
1277                 return Trace;
1278             })(AI.MessageData);
1279             Telemetry.Trace = Trace;
1280         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1281     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1282 })(Microsoft || (Microsoft = {}));
1283 var AI;
1284 (function (AI) {
1285     "use strict";
1286     var EventData = (function (_super) {
1287         __extends(EventData, _super);
1288         function EventData() {
1289             this.ver = 2;
1290             this.properties = {};
1291             this.measurements = {};
1292             _super.call(this);
1293         }
1294         return EventData;
1295     })(Microsoft.Telemetry.Domain);
1296     AI.EventData = EventData;
1297 })(AI || (AI = {}));
1298 var Microsoft;
1299 (function (Microsoft) {
1300     var ApplicationInsights;
1301     (function (ApplicationInsights) {
1302         var Telemetry;
1303         (function (Telemetry) {
1304             "use strict";
1305             var Event = (function (_super) {
1306                 __extends(Event, _super);
1307                 function Event(name, properties, measurements) {
1308                     _super.call(this);
1309                     this.aiDataContract = {
1310                         ver: true,
1311                         name: true,
1312                         properties: false,
1313                         measurements: false
1314                     };
1315                     this.name = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeString(name);
1316                     this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1317                     this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1318                 }
1319                 Event.envelopeType = "Microsoft.ApplicationInsights.Event";
1320                 Event.dataType = "EventData";
1321                 return Event;
1322             })(AI.EventData);
1323             Telemetry.Event = Event;
1324         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1325     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1326 })(Microsoft || (Microsoft = {}));
1327 var AI;
1328 (function (AI) {
1329     "use strict";
1330     var ExceptionDetails = (function () {
1331         function ExceptionDetails() {
1332             this.hasFullStack = true;
1333             this.parsedStack = [];
1334         }
1335         return ExceptionDetails;
1336     })();
1337     AI.ExceptionDetails = ExceptionDetails;
1338 })(AI || (AI = {}));
1339 var AI;
1340 (function (AI) {
1341     "use strict";
1342     var ExceptionData = (function (_super) {
1343         __extends(ExceptionData, _super);
1344         function ExceptionData() {
1345             this.ver = 2;
1346             this.exceptions = [];
1347             this.properties = {};
1348             this.measurements = {};
1349             _super.call(this);
1350         }
1351         return ExceptionData;
1352     })(Microsoft.Telemetry.Domain);
1353     AI.ExceptionData = ExceptionData;
1354 })(AI || (AI = {}));
1355 var AI;
1356 (function (AI) {
1357     "use strict";
1358     var StackFrame = (function () {
1359         function StackFrame() {
1360         }
1361         return StackFrame;
1362     })();
1363     AI.StackFrame = StackFrame;
1364 })(AI || (AI = {}));
1365 var Microsoft;
1366 (function (Microsoft) {
1367     var ApplicationInsights;
1368     (function (ApplicationInsights) {
1369         var Telemetry;
1370         (function (Telemetry) {
1371             "use strict";
1372             var Exception = (function (_super) {
1373                 __extends(Exception, _super);
1374                 function Exception(exception, handledAt, properties, measurements) {
1375                     _super.call(this);
1376                     this.aiDataContract = {
1377                         ver: true,
1378                         handledAt: true,
1379                         exceptions: true,
1380                         severityLevel: false,
1381                         properties: false,
1382                         measurements: false
1383                     };
1384                     this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1385                     this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1386                     this.handledAt = handledAt || "unhandled";
1387                     this.exceptions = [new _ExceptionDetails(exception)];
1388                 }
1389                 Exception.CreateSimpleException = function (message, typeName, assembly, fileName, details, line, handledAt) {
1390                     var exceptionTelemetry;
1391                     try {
1392                         throw new Error();
1393                     }
1394                     catch (e) {
1395                         exceptionTelemetry = new Telemetry.Exception(e);
1396                     }
1397                     var stack = exceptionTelemetry.exceptions[0].parsedStack[0];
1398                     stack.assembly = assembly;
1399                     stack.fileName = fileName;
1400                     stack.level = 0;
1401                     stack.line = line;
1402                     stack.method = "unknown";
1403                     var exception = exceptionTelemetry.exceptions[0];
1404                     exception.hasFullStack = true;
1405                     exception.message = message;
1406                     exception.parsedStack = null;
1407                     exception.stack = details;
1408                     exception.typeName = typeName;
1409                     exceptionTelemetry.handledAt = handledAt || "unhandled";
1410                     return exceptionTelemetry;
1411                 };
1412                 Exception.envelopeType = "Microsoft.ApplicationInsights.Exception";
1413                 Exception.dataType = "ExceptionData";
1414                 return Exception;
1415             })(AI.ExceptionData);
1416             Telemetry.Exception = Exception;
1417             var _ExceptionDetails = (function (_super) {
1418                 __extends(_ExceptionDetails, _super);
1419                 function _ExceptionDetails(exception) {
1420                     _super.call(this);
1421                     this.aiDataContract = {
1422                         id: false,
1423                         outerId: false,
1424                         typeName: true,
1425                         message: true,
1426                         hasFullStack: false,
1427                         stack: false,
1428                         parsedStack: []
1429                     };
1430                     this.typeName = Telemetry.Common.DataSanitizer.sanitizeString(exception.name || ApplicationInsights.Util.NotSpecified);
1431                     this.message = Telemetry.Common.DataSanitizer.sanitizeMessage(exception.message || ApplicationInsights.Util.NotSpecified);
1432                     var stack = exception["stack"];
1433                     this.parsedStack = this.parseStack(stack);
1434                     this.stack = Telemetry.Common.DataSanitizer.sanitizeException(stack);
1435                     this.hasFullStack = ApplicationInsights.Util.isArray(this.parsedStack) && this.parsedStack.length > 0;
1436                 }
1437                 _ExceptionDetails.prototype.parseStack = function (stack) {
1438                     var parsedStack = undefined;
1439                     if (typeof stack === "string") {
1440                         var frames = stack.split('\n');
1441                         parsedStack = [];
1442                         var level = 0;
1443                         var totalSizeInBytes = 0;
1444                         for (var i = 0; i <= frames.length; i++) {
1445                             var frame = frames[i];
1446                             if (_StackFrame.regex.test(frame)) {
1447                                 var parsedFrame = new _StackFrame(frames[i], level++);
1448                                 totalSizeInBytes += parsedFrame.sizeInBytes;
1449                                 parsedStack.push(parsedFrame);
1450                             }
1451                         }
1452                         var exceptionParsedStackThreshold = 32 * 1024;
1453                         if (totalSizeInBytes > exceptionParsedStackThreshold) {
1454                             var left = 0;
1455                             var right = parsedStack.length - 1;
1456                             var size = 0;
1457                             var acceptedLeft = left;
1458                             var acceptedRight = right;
1459                             while (left < right) {
1460                                 var lSize = parsedStack[left].sizeInBytes;
1461                                 var rSize = parsedStack[right].sizeInBytes;
1462                                 size += lSize + rSize;
1463                                 if (size > exceptionParsedStackThreshold) {
1464                                     var howMany = acceptedRight - acceptedLeft + 1;
1465                                     parsedStack.splice(acceptedLeft, howMany);
1466                                     break;
1467                                 }
1468                                 acceptedLeft = left;
1469                                 acceptedRight = right;
1470                                 left++;
1471                                 right--;
1472                             }
1473                         }
1474                     }
1475                     return parsedStack;
1476                 };
1477                 return _ExceptionDetails;
1478             })(AI.ExceptionDetails);
1479             var _StackFrame = (function (_super) {
1480                 __extends(_StackFrame, _super);
1481                 function _StackFrame(frame, level) {
1482                     _super.call(this);
1483                     this.sizeInBytes = 0;
1484                     this.aiDataContract = {
1485                         level: true,
1486                         method: true,
1487                         assembly: false,
1488                         fileName: false,
1489                         line: false
1490                     };
1491                     this.level = level;
1492                     this.method = "unavailable";
1493                     this.assembly = ApplicationInsights.Util.trim(frame);
1494                     var matches = frame.match(_StackFrame.regex);
1495                     if (matches && matches.length >= 5) {
1496                         this.method = ApplicationInsights.Util.trim(matches[2]);
1497                         this.fileName = ApplicationInsights.Util.trim(matches[4]);
1498                         this.line = parseInt(matches[5]) || 0;
1499                     }
1500                     this.sizeInBytes += this.method.length;
1501                     this.sizeInBytes += this.fileName.length;
1502                     this.sizeInBytes += this.assembly.length;
1503                     this.sizeInBytes += _StackFrame.baseSize;
1504                     this.sizeInBytes += this.level.toString().length;
1505                     this.sizeInBytes += this.line.toString().length;
1506                 }
1507                 _StackFrame.regex = /^([\s]+at)?(.*?)(\@|\s\(|\s)([^\(\@\n]+):([0-9]+):([0-9]+)(\)?)$/;
1508                 _StackFrame.baseSize = 58;
1509                 return _StackFrame;
1510             })(AI.StackFrame);
1511         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1512     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1513 })(Microsoft || (Microsoft = {}));
1514 var AI;
1515 (function (AI) {
1516     "use strict";
1517     var MetricData = (function (_super) {
1518         __extends(MetricData, _super);
1519         function MetricData() {
1520             this.ver = 2;
1521             this.metrics = [];
1522             this.properties = {};
1523             _super.call(this);
1524         }
1525         return MetricData;
1526     })(Microsoft.Telemetry.Domain);
1527     AI.MetricData = MetricData;
1528 })(AI || (AI = {}));
1529 var AI;
1530 (function (AI) {
1531     "use strict";
1532     (function (DataPointType) {
1533         DataPointType[DataPointType["Measurement"] = 0] = "Measurement";
1534         DataPointType[DataPointType["Aggregation"] = 1] = "Aggregation";
1535     })(AI.DataPointType || (AI.DataPointType = {}));
1536     var DataPointType = AI.DataPointType;
1537 })(AI || (AI = {}));
1538 var AI;
1539 (function (AI) {
1540     "use strict";
1541     var DataPoint = (function () {
1542         function DataPoint() {
1543             this.kind = 0 /* Measurement */;
1544         }
1545         return DataPoint;
1546     })();
1547     AI.DataPoint = DataPoint;
1548 })(AI || (AI = {}));
1549 var Microsoft;
1550 (function (Microsoft) {
1551     var ApplicationInsights;
1552     (function (ApplicationInsights) {
1553         var Telemetry;
1554         (function (Telemetry) {
1555             var Common;
1556             (function (Common) {
1557                 "use strict";
1558                 var DataPoint = (function (_super) {
1559                     __extends(DataPoint, _super);
1560                     function DataPoint() {
1561                         _super.apply(this, arguments);
1562                         this.aiDataContract = {
1563                             name: true,
1564                             kind: false,
1565                             value: true,
1566                             count: false,
1567                             min: false,
1568                             max: false,
1569                             stdDev: false
1570                         };
1571                     }
1572                     return DataPoint;
1573                 })(AI.DataPoint);
1574                 Common.DataPoint = DataPoint;
1575             })(Common = Telemetry.Common || (Telemetry.Common = {}));
1576         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1577     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1578 })(Microsoft || (Microsoft = {}));
1579 var Microsoft;
1580 (function (Microsoft) {
1581     var ApplicationInsights;
1582     (function (ApplicationInsights) {
1583         var Telemetry;
1584         (function (Telemetry) {
1585             "use strict";
1586             var Metric = (function (_super) {
1587                 __extends(Metric, _super);
1588                 function Metric(name, value, count, min, max, properties) {
1589                     _super.call(this);
1590                     this.aiDataContract = {
1591                         ver: true,
1592                         metrics: true,
1593                         properties: false
1594                     };
1595                     var dataPoint = new Microsoft.ApplicationInsights.Telemetry.Common.DataPoint();
1596                     dataPoint.count = count > 0 ? count : undefined;
1597                     dataPoint.max = isNaN(max) || max === null ? undefined : max;
1598                     dataPoint.min = isNaN(min) || min === null ? undefined : min;
1599                     dataPoint.name = Telemetry.Common.DataSanitizer.sanitizeString(name);
1600                     dataPoint.value = value;
1601                     this.metrics = [dataPoint];
1602                     this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1603                 }
1604                 Metric.envelopeType = "Microsoft.ApplicationInsights.Metric";
1605                 Metric.dataType = "MetricData";
1606                 return Metric;
1607             })(AI.MetricData);
1608             Telemetry.Metric = Metric;
1609         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1610     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1611 })(Microsoft || (Microsoft = {}));
1612 var AI;
1613 (function (AI) {
1614     "use strict";
1615     var PageViewData = (function (_super) {
1616         __extends(PageViewData, _super);
1617         function PageViewData() {
1618             this.ver = 2;
1619             this.properties = {};
1620             this.measurements = {};
1621             _super.call(this);
1622         }
1623         return PageViewData;
1624     })(AI.EventData);
1625     AI.PageViewData = PageViewData;
1626 })(AI || (AI = {}));
1627 var Microsoft;
1628 (function (Microsoft) {
1629     var ApplicationInsights;
1630     (function (ApplicationInsights) {
1631         var Telemetry;
1632         (function (Telemetry) {
1633             "use strict";
1634             var PageView = (function (_super) {
1635                 __extends(PageView, _super);
1636                 function PageView(name, url, durationMs, properties, measurements) {
1637                     _super.call(this);
1638                     this.aiDataContract = {
1639                         ver: true,
1640                         name: false,
1641                         url: false,
1642                         duration: false,
1643                         properties: false,
1644                         measurements: false
1645                     };
1646                     this.url = Telemetry.Common.DataSanitizer.sanitizeUrl(url);
1647                     this.name = Telemetry.Common.DataSanitizer.sanitizeString(name || ApplicationInsights.Util.NotSpecified);
1648                     if (!isNaN(durationMs)) {
1649                         this.duration = ApplicationInsights.Util.msToTimeSpan(durationMs);
1650                     }
1651                     this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1652                     this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1653                 }
1654                 PageView.envelopeType = "Microsoft.ApplicationInsights.Pageview";
1655                 PageView.dataType = "PageviewData";
1656                 return PageView;
1657             })(AI.PageViewData);
1658             Telemetry.PageView = PageView;
1659         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1660     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1661 })(Microsoft || (Microsoft = {}));
1662 var AI;
1663 (function (AI) {
1664     "use strict";
1665     var PageViewPerfData = (function (_super) {
1666         __extends(PageViewPerfData, _super);
1667         function PageViewPerfData() {
1668             this.ver = 2;
1669             this.properties = {};
1670             this.measurements = {};
1671             _super.call(this);
1672         }
1673         return PageViewPerfData;
1674     })(AI.PageViewData);
1675     AI.PageViewPerfData = PageViewPerfData;
1676 })(AI || (AI = {}));
1677 var Microsoft;
1678 (function (Microsoft) {
1679     var ApplicationInsights;
1680     (function (ApplicationInsights) {
1681         var Telemetry;
1682         (function (Telemetry) {
1683             "use strict";
1684             var PageViewPerformance = (function (_super) {
1685                 __extends(PageViewPerformance, _super);
1686                 function PageViewPerformance(name, url, durationMs, properties, measurements) {
1687                     _super.call(this);
1688                     this.aiDataContract = {
1689                         ver: true,
1690                         name: false,
1691                         url: false,
1692                         duration: false,
1693                         perfTotal: false,
1694                         networkConnect: false,
1695                         sentRequest: false,
1696                         receivedResponse: false,
1697                         domProcessing: false,
1698                         properties: false,
1699                         measurements: false
1700                     };
1701                     this.isValid = false;
1702                     var timing = PageViewPerformance.getPerformanceTiming();
1703                     if (timing) {
1704                         var total = PageViewPerformance.getDuration(timing.navigationStart, timing.loadEventEnd);
1705                         var network = PageViewPerformance.getDuration(timing.navigationStart, timing.connectEnd);
1706                         var request = PageViewPerformance.getDuration(timing.requestStart, timing.responseStart);
1707                         var response = PageViewPerformance.getDuration(timing.responseStart, timing.responseEnd);
1708                         var dom = PageViewPerformance.getDuration(timing.responseEnd, timing.loadEventEnd);
1709                         if (total == 0) {
1710                             ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "error calculating page view performance: total='" + total + "', network='" + network + "', request='" + request + "', response='" + response + "', dom='" + dom + "'");
1711                         }
1712                         else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {
1713                             ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "client performance math error:" + total + " < " + network + " + " + request + " + " + response + " + " + dom);
1714                         }
1715                         else {
1716                             durationMs = total;
1717                             this.perfTotal = ApplicationInsights.Util.msToTimeSpan(total);
1718                             this.networkConnect = ApplicationInsights.Util.msToTimeSpan(network);
1719                             this.sentRequest = ApplicationInsights.Util.msToTimeSpan(request);
1720                             this.receivedResponse = ApplicationInsights.Util.msToTimeSpan(response);
1721                             this.domProcessing = ApplicationInsights.Util.msToTimeSpan(dom);
1722                             this.isValid = true;
1723                         }
1724                     }
1725                     this.url = Telemetry.Common.DataSanitizer.sanitizeUrl(url);
1726                     this.name = Telemetry.Common.DataSanitizer.sanitizeString(name || ApplicationInsights.Util.NotSpecified);
1727                     if (!isNaN(durationMs)) {
1728                         this.duration = ApplicationInsights.Util.msToTimeSpan(durationMs);
1729                     }
1730                     this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1731                     this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1732                 }
1733                 PageViewPerformance.getPerformanceTiming = function () {
1734                     if (typeof window != "undefined" && window.performance && window.performance.timing) {
1735                         return window.performance.timing;
1736                     }
1737                     return null;
1738                 };
1739                 PageViewPerformance.isPerformanceTimingSupported = function () {
1740                     return typeof window != "undefined" && window.performance && window.performance.timing;
1741                 };
1742                 PageViewPerformance.isPerformanceTimingDataReady = function () {
1743                     var timing = window.performance.timing;
1744                     return timing.domainLookupStart > 0 && timing.navigationStart > 0 && timing.responseStart > 0 && timing.requestStart > 0 && timing.loadEventEnd > 0 && timing.responseEnd > 0 && timing.connectEnd > 0 && timing.domLoading > 0;
1745                 };
1746                 PageViewPerformance.getDuration = function (start, end) {
1747                     var duration = 0;
1748                     if (!(isNaN(start) || isNaN(end))) {
1749                         duration = Math.max(end - start, 0);
1750                     }
1751                     return duration;
1752                 };
1753                 PageViewPerformance.envelopeType = "Microsoft.ApplicationInsights.PageviewPerformance";
1754                 PageViewPerformance.dataType = "PageviewPerformanceData";
1755                 return PageViewPerformance;
1756             })(AI.PageViewPerfData);
1757             Telemetry.PageViewPerformance = PageViewPerformance;
1758         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1759     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1760 })(Microsoft || (Microsoft = {}));
1761 var AI;
1762 (function (AI) {
1763     "use strict";
1764     var SessionStateData = (function (_super) {
1765         __extends(SessionStateData, _super);
1766         function SessionStateData() {
1767             this.ver = 2;
1768             this.state = 0 /* Start */;
1769             _super.call(this);
1770         }
1771         return SessionStateData;
1772     })(Microsoft.Telemetry.Domain);
1773     AI.SessionStateData = SessionStateData;
1774 })(AI || (AI = {}));
1775 var Microsoft;
1776 (function (Microsoft) {
1777     var ApplicationInsights;
1778     (function (ApplicationInsights) {
1779         var Telemetry;
1780         (function (Telemetry) {
1781             "use strict";
1782             var SessionTelemetry = (function (_super) {
1783                 __extends(SessionTelemetry, _super);
1784                 function SessionTelemetry(state) {
1785                     _super.call(this);
1786                     this.aiDataContract = {
1787                         ver: true,
1788                         state: true
1789                     };
1790                     this.state = state;
1791                 }
1792                 SessionTelemetry.envelopeType = "Microsoft.ApplicationInsights.SessionState";
1793                 SessionTelemetry.dataType = "SessionStateData";
1794                 return SessionTelemetry;
1795             })(AI.SessionStateData);
1796             Telemetry.SessionTelemetry = SessionTelemetry;
1797         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1798     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1799 })(Microsoft || (Microsoft = {}));
1800 var Microsoft;
1801 (function (Microsoft) {
1802     var ApplicationInsights;
1803     (function (ApplicationInsights) {
1804         "use strict";
1805         var TelemetryContext = (function () {
1806             function TelemetryContext(config) {
1807                 var _this = this;
1808                 this._config = config;
1809                 this._sender = new ApplicationInsights.Sender(config);
1810                 if (typeof window !== 'undefined') {
1811                     this._sessionManager = new ApplicationInsights.Context._SessionManager(config, function (sessionState, timestamp) { return TelemetryContext._sessionHandler(_this, sessionState, timestamp); });
1812                     this.application = new ApplicationInsights.Context.Application();
1813                     this.device = new ApplicationInsights.Context.Device();
1814                     this.internal = new ApplicationInsights.Context.Internal();
1815                     this.location = new ApplicationInsights.Context.Location();
1816                     this.user = new ApplicationInsights.Context.User(config.accountId());
1817                     this.operation = new ApplicationInsights.Context.Operation();
1818                     this.session = new ApplicationInsights.Context.Session();
1819                     this.sample = new ApplicationInsights.Context.Sample(config.sampleRate());
1820                 }
1821             }
1822             TelemetryContext.prototype.addTelemetryInitializer = function (telemetryInitializer) {
1823                 this.telemetryInitializers = this.telemetryInitializers || [];
1824                 this.telemetryInitializers.push(telemetryInitializer);
1825             };
1826             TelemetryContext.prototype.track = function (envelope) {
1827                 if (!envelope) {
1828                     ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "cannot call .track() with a null or undefined argument");
1829                 }
1830                 else {
1831                     if (envelope.name === ApplicationInsights.Telemetry.PageView.envelopeType) {
1832                         ApplicationInsights._InternalLogging.resetInternalMessageCount();
1833                     }
1834                     if (this.session) {
1835                         if (typeof this.session.id !== "string") {
1836                             this._sessionManager.update();
1837                         }
1838                     }
1839                     this._track(envelope);
1840                 }
1841                 return envelope;
1842             };
1843             TelemetryContext.prototype._track = function (envelope) {
1844                 if (this.session) {
1845                     if (typeof this.session.id === "string") {
1846                         this._applySessionContext(envelope, this.session);
1847                     }
1848                     else {
1849                         this._applySessionContext(envelope, this._sessionManager.automaticSession);
1850                     }
1851                 }
1852                 this._applyApplicationContext(envelope, this.application);
1853                 this._applyDeviceContext(envelope, this.device);
1854                 this._applyInternalContext(envelope, this.internal);
1855                 this._applyLocationContext(envelope, this.location);
1856                 this._applySampleContext(envelope, this.sample);
1857                 this._applyUserContext(envelope, this.user);
1858                 this._applyOperationContext(envelope, this.operation);
1859                 envelope.iKey = this._config.instrumentationKey();
1860                 var telemetryInitializersFailed = false;
1861                 try {
1862                     this.telemetryInitializers = this.telemetryInitializers || [];
1863                     var telemetryInitializersCount = this.telemetryInitializers.length;
1864                     for (var i = 0; i < telemetryInitializersCount; ++i) {
1865                         var telemetryInitializer = this.telemetryInitializers[i];
1866                         if (telemetryInitializer) {
1867                             telemetryInitializer.apply(null, [envelope]);
1868                         }
1869                     }
1870                 }
1871                 catch (e) {
1872                     telemetryInitializersFailed = true;
1873                     ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "One of telemetry initializers failed, telemetry item will not be sent: " + ApplicationInsights.Util.dump(e));
1874                 }
1875                 if (!telemetryInitializersFailed) {
1876                     if (envelope.name === ApplicationInsights.Telemetry.SessionTelemetry.envelopeType || envelope.name === ApplicationInsights.Telemetry.Metric.envelopeType || this.sample.isSampledIn(envelope)) {
1877                         this._sender.send(envelope);
1878                     }
1879                     else {
1880                         ApplicationInsights._InternalLogging.logInternalMessage(1 /* WARNING */, "Telemetry is sampled and not sent to the AI service. SampleRate is " + this.sample.sampleRate);
1881                     }
1882                 }
1883                 return envelope;
1884             };
1885             TelemetryContext._sessionHandler = function (tc, sessionState, timestamp) {
1886                 var sessionStateTelemetry = new ApplicationInsights.Telemetry.SessionTelemetry(sessionState);
1887                 var sessionStateData = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.SessionTelemetry.dataType, sessionStateTelemetry);
1888                 var sessionStateEnvelope = new ApplicationInsights.Telemetry.Common.Envelope(sessionStateData, ApplicationInsights.Telemetry.SessionTelemetry.envelopeType);
1889                 sessionStateEnvelope.time = ApplicationInsights.Util.toISOStringForIE8(new Date(timestamp));
1890                 tc._track(sessionStateEnvelope);
1891             };
1892             TelemetryContext.prototype._applyApplicationContext = function (envelope, appContext) {
1893                 if (appContext) {
1894                     var tagKeys = new AI.ContextTagKeys();
1895                     if (typeof appContext.ver === "string") {
1896                         envelope.tags[tagKeys.applicationVersion] = appContext.ver;
1897                     }
1898                     if (typeof appContext.build === "string") {
1899                         envelope.tags[tagKeys.applicationBuild] = appContext.build;
1900                     }
1901                 }
1902             };
1903             TelemetryContext.prototype._applyDeviceContext = function (envelope, deviceContext) {
1904                 var tagKeys = new AI.ContextTagKeys();
1905                 if (deviceContext) {
1906                     if (typeof deviceContext.id === "string") {
1907                         envelope.tags[tagKeys.deviceId] = deviceContext.id;
1908                     }
1909                     if (typeof deviceContext.ip === "string") {
1910                         envelope.tags[tagKeys.deviceIp] = deviceContext.ip;
1911                     }
1912                     if (typeof deviceContext.language === "string") {
1913                         envelope.tags[tagKeys.deviceLanguage] = deviceContext.language;
1914                     }
1915                     if (typeof deviceContext.locale === "string") {
1916                         envelope.tags[tagKeys.deviceLocale] = deviceContext.locale;
1917                     }
1918                     if (typeof deviceContext.model === "string") {
1919                         envelope.tags[tagKeys.deviceModel] = deviceContext.model;
1920                     }
1921                     if (typeof deviceContext.network !== "undefined") {
1922                         envelope.tags[tagKeys.deviceNetwork] = deviceContext.network;
1923                     }
1924                     if (typeof deviceContext.oemName === "string") {
1925                         envelope.tags[tagKeys.deviceOEMName] = deviceContext.oemName;
1926                     }
1927                     if (typeof deviceContext.os === "string") {
1928                         envelope.tags[tagKeys.deviceOS] = deviceContext.os;
1929                     }
1930                     if (typeof deviceContext.osversion === "string") {
1931                         envelope.tags[tagKeys.deviceOSVersion] = deviceContext.osversion;
1932                     }
1933                     if (typeof deviceContext.resolution === "string") {
1934                         envelope.tags[tagKeys.deviceScreenResolution] = deviceContext.resolution;
1935                     }
1936                     if (typeof deviceContext.type === "string") {
1937                         envelope.tags[tagKeys.deviceType] = deviceContext.type;
1938                     }
1939                 }
1940             };
1941             TelemetryContext.prototype._applyInternalContext = function (envelope, internalContext) {
1942                 if (internalContext) {
1943                     var tagKeys = new AI.ContextTagKeys();
1944                     if (typeof internalContext.agentVersion === "string") {
1945                         envelope.tags[tagKeys.internalAgentVersion] = internalContext.agentVersion;
1946                     }
1947                     if (typeof internalContext.sdkVersion === "string") {
1948                         envelope.tags[tagKeys.internalSdkVersion] = internalContext.sdkVersion;
1949                     }
1950                 }
1951             };
1952             TelemetryContext.prototype._applyLocationContext = function (envelope, locationContext) {
1953                 if (locationContext) {
1954                     var tagKeys = new AI.ContextTagKeys();
1955                     if (typeof locationContext.ip === "string") {
1956                         envelope.tags[tagKeys.locationIp] = locationContext.ip;
1957                     }
1958                 }
1959             };
1960             TelemetryContext.prototype._applyOperationContext = function (envelope, operationContext) {
1961                 if (operationContext) {
1962                     var tagKeys = new AI.ContextTagKeys();
1963                     if (typeof operationContext.id === "string") {
1964                         envelope.tags[tagKeys.operationId] = operationContext.id;
1965                     }
1966                     if (typeof operationContext.name === "string") {
1967                         envelope.tags[tagKeys.operationName] = operationContext.name;
1968                     }
1969                     if (typeof operationContext.parentId === "string") {
1970                         envelope.tags[tagKeys.operationParentId] = operationContext.parentId;
1971                     }
1972                     if (typeof operationContext.rootId === "string") {
1973                         envelope.tags[tagKeys.operationRootId] = operationContext.rootId;
1974                     }
1975                     if (typeof operationContext.syntheticSource === "string") {
1976                         envelope.tags[tagKeys.operationSyntheticSource] = operationContext.syntheticSource;
1977                     }
1978                 }
1979             };
1980             TelemetryContext.prototype._applySampleContext = function (envelope, sampleContext) {
1981                 if (sampleContext) {
1982                     var tagKeys = new AI.ContextTagKeys();
1983                     envelope.tags[tagKeys.sampleRate] = sampleContext.sampleRate;
1984                 }
1985             };
1986             TelemetryContext.prototype._applySessionContext = function (envelope, sessionContext) {
1987                 if (sessionContext) {
1988                     var tagKeys = new AI.ContextTagKeys();
1989                     if (typeof sessionContext.id === "string") {
1990                         envelope.tags[tagKeys.sessionId] = sessionContext.id;
1991                     }
1992                     if (typeof sessionContext.isFirst !== "undefined") {
1993                         envelope.tags[tagKeys.sessionIsFirst] = sessionContext.isFirst;
1994                     }
1995                 }
1996             };
1997             TelemetryContext.prototype._applyUserContext = function (envelope, userContext) {
1998                 if (userContext) {
1999                     var tagKeys = new AI.ContextTagKeys();
2000                     if (typeof userContext.accountAcquisitionDate === "string") {
2001                         envelope.tags[tagKeys.userAccountAcquisitionDate] = userContext.accountAcquisitionDate;
2002                     }
2003                     if (typeof userContext.accountId === "string") {
2004                         envelope.tags[tagKeys.userAccountId] = userContext.accountId;
2005                     }
2006                     if (typeof userContext.agent === "string") {
2007                         envelope.tags[tagKeys.userAgent] = userContext.agent;
2008                     }
2009                     if (typeof userContext.id === "string") {
2010                         envelope.tags[tagKeys.userId] = userContext.id;
2011                     }
2012                     if (typeof userContext.authenticatedId === "string") {
2013                         envelope.tags[tagKeys.userAuthUserId] = userContext.authenticatedId;
2014                     }
2015                     if (typeof userContext.storeRegion === "string") {
2016                         envelope.tags[tagKeys.userStoreRegion] = userContext.storeRegion;
2017                     }
2018                 }
2019             };
2020             return TelemetryContext;
2021         })();
2022         ApplicationInsights.TelemetryContext = TelemetryContext;
2023     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2024 })(Microsoft || (Microsoft = {}));
2025 var Microsoft;
2026 (function (Microsoft) {
2027     var Telemetry;
2028     (function (Telemetry) {
2029         "use strict";
2030         var Data = (function (_super) {
2031             __extends(Data, _super);
2032             function Data() {
2033                 _super.call(this);
2034             }
2035             return Data;
2036         })(Microsoft.Telemetry.Base);
2037         Telemetry.Data = Data;
2038     })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
2039 })(Microsoft || (Microsoft = {}));
2040 var Microsoft;
2041 (function (Microsoft) {
2042     var ApplicationInsights;
2043     (function (ApplicationInsights) {
2044         var Telemetry;
2045         (function (Telemetry) {
2046             var Common;
2047             (function (Common) {
2048                 "use strict";
2049                 var Data = (function (_super) {
2050                     __extends(Data, _super);
2051                     function Data(type, data) {
2052                         _super.call(this);
2053                         this.aiDataContract = {
2054                             baseType: true,
2055                             baseData: true
2056                         };
2057                         this.baseType = type;
2058                         this.baseData = data;
2059                     }
2060                     return Data;
2061                 })(Microsoft.Telemetry.Data);
2062                 Common.Data = Data;
2063             })(Common = Telemetry.Common || (Telemetry.Common = {}));
2064         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
2065     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2066 })(Microsoft || (Microsoft = {}));
2067 var Microsoft;
2068 (function (Microsoft) {
2069     var ApplicationInsights;
2070     (function (ApplicationInsights) {
2071         var Telemetry;
2072         (function (Telemetry) {
2073             "use strict";
2074             var PageVisitTimeManager = (function () {
2075                 function PageVisitTimeManager(pageVisitTimeTrackingHandler) {
2076                     this.prevPageVisitDataKeyName = "prevPageVisitData";
2077                     this.pageVisitTimeTrackingHandler = pageVisitTimeTrackingHandler;
2078                 }
2079                 PageVisitTimeManager.prototype.trackPreviousPageVisit = function (currentPageName, currentPageUrl) {
2080                     try {
2081                         var prevPageVisitTimeData = this.restartPageVisitTimer(currentPageName, currentPageUrl);
2082                         if (prevPageVisitTimeData) {
2083                             this.pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);
2084                         }
2085                     }
2086                     catch (e) {
2087                         ApplicationInsights._InternalLogging.warnToConsole("Auto track page visit time failed, metric will not be collected: " + ApplicationInsights.Util.dump(e));
2088                     }
2089                 };
2090                 PageVisitTimeManager.prototype.restartPageVisitTimer = function (pageName, pageUrl) {
2091                     try {
2092                         var prevPageVisitData = this.stopPageVisitTimer();
2093                         this.startPageVisitTimer(pageName, pageUrl);
2094                         return prevPageVisitData;
2095                     }
2096                     catch (e) {
2097                         ApplicationInsights._InternalLogging.warnToConsole("Call to restart failed: " + ApplicationInsights.Util.dump(e));
2098                         return null;
2099                     }
2100                 };
2101                 PageVisitTimeManager.prototype.startPageVisitTimer = function (pageName, pageUrl) {
2102                     try {
2103                         if (ApplicationInsights.Util.canUseSessionStorage()) {
2104                             if (ApplicationInsights.Util.getSessionStorage(this.prevPageVisitDataKeyName) != null) {
2105                                 throw new Error("Cannot call startPageVisit consecutively without first calling stopPageVisit");
2106                             }
2107                             var currPageVisitData = new PageVisitData(pageName, pageUrl);
2108                             var currPageVisitDataStr = JSON.stringify(currPageVisitData);
2109                             ApplicationInsights.Util.setSessionStorage(this.prevPageVisitDataKeyName, currPageVisitDataStr);
2110                         }
2111                     }
2112                     catch (e) {
2113                         ApplicationInsights._InternalLogging.warnToConsole("Call to start failed: " + ApplicationInsights.Util.dump(e));
2114                     }
2115                 };
2116                 PageVisitTimeManager.prototype.stopPageVisitTimer = function () {
2117                     try {
2118                         if (ApplicationInsights.Util.canUseSessionStorage()) {
2119                             var pageVisitEndTime = Date.now();
2120                             var pageVisitDataJsonStr = ApplicationInsights.Util.getSessionStorage(this.prevPageVisitDataKeyName);
2121                             if (pageVisitDataJsonStr) {
2122                                 var prevPageVisitData = JSON.parse(pageVisitDataJsonStr);
2123                                 prevPageVisitData.pageVisitTime = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;
2124                                 ApplicationInsights.Util.removeSessionStorage(this.prevPageVisitDataKeyName);
2125                                 return prevPageVisitData;
2126                             }
2127                             else {
2128                                 return null;
2129                             }
2130                         }
2131                         return null;
2132                     }
2133                     catch (e) {
2134                         ApplicationInsights._InternalLogging.warnToConsole("Stop page visit timer failed: " + ApplicationInsights.Util.dump(e));
2135                         return null;
2136                     }
2137                 };
2138                 return PageVisitTimeManager;
2139             })();
2140             Telemetry.PageVisitTimeManager = PageVisitTimeManager;
2141             var PageVisitData = (function () {
2142                 function PageVisitData(pageName, pageUrl) {
2143                     this.pageVisitStartTime = Date.now();
2144                     this.pageName = pageName;
2145                     this.pageUrl = pageUrl;
2146                 }
2147                 return PageVisitData;
2148             })();
2149             Telemetry.PageVisitData = PageVisitData;
2150         })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
2151     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2152 })(Microsoft || (Microsoft = {}));
2153 var Microsoft;
2154 (function (Microsoft) {
2155     var ApplicationInsights;
2156     (function (ApplicationInsights) {
2157         "use strict";
2158         ApplicationInsights.Version = "0.18.0";
2159         var AppInsights = (function () {
2160             function AppInsights(config) {
2161                 var _this = this;
2162                 this.config = config || {};
2163                 var defaults = AppInsights.defaultConfig;
2164                 if (defaults !== undefined) {
2165                     for (var field in defaults) {
2166                         if (this.config[field] === undefined) {
2167                             this.config[field] = defaults[field];
2168                         }
2169                     }
2170                 }
2171                 ApplicationInsights._InternalLogging.verboseLogging = function () { return _this.config.verboseLogging; };
2172                 ApplicationInsights._InternalLogging.enableDebugExceptions = function () { return _this.config.enableDebug; };
2173                 var configGetters = {
2174                     instrumentationKey: function () { return _this.config.instrumentationKey; },
2175                     accountId: function () { return _this.config.accountId; },
2176                     appUserId: function () { return _this.config.appUserId; },
2177                     sessionRenewalMs: function () { return _this.config.sessionRenewalMs; },
2178                     sessionExpirationMs: function () { return _this.config.sessionExpirationMs; },
2179                     endpointUrl: function () { return _this.config.endpointUrl; },
2180                     emitLineDelimitedJson: function () { return _this.config.emitLineDelimitedJson; },
2181                     maxBatchSizeInBytes: function () { return _this.config.maxBatchSizeInBytes; },
2182                     maxBatchInterval: function () { return _this.config.maxBatchInterval; },
2183                     disableTelemetry: function () { return _this.config.disableTelemetry; },
2184                     sampleRate: function () { return _this.config.samplingPercentage; }
2185                 };
2186                 this.context = new ApplicationInsights.TelemetryContext(configGetters);
2187                 this._eventTracking = new Timing("trackEvent");
2188                 this._eventTracking.action = function (name, url, duration, properties, measurements) {
2189                     var event = new ApplicationInsights.Telemetry.Event(name, properties, measurements);
2190                     var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Event.dataType, event);
2191                     var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Event.envelopeType);
2192                     _this.context.track(envelope);
2193                 };
2194                 this._pageTracking = new Timing("trackPageView");
2195                 this._pageTracking.action = function (name, url, duration, properties, measurements) {
2196                     _this.sendPageViewInternal(name, url, duration, properties, measurements);
2197                 };
2198                 this._pageVisitTimeManager = new ApplicationInsights.Telemetry.PageVisitTimeManager(function (pageName, pageUrl, pageVisitTime) { return _this.trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
2199             }
2200             AppInsights.prototype.sendPageViewInternal = function (name, url, duration, properties, measurements) {
2201                 var pageView = new ApplicationInsights.Telemetry.PageView(name, url, duration, properties, measurements);
2202                 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.PageView.dataType, pageView);
2203                 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.PageView.envelopeType);
2204                 this.context.track(envelope);
2205             };
2206             AppInsights.prototype.startTrackPage = function (name) {
2207                 try {
2208                     if (typeof name !== "string") {
2209                         name = window.document && window.document.title || "";
2210                     }
2211                     this._pageTracking.start(name);
2212                 }
2213                 catch (e) {
2214                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "startTrackPage failed, page view may not be collected: " + ApplicationInsights.Util.dump(e));
2215                 }
2216             };
2217             AppInsights.prototype.stopTrackPage = function (name, url, properties, measurements) {
2218                 try {
2219                     if (typeof name !== "string") {
2220                         name = window.document && window.document.title || "";
2221                     }
2222                     if (typeof url !== "string") {
2223                         url = window.location && window.location.href || "";
2224                     }
2225                     this._pageTracking.stop(name, url, properties, measurements);
2226                     if (this.config.autoTrackPageVisitTime) {
2227                         this._pageVisitTimeManager.trackPreviousPageVisit(name, url);
2228                     }
2229                 }
2230                 catch (e) {
2231                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "stopTrackPage failed, page view will not be collected: " + ApplicationInsights.Util.dump(e));
2232                 }
2233             };
2234             AppInsights.prototype.trackPageView = function (name, url, properties, measurements) {
2235                 try {
2236                     if (typeof name !== "string") {
2237                         name = window.document && window.document.title || "";
2238                     }
2239                     if (typeof url !== "string") {
2240                         url = window.location && window.location.href || "";
2241                     }
2242                     this.trackPageViewInternal(name, url, properties, measurements);
2243                     if (this.config.autoTrackPageVisitTime) {
2244                         this._pageVisitTimeManager.trackPreviousPageVisit(name, url);
2245                     }
2246                 }
2247                 catch (e) {
2248                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackPageView failed, page view will not be collected: " + ApplicationInsights.Util.dump(e));
2249                 }
2250             };
2251             AppInsights.prototype.trackPageViewInternal = function (name, url, properties, measurements) {
2252                 var _this = this;
2253                 var durationMs = 0;
2254                 if (ApplicationInsights.Telemetry.PageViewPerformance.isPerformanceTimingSupported()) {
2255                     var startTime = window.performance.timing.navigationStart;
2256                     durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2257                     var handle = setInterval(function () {
2258                         try {
2259                             durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2260                             var timingDataReady = ApplicationInsights.Telemetry.PageViewPerformance.isPerformanceTimingDataReady();
2261                             var timeoutReached = durationMs > 60000;
2262                             if (timeoutReached || timingDataReady) {
2263                                 clearInterval(handle);
2264                                 durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2265                                 var pageViewPerformance = new ApplicationInsights.Telemetry.PageViewPerformance(name, url, durationMs, properties, measurements);
2266                                 _this.sendPageViewInternal(name, url, pageViewPerformance.isValid && !isNaN(pageViewPerformance.duration) ? +pageViewPerformance.duration : durationMs, properties, measurements);
2267                                 if (pageViewPerformance.isValid) {
2268                                     var pageViewPerformanceData = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.PageViewPerformance.dataType, pageViewPerformance);
2269                                     var pageViewPerformanceEnvelope = new ApplicationInsights.Telemetry.Common.Envelope(pageViewPerformanceData, ApplicationInsights.Telemetry.PageViewPerformance.envelopeType);
2270                                     _this.context.track(pageViewPerformanceEnvelope);
2271                                 }
2272                                 _this.context._sender.triggerSend();
2273                             }
2274                         }
2275                         catch (e) {
2276                             ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackPageView failed on page load calculation: " + ApplicationInsights.Util.dump(e));
2277                         }
2278                     }, 100);
2279                 }
2280             };
2281             AppInsights.prototype.startTrackEvent = function (name) {
2282                 try {
2283                     this._eventTracking.start(name);
2284                 }
2285                 catch (e) {
2286                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "startTrackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2287                 }
2288             };
2289             AppInsights.prototype.stopTrackEvent = function (name, properties, measurements) {
2290                 try {
2291                     this._eventTracking.stop(name, undefined, properties, measurements);
2292                 }
2293                 catch (e) {
2294                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "stopTrackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2295                 }
2296             };
2297             AppInsights.prototype.trackEvent = function (name, properties, measurements) {
2298                 try {
2299                     var eventTelemetry = new ApplicationInsights.Telemetry.Event(name, properties, measurements);
2300                     var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Event.dataType, eventTelemetry);
2301                     var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Event.envelopeType);
2302                     this.context.track(envelope);
2303                 }
2304                 catch (e) {
2305                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2306                 }
2307             };
2308             AppInsights.prototype.trackException = function (exception, handledAt, properties, measurements) {
2309                 try {
2310                     if (!ApplicationInsights.Util.isError(exception)) {
2311                         try {
2312                             throw new Error(exception);
2313                         }
2314                         catch (error) {
2315                             exception = error;
2316                         }
2317                     }
2318                     var exceptionTelemetry = new ApplicationInsights.Telemetry.Exception(exception, handledAt, properties, measurements);
2319                     var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Exception.dataType, exceptionTelemetry);
2320                     var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Exception.envelopeType);
2321                     this.context.track(envelope);
2322                 }
2323                 catch (e) {
2324                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackException failed, exception will not be collected: " + ApplicationInsights.Util.dump(e));
2325                 }
2326             };
2327             AppInsights.prototype.trackMetric = function (name, average, sampleCount, min, max, properties) {
2328                 try {
2329                     var telemetry = new ApplicationInsights.Telemetry.Metric(name, average, sampleCount, min, max, properties);
2330                     var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Metric.dataType, telemetry);
2331                     var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Metric.envelopeType);
2332                     this.context.track(envelope);
2333                 }
2334                 catch (e) {
2335                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackMetric failed, metric will not be collected: " + ApplicationInsights.Util.dump(e));
2336                 }
2337             };
2338             AppInsights.prototype.trackTrace = function (message, properties) {
2339                 try {
2340                     var telemetry = new ApplicationInsights.Telemetry.Trace(message, properties);
2341                     var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Trace.dataType, telemetry);
2342                     var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Trace.envelopeType);
2343                     this.context.track(envelope);
2344                 }
2345                 catch (e) {
2346                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "trackTrace failed, trace will not be collected: " + ApplicationInsights.Util.dump(e));
2347                 }
2348             };
2349             AppInsights.prototype.trackPageVisitTime = function (pageName, pageUrl, pageVisitTime) {
2350                 var properties = { PageName: pageName, PageUrl: pageUrl };
2351                 this.trackMetric("PageVisitTime", pageVisitTime, 1, pageVisitTime, pageVisitTime, properties);
2352             };
2353             AppInsights.prototype.flush = function () {
2354                 try {
2355                     this.context._sender.triggerSend();
2356                 }
2357                 catch (e) {
2358                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "flush failed, telemetry will not be collected: " + ApplicationInsights.Util.dump(e));
2359                 }
2360             };
2361             AppInsights.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId) {
2362                 try {
2363                     this.context.user.setAuthenticatedUserContext(authenticatedUserId, accountId);
2364                 }
2365                 catch (e) {
2366                     ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Setting auth user context failed. " + ApplicationInsights.Util.dump(e));
2367                 }
2368             };
2369             AppInsights.prototype.clearAuthenticatedUserContext = function () {
2370                 try {
2371                     this.context.user.clearAuthenticatedUserContext();
2372                 }
2373                 catch (e) {
2374                     ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Clearing auth user context failed. " + ApplicationInsights.Util.dump(e));
2375                 }
2376             };
2377             AppInsights.prototype.SendCORSException = function (properties) {
2378                 var exceptionData = Microsoft.ApplicationInsights.Telemetry.Exception.CreateSimpleException("Script error.", "Error", "unknown", "unknown", "The browser’s same-origin policy prevents us from getting the details of this exception.The exception occurred in a script loaded from an origin different than the web page.For cross- domain error reporting you can use crossorigin attribute together with appropriate CORS HTTP headers.For more information please see http://www.w3.org/TR/cors/.", 0, null);
2379                 exceptionData.properties = properties;
2380                 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Exception.dataType, exceptionData);
2381                 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Exception.envelopeType);
2382                 this.context.track(envelope);
2383             };
2384             AppInsights.prototype._onerror = function (message, url, lineNumber, columnNumber, error) {
2385                 try {
2386                     var properties = { url: url ? url : document.URL };
2387                     if (ApplicationInsights.Util.isCrossOriginError(message, url, lineNumber, columnNumber, error)) {
2388                         this.SendCORSException(properties);
2389                     }
2390                     else {
2391                         if (!ApplicationInsights.Util.isError(error)) {
2392                             var stack = "window.onerror@" + properties.url + ":" + lineNumber + ":" + (columnNumber || 0);
2393                             error = new Error(message);
2394                             error["stack"] = stack;
2395                         }
2396                         this.trackException(error, null, properties);
2397                     }
2398                 }
2399                 catch (exception) {
2400                     var errorString = error ? (error.name + ", " + error.message) : "null";
2401                     var exceptionDump = ApplicationInsights.Util.dump(exception);
2402                     ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "_onerror threw " + exceptionDump + " while logging error, error will not be collected: " + errorString);
2403                 }
2404             };
2405             return AppInsights;
2406         })();
2407         ApplicationInsights.AppInsights = AppInsights;
2408         var Timing = (function () {
2409             function Timing(name) {
2410                 this._name = name;
2411                 this._events = {};
2412             }
2413             Timing.prototype.start = function (name) {
2414                 if (typeof this._events[name] !== "undefined") {
2415                     ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "start" + this._name + " was called more than once for this event without calling stop" + this._name + ". key is '" + name + "'");
2416                 }
2417                 this._events[name] = +new Date;
2418             };
2419             Timing.prototype.stop = function (name, url, properties, measurements) {
2420                 var start = this._events[name];
2421                 if (isNaN(start)) {
2422                     ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "stop" + this._name + " was called without a corresponding start" + this._name + " . Event name is '" + name + "'");
2423                 }
2424                 else {
2425                     var end = +new Date;
2426                     var duration = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(start, end);
2427                     this.action(name, url, duration, properties, measurements);
2428                 }
2429                 delete this._events[name];
2430                 this._events[name] = undefined;
2431             };
2432             return Timing;
2433         })();
2434     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2435 })(Microsoft || (Microsoft = {}));
2436 var AI;
2437 (function (AI) {
2438     "use strict";
2439     var AjaxCallData = (function (_super) {
2440         __extends(AjaxCallData, _super);
2441         function AjaxCallData() {
2442             this.ver = 2;
2443             this.properties = {};
2444             this.measurements = {};
2445             _super.call(this);
2446         }
2447         return AjaxCallData;
2448     })(AI.PageViewData);
2449     AI.AjaxCallData = AjaxCallData;
2450 })(AI || (AI = {}));
2451 var AI;
2452 (function (AI) {
2453     "use strict";
2454     (function (DependencyKind) {
2455         DependencyKind[DependencyKind["SQL"] = 0] = "SQL";
2456         DependencyKind[DependencyKind["Http"] = 1] = "Http";
2457         DependencyKind[DependencyKind["Other"] = 2] = "Other";
2458     })(AI.DependencyKind || (AI.DependencyKind = {}));
2459     var DependencyKind = AI.DependencyKind;
2460 })(AI || (AI = {}));
2461 var AI;
2462 (function (AI) {
2463     "use strict";
2464     (function (DependencySourceType) {
2465         DependencySourceType[DependencySourceType["Undefined"] = 0] = "Undefined";
2466         DependencySourceType[DependencySourceType["Aic"] = 1] = "Aic";
2467         DependencySourceType[DependencySourceType["Apmc"] = 2] = "Apmc";
2468     })(AI.DependencySourceType || (AI.DependencySourceType = {}));
2469     var DependencySourceType = AI.DependencySourceType;
2470 })(AI || (AI = {}));
2471 var AI;
2472 (function (AI) {
2473     "use strict";
2474     var RemoteDependencyData = (function (_super) {
2475         __extends(RemoteDependencyData, _super);
2476         function RemoteDependencyData() {
2477             this.ver = 2;
2478             this.kind = 0 /* Measurement */;
2479             this.dependencyKind = 2 /* Other */;
2480             this.success = true;
2481             this.dependencySource = 0 /* Undefined */;
2482             this.properties = {};
2483             _super.call(this);
2484         }
2485         return RemoteDependencyData;
2486     })(Microsoft.Telemetry.Domain);
2487     AI.RemoteDependencyData = RemoteDependencyData;
2488 })(AI || (AI = {}));
2489 var AI;
2490 (function (AI) {
2491     "use strict";
2492     var RequestData = (function (_super) {
2493         __extends(RequestData, _super);
2494         function RequestData() {
2495             this.ver = 2;
2496             this.properties = {};
2497             this.measurements = {};
2498             _super.call(this);
2499         }
2500         return RequestData;
2501     })(Microsoft.Telemetry.Domain);
2502     AI.RequestData = RequestData;
2503 })(AI || (AI = {}));
2504 var Microsoft;
2505 (function (Microsoft) {
2506     var ApplicationInsights;
2507     (function (ApplicationInsights) {
2508         "use strict";
2509         var Initialization = (function () {
2510             function Initialization(snippet) {
2511                 snippet.queue = snippet.queue || [];
2512                 var config = snippet.config || {};
2513                 if (config && !config.instrumentationKey) {
2514                     config = snippet;
2515                     if (config["iKey"]) {
2516                         Microsoft.ApplicationInsights.Version = "0.10.0.0";
2517                         config.instrumentationKey = config["iKey"];
2518                     }
2519                     else if (config["applicationInsightsId"]) {
2520                         Microsoft.ApplicationInsights.Version = "0.7.2.0";
2521                         config.instrumentationKey = config["applicationInsightsId"];
2522                     }
2523                     else {
2524                         throw new Error("Cannot load Application Insights SDK, no instrumentationKey was provided.");
2525                     }
2526                 }
2527                 config = Initialization.getDefaultConfig(config);
2528                 this.snippet = snippet;
2529                 this.config = config;
2530             }
2531             Initialization.prototype.loadAppInsights = function () {
2532                 var appInsights = new Microsoft.ApplicationInsights.AppInsights(this.config);
2533                 if (this.config["iKey"]) {
2534                     var originalTrackPageView = appInsights.trackPageView;
2535                     appInsights.trackPageView = function (pagePath, properties, measurements) {
2536                         originalTrackPageView.apply(appInsights, [null, pagePath, properties, measurements]);
2537                     };
2538                 }
2539                 var legacyPageView = "logPageView";
2540                 if (typeof this.snippet[legacyPageView] === "function") {
2541                     appInsights[legacyPageView] = function (pagePath, properties, measurements) {
2542                         appInsights.trackPageView(null, pagePath, properties, measurements);
2543                     };
2544                 }
2545                 var legacyEvent = "logEvent";
2546                 if (typeof this.snippet[legacyEvent] === "function") {
2547                     appInsights[legacyEvent] = function (name, properties, measurements) {
2548                         appInsights.trackEvent(name, properties, measurements);
2549                     };
2550                 }
2551                 return appInsights;
2552             };
2553             Initialization.prototype.emptyQueue = function () {
2554                 try {
2555                     if (Microsoft.ApplicationInsights.Util.isArray(this.snippet.queue)) {
2556                         var length = this.snippet.queue.length;
2557                         for (var i = 0; i < length; i++) {
2558                             var call = this.snippet.queue[i];
2559                             call();
2560                         }
2561                         this.snippet.queue = undefined;
2562                         delete this.snippet.queue;
2563                     }
2564                 }
2565                 catch (exception) {
2566                     var message = "Failed to send queued telemetry";
2567                     if (exception && typeof exception.toString === "function") {
2568                         message += ": " + exception.toString();
2569                     }
2570                     Microsoft.ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, message);
2571                 }
2572             };
2573             Initialization.prototype.pollInteralLogs = function (appInsightsInstance) {
2574                 return setInterval(function () {
2575                     var queue = Microsoft.ApplicationInsights._InternalLogging.queue;
2576                     var length = queue.length;
2577                     for (var i = 0; i < length; i++) {
2578                         appInsightsInstance.trackTrace(queue[i]);
2579                     }
2580                     queue.length = 0;
2581                 }, this.config.diagnosticLogInterval);
2582             };
2583             Initialization.prototype.addHousekeepingBeforeUnload = function (appInsightsInstance) {
2584                 if ('onbeforeunload' in window) {
2585                     var performHousekeeping = function () {
2586                         appInsightsInstance.context._sender.triggerSend();
2587                         appInsightsInstance.context._sessionManager.backup();
2588                     };
2589                     if (!Microsoft.ApplicationInsights.Util.addEventHandler('beforeunload', performHousekeeping)) {
2590                         Microsoft.ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, 'Could not add handler for beforeunload');
2591                     }
2592                 }
2593             };
2594             Initialization.getDefaultConfig = function (config) {
2595                 if (!config) {
2596                     config = {};
2597                 }
2598                 config.endpointUrl = config.endpointUrl || "//dc.services.visualstudio.com/v2/track";
2599                 config.accountId = config.accountId;
2600                 config.appUserId = config.appUserId;
2601                 config.sessionRenewalMs = 30 * 60 * 1000;
2602                 config.sessionExpirationMs = 24 * 60 * 60 * 1000;
2603                 config.maxBatchSizeInBytes = config.maxBatchSizeInBytes > 0 ? config.maxBatchSizeInBytes : 1000000;
2604                 config.maxBatchInterval = !isNaN(config.maxBatchInterval) ? config.maxBatchInterval : 15000;
2605                 config.enableDebug = ApplicationInsights.Util.stringToBoolOrDefault(config.enableDebug);
2606                 config.autoCollectErrors = (config.autoCollectErrors !== undefined && config.autoCollectErrors !== null) ? ApplicationInsights.Util.stringToBoolOrDefault(config.autoCollectErrors) : true;
2607                 config.disableTelemetry = ApplicationInsights.Util.stringToBoolOrDefault(config.disableTelemetry);
2608                 config.verboseLogging = ApplicationInsights.Util.stringToBoolOrDefault(config.verboseLogging);
2609                 config.emitLineDelimitedJson = ApplicationInsights.Util.stringToBoolOrDefault(config.emitLineDelimitedJson);
2610                 config.diagnosticLogInterval = config.diagnosticLogInterval || 10000;
2611                 config.autoTrackPageVisitTime = ApplicationInsights.Util.stringToBoolOrDefault(config.autoTrackPageVisitTime);
2612                 if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
2613                     config.samplingPercentage = 100;
2614                 }
2615                 return config;
2616             };
2617             return Initialization;
2618         })();
2619         ApplicationInsights.Initialization = Initialization;
2620     })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2621 })(Microsoft || (Microsoft = {}));
2622 function initializeAppInsights() {
2623     try {
2624         if (typeof window !== "undefined" && typeof JSON !== "undefined") {
2625             var aiName = "appInsights";
2626             if (window[aiName] === undefined) {
2627                 Microsoft.ApplicationInsights.AppInsights.defaultConfig = Microsoft.ApplicationInsights.Initialization.getDefaultConfig();
2628             }
2629             else {
2630                 var snippet = window[aiName] || {};
2631                 var init = new Microsoft.ApplicationInsights.Initialization(snippet);
2632                 var appInsightsLocal = init.loadAppInsights();
2633                 for (var field in appInsightsLocal) {
2634                     snippet[field] = appInsightsLocal[field];
2635                 }
2636                 init.emptyQueue();
2637                 init.pollInteralLogs(appInsightsLocal);
2638                 init.addHousekeepingBeforeUnload(appInsightsLocal);
2639             }
2640         }
2641     }
2642     catch (e) {
2643         Microsoft.ApplicationInsights._InternalLogging.warnToConsole('Failed to initialize AppInsights JS SDK: ' + e.message);
2644     }
2645 }
2646 initializeAppInsights();