1 | /*
|
2 | * Application Insights JavaScript SDK - Web, 3.2.2
|
3 | * Copyright (c) Microsoft and contributors. All rights reserved.
|
4 | */
|
5 |
|
6 |
|
7 | ;
|
8 | var _a, _b, _c, _d;
|
9 | import dynamicProto from "@microsoft/dynamicproto-js";
|
10 | import { AnalyticsPlugin } from "@microsoft/applicationinsights-analytics-js";
|
11 | import { CfgSyncPlugin } from "@microsoft/applicationinsights-cfgsync-js";
|
12 | import { Sender } from "@microsoft/applicationinsights-channel-js";
|
13 | import { AnalyticsPluginIdentifier, DEFAULT_BREEZE_PATH, PropertiesPluginIdentifier, ThrottleMgr, parseConnectionString } from "@microsoft/applicationinsights-common";
|
14 | import { AppInsightsCore, _throwInternal, addPageHideEventListener, addPageUnloadEventListener, cfgDfMerge, cfgDfValidate, createDynamicConfig, createProcessTelemetryContext, createUniqueNamespace, doPerf, hasDocument, hasWindow, isArray, isFeatureEnabled, isFunction, isNullOrUndefined, isReactNative, isString, mergeEvtNamespace, onConfigChange, proxyAssign, proxyFunctions, removePageHideEventListener, removePageUnloadEventListener } from "@microsoft/applicationinsights-core-js";
|
15 | import { AjaxPlugin as DependenciesPlugin } from "@microsoft/applicationinsights-dependencies-js";
|
16 | import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
|
17 | import { createPromise } from "@nevware21/ts-async";
|
18 | import { arrForEach, arrIndexOf, objDefine, objForEachKey, strIndexOf, throwUnsupported } from "@nevware21/ts-utils";
|
19 | import { CONFIG_ENDPOINT_URL, STR_ADD_TELEMETRY_INITIALIZER, STR_CLEAR_AUTHENTICATED_USER_CONTEXT, STR_EVT_NAMESPACE, STR_FLUSH, STR_GET_COOKIE_MGR, STR_GET_PLUGIN, STR_POLL_INTERNAL_LOGS, STR_SET_AUTHENTICATED_USER_CONTEXT, STR_SNIPPET, STR_START_TRACK_EVENT, STR_START_TRACK_PAGE, STR_STOP_TRACK_EVENT, STR_STOP_TRACK_PAGE, STR_TRACK_DEPENDENCY_DATA, STR_TRACK_EVENT, STR_TRACK_EXCEPTION, STR_TRACK_METRIC, STR_TRACK_PAGE_VIEW, STR_TRACK_TRACE } from "./InternalConstants";
|
20 | import { _DYN_ADD_HOUSEKEEPING_BEF1, _DYN_CONNECTION_STRING, _DYN_CONTEXT, _DYN_ENDPOINT_URL, _DYN_INSTRUMENTATION_KEY, _DYN_ONUNLOAD_FLUSH, _DYN_QUEUE, _DYN_SEND_MESSAGE, _DYN_UPDATE_SNIPPET_DEFIN2, _DYN_USER_OVERRIDE_ENDPOI0, _DYN_VERSION } from "./__DynamicConstants";
|
21 | var _internalSdkSrc;
|
22 | // This is an exclude list of properties that should not be updated during initialization
|
23 | // They include a combination of private and internal property names
|
24 | var _ignoreUpdateSnippetProperties = [
|
25 | STR_SNIPPET, "dependencies", "properties", "_snippetVersion", "appInsightsNew", "getSKUDefaults"
|
26 | ];
|
27 | var IKEY_USAGE = "iKeyUsage";
|
28 | var CDN_USAGE = "CdnUsage";
|
29 | var SDK_LOADER_VER = "SdkLoaderVer";
|
30 | var UNDEFINED_VALUE = undefined;
|
31 | var default_limit = {
|
32 | samplingRate: 100,
|
33 | maxSendNumber: 1
|
34 | };
|
35 | var default_interval = {
|
36 | monthInterval: 3,
|
37 | daysOfMonth: [28]
|
38 | };
|
39 | var default_throttle_config = {
|
40 | disabled: true,
|
41 | limit: cfgDfMerge(default_limit),
|
42 | interval: cfgDfMerge(default_interval)
|
43 | };
|
44 | // We need to include all properties that we only reference that we want to be dynamically updatable here
|
45 | // So they are converted even when not specified in the passed configuration
|
46 | var defaultConfigValues = (_a = {},
|
47 | _a[_DYN_CONNECTION_STRING /* @min:connectionString */] = UNDEFINED_VALUE,
|
48 | _a[_DYN_ENDPOINT_URL /* @min:endpointUrl */] = UNDEFINED_VALUE,
|
49 | _a[_DYN_INSTRUMENTATION_KEY /* @min:instrumentationKey */] = UNDEFINED_VALUE,
|
50 | _a[_DYN_USER_OVERRIDE_ENDPOI0 /* @min:userOverrideEndpointUrl */] = UNDEFINED_VALUE,
|
51 | _a.diagnosticLogInterval = cfgDfValidate(_chkDiagLevel, 10000),
|
52 | _a.featureOptIn = (_b = {},
|
53 | _b[IKEY_USAGE] = { mode: 3 /* FeatureOptInMode.enable */ },
|
54 | _b[CDN_USAGE] = { mode: 2 /* FeatureOptInMode.disable */ },
|
55 | _b[SDK_LOADER_VER] = { mode: 2 /* FeatureOptInMode.disable */ },
|
56 | _b),
|
57 | _a.throttleMgrCfg = cfgDfMerge((_c = {},
|
58 | _c[109 /* _eInternalMessageId.DefaultThrottleMsgKey */] = cfgDfMerge(default_throttle_config),
|
59 | _c[106 /* _eInternalMessageId.InstrumentationKeyDeprecation */] = cfgDfMerge(default_throttle_config),
|
60 | _c[111 /* _eInternalMessageId.SdkLdrUpdate */] = cfgDfMerge(default_throttle_config),
|
61 | _c[110 /* _eInternalMessageId.CdnDeprecation */] = cfgDfMerge(default_throttle_config),
|
62 | _c)),
|
63 | _a.extensionConfig = cfgDfMerge((_d = {},
|
64 | _d["AppInsightsCfgSyncPlugin"] = cfgDfMerge({
|
65 | cfgUrl: CONFIG_ENDPOINT_URL,
|
66 | syncMode: 2 /* ICfgSyncMode.Receive */
|
67 | }),
|
68 | _d)),
|
69 | _a);
|
70 | function _chkDiagLevel(value) {
|
71 | // Make sure we have a value > 0
|
72 | return value && value > 0;
|
73 | }
|
74 | /**
|
75 | * Application Insights API
|
76 | * @group Entrypoint
|
77 | * @group Classes
|
78 | * @class Initialization
|
79 | * @implements {IApplicationInsights}
|
80 | */
|
81 | var AppInsightsSku = /** @class */ (function () {
|
82 | function AppInsightsSku(snippet) {
|
83 | var _this = this;
|
84 | // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
|
85 | var dependencies;
|
86 | var properties;
|
87 | var _sender;
|
88 | var _snippetVersion;
|
89 | var _evtNamespace;
|
90 | var _houseKeepingNamespace;
|
91 | var _core;
|
92 | var _config;
|
93 | var _analyticsPlugin;
|
94 | var _cfgSyncPlugin;
|
95 | var _throttleMgr;
|
96 | var _iKeySentMessage;
|
97 | var _cdnSentMessage;
|
98 | var _sdkVerSentMessage;
|
99 | dynamicProto(AppInsightsSku, this, function (_self) {
|
100 | _initDefaults();
|
101 | objDefine(_self, "config", {
|
102 | g: function () {
|
103 | return _config;
|
104 | }
|
105 | });
|
106 | arrForEach(["pluginVersionStringArr", "pluginVersionString"], function (key) {
|
107 | objDefine(_self, key, {
|
108 | g: function () {
|
109 | if (_core) {
|
110 | return _core[key];
|
111 | }
|
112 | return null;
|
113 | }
|
114 | });
|
115 | });
|
116 | // initialize the queue and config in case they are undefined
|
117 | _snippetVersion = "" + (snippet.sv || snippet[_DYN_VERSION /* @min:%2eversion */] || "");
|
118 | snippet[_DYN_QUEUE /* @min:%2equeue */] = snippet[_DYN_QUEUE /* @min:%2equeue */] || [];
|
119 | snippet[_DYN_VERSION /* @min:%2eversion */] = snippet[_DYN_VERSION /* @min:%2eversion */] || 2.0; // Default to new version
|
120 | var cfgHandler = createDynamicConfig(snippet.config || {}, defaultConfigValues);
|
121 | _config = cfgHandler.cfg;
|
122 | _analyticsPlugin = new AnalyticsPlugin();
|
123 | objDefine(_self, "appInsights", {
|
124 | g: function () {
|
125 | return _analyticsPlugin;
|
126 | }
|
127 | });
|
128 | properties = new PropertiesPlugin();
|
129 | dependencies = new DependenciesPlugin();
|
130 | _sender = new Sender();
|
131 | _core = new AppInsightsCore();
|
132 | objDefine(_self, "core", {
|
133 | g: function () {
|
134 | return _core;
|
135 | }
|
136 | });
|
137 | // Will get recalled if any referenced values are changed
|
138 | _addUnloadHook(onConfigChange(cfgHandler, function () {
|
139 | if (_config[_DYN_CONNECTION_STRING /* @min:%2econnectionString */]) {
|
140 | var cs = parseConnectionString(_config[_DYN_CONNECTION_STRING /* @min:%2econnectionString */]);
|
141 | var ingest = cs.ingestionendpoint;
|
142 | _config[_DYN_ENDPOINT_URL /* @min:%2eendpointUrl */] = _config[_DYN_USER_OVERRIDE_ENDPOI0 /* @min:%2euserOverrideEndpointUrl */] ? _config[_DYN_USER_OVERRIDE_ENDPOI0 /* @min:%2euserOverrideEndpointUrl */] : ingest + DEFAULT_BREEZE_PATH; // add /v2/track
|
143 | _config[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */] = cs.instrumentationkey || _config[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */];
|
144 | }
|
145 | // userOverrideEndpointUrl have the highest priority
|
146 | _config[_DYN_ENDPOINT_URL /* @min:%2eendpointUrl */] = _config[_DYN_USER_OVERRIDE_ENDPOI0 /* @min:%2euserOverrideEndpointUrl */] ? _config[_DYN_USER_OVERRIDE_ENDPOI0 /* @min:%2euserOverrideEndpointUrl */] : _config[_DYN_ENDPOINT_URL /* @min:%2eendpointUrl */];
|
147 | }));
|
148 | _self[STR_SNIPPET /* @min:%2esnippet */] = snippet;
|
149 | _self[STR_FLUSH /* @min:%2eflush */] = function (async, callBack) {
|
150 | if (async === void 0) { async = true; }
|
151 | var result;
|
152 | doPerf(_core, function () { return "AISKU.flush"; }, function () {
|
153 | if (async && !callBack) {
|
154 | result = createPromise(function (resolve) {
|
155 | callBack = resolve;
|
156 | });
|
157 | }
|
158 | var waiting = 1;
|
159 | var flushDone = function () {
|
160 | waiting--;
|
161 | if (waiting === 0) {
|
162 | callBack();
|
163 | }
|
164 | };
|
165 | arrForEach(_core.getChannels(), function (channel) {
|
166 | if (channel) {
|
167 | waiting++;
|
168 | channel[STR_FLUSH /* @min:%2eflush */](async, flushDone);
|
169 | }
|
170 | });
|
171 | // decrement the initial "waiting"
|
172 | flushDone();
|
173 | }, null, async);
|
174 | return result;
|
175 | };
|
176 | _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function (async) {
|
177 | if (async === void 0) { async = true; }
|
178 | arrForEach(_core.getChannels(), function (channel) {
|
179 | if (channel[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]) {
|
180 | channel[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();
|
181 | }
|
182 | else {
|
183 | channel[STR_FLUSH /* @min:%2eflush */](async);
|
184 | }
|
185 | });
|
186 | };
|
187 | _self.loadAppInsights = function (legacyMode, logger, notificationManager) {
|
188 | if (legacyMode === void 0) { legacyMode = false; }
|
189 | if (legacyMode) {
|
190 | throwUnsupported("Legacy Mode is no longer supported");
|
191 | }
|
192 | function _updateSnippetProperties(snippet) {
|
193 | if (snippet) {
|
194 | var snippetVer = "";
|
195 | if (!isNullOrUndefined(_snippetVersion)) {
|
196 | snippetVer += _snippetVersion;
|
197 | }
|
198 | if (_self[_DYN_CONTEXT /* @min:%2econtext */] && _self[_DYN_CONTEXT /* @min:%2econtext */].internal) {
|
199 | _self[_DYN_CONTEXT /* @min:%2econtext */].internal.snippetVer = snippetVer || "-";
|
200 | }
|
201 | // apply updated properties to the global instance (snippet)
|
202 | objForEachKey(_self, function (field, value) {
|
203 | if (isString(field) &&
|
204 | !isFunction(value) &&
|
205 | field && field[0] !== "_" && // Don't copy "internal" values
|
206 | arrIndexOf(_ignoreUpdateSnippetProperties, field) === -1) {
|
207 | if (snippet[field] !== value) {
|
208 | snippet[field] = value;
|
209 | }
|
210 | }
|
211 | });
|
212 | }
|
213 | }
|
214 | doPerf(_self.core, function () { return "AISKU.loadAppInsights"; }, function () {
|
215 | // initialize core
|
216 | _core.initialize(_config, [_sender, properties, dependencies, _analyticsPlugin, _cfgSyncPlugin], logger, notificationManager);
|
217 | objDefine(_self, "context", {
|
218 | g: function () { return properties[_DYN_CONTEXT /* @min:%2econtext */]; }
|
219 | });
|
220 | if (!_throttleMgr) {
|
221 | _throttleMgr = new ThrottleMgr(_core);
|
222 | }
|
223 | var sdkSrc = _findSdkSourceFile();
|
224 | if (sdkSrc && _self[_DYN_CONTEXT /* @min:%2econtext */]) {
|
225 | _self[_DYN_CONTEXT /* @min:%2econtext */].internal.sdkSrc = sdkSrc;
|
226 | }
|
227 | _updateSnippetProperties(_self[STR_SNIPPET /* @min:%2esnippet */]);
|
228 | // Empty queue of all api calls logged prior to sdk download
|
229 | _self.emptyQueue();
|
230 | _self[STR_POLL_INTERNAL_LOGS /* @min:%2epollInternalLogs */]();
|
231 | _self[_DYN_ADD_HOUSEKEEPING_BEF1 /* @min:%2eaddHousekeepingBeforeUnload */](_self);
|
232 | _addUnloadHook(onConfigChange(cfgHandler, function () {
|
233 | var defaultEnable = false;
|
234 | if (_config.throttleMgrCfg[109 /* _eInternalMessageId.DefaultThrottleMsgKey */]) {
|
235 | defaultEnable = !_config.throttleMgrCfg[109 /* _eInternalMessageId.DefaultThrottleMsgKey */].disabled;
|
236 | }
|
237 | if (!_throttleMgr.isReady() && _config.extensionConfig && _config.extensionConfig[_cfgSyncPlugin.identifier] && defaultEnable) {
|
238 | // set ready state to true will automatically trigger flush()
|
239 | _throttleMgr.onReadyState(true);
|
240 | }
|
241 | var result;
|
242 | if (!_iKeySentMessage && !_config[_DYN_CONNECTION_STRING /* @min:%2econnectionString */] && isFeatureEnabled(IKEY_USAGE, _config)) {
|
243 | result = _throttleMgr[_DYN_SEND_MESSAGE /* @min:%2esendMessage */](106 /* _eInternalMessageId.InstrumentationKeyDeprecation */, "See Instrumentation key support at aka.ms/IkeyMigrate");
|
244 | _iKeySentMessage = true;
|
245 | }
|
246 | if (!_cdnSentMessage && _self[_DYN_CONTEXT /* @min:%2econtext */].internal.sdkSrc && _self[_DYN_CONTEXT /* @min:%2econtext */].internal.sdkSrc.indexOf("az416426") != -1 && isFeatureEnabled(CDN_USAGE, _config)) {
|
247 | result = _throttleMgr[_DYN_SEND_MESSAGE /* @min:%2esendMessage */](110 /* _eInternalMessageId.CdnDeprecation */, "See Cdn support notice at aka.ms/JsActiveCdn");
|
248 | _cdnSentMessage = true;
|
249 | }
|
250 | if (!_sdkVerSentMessage && parseInt(_snippetVersion) < 6 && isFeatureEnabled(SDK_LOADER_VER, _config)) {
|
251 | result = _throttleMgr[_DYN_SEND_MESSAGE /* @min:%2esendMessage */](111 /* _eInternalMessageId.SdkLdrUpdate */, "An updated Sdk Loader is available, see aka.ms/SnippetVer");
|
252 | _sdkVerSentMessage = true;
|
253 | }
|
254 | }));
|
255 | });
|
256 | return _self;
|
257 | };
|
258 | _self[_DYN_UPDATE_SNIPPET_DEFIN2 /* @min:%2eupdateSnippetDefinitions */] = function (snippet) {
|
259 | // apply full appInsights to the global instance
|
260 | // Note: This must be called before loadAppInsights is called
|
261 | proxyAssign(snippet, _self, function (name) {
|
262 | // Not excluding names prefixed with "_" as we need to proxy some functions like _onError
|
263 | return name && arrIndexOf(_ignoreUpdateSnippetProperties, name) === -1;
|
264 | });
|
265 | };
|
266 | _self.emptyQueue = function () {
|
267 | // call functions that were queued before the main script was loaded
|
268 | try {
|
269 | if (isArray(_self.snippet[_DYN_QUEUE /* @min:%2equeue */])) {
|
270 | // note: do not check length in the for-loop conditional in case something goes wrong and the stub methods are not overridden.
|
271 | var length_1 = _self.snippet[_DYN_QUEUE /* @min:%2equeue */].length;
|
272 | for (var i = 0; i < length_1; i++) {
|
273 | var call = _self.snippet[_DYN_QUEUE /* @min:%2equeue */][i];
|
274 | call();
|
275 | }
|
276 | _self.snippet[_DYN_QUEUE /* @min:%2equeue */] = undefined;
|
277 | delete _self.snippet[_DYN_QUEUE /* @min:%2equeue */];
|
278 | }
|
279 | }
|
280 | catch (exception) {
|
281 | var properties_1 = {};
|
282 | if (exception && isFunction(exception.toString)) {
|
283 | properties_1.exception = exception.toString();
|
284 | }
|
285 | // need from core
|
286 | // Microsoft.ApplicationInsights._InternalLogging.throwInternal(
|
287 | // eLoggingSeverity.WARNING,
|
288 | // _eInternalMessageId.FailedToSendQueuedTelemetry,
|
289 | // "Failed to send queued telemetry",
|
290 | // properties);
|
291 | }
|
292 | };
|
293 | _self[_DYN_ADD_HOUSEKEEPING_BEF1 /* @min:%2eaddHousekeepingBeforeUnload */] = function (appInsightsInstance) {
|
294 | // Add callback to push events when the user navigates away
|
295 | if (hasWindow() || hasDocument()) {
|
296 | var performHousekeeping_1 = function () {
|
297 | // Adds the ability to flush all data before the page unloads.
|
298 | // Note: This approach tries to push a sync request with all the pending events onbeforeunload.
|
299 | // Firefox does not respect this.Other browsers DO push out the call with < 100% hit rate.
|
300 | // Telemetry here will help us analyze how effective this approach is.
|
301 | // Another approach would be to make this call sync with a acceptable timeout to reduce the
|
302 | // impact on user experience.
|
303 | // appInsightsInstance.context._sender.triggerSend();
|
304 | appInsightsInstance[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */](false);
|
305 | // Back up the current session to local storage
|
306 | // This lets us close expired sessions after the cookies themselves expire
|
307 | if (isFunction(_self.core[STR_GET_PLUGIN /* @min:%2egetPlugin */])) {
|
308 | var loadedPlugin = _this.core[STR_GET_PLUGIN /* @min:%2egetPlugin */](PropertiesPluginIdentifier);
|
309 | if (loadedPlugin) {
|
310 | var propertiesPlugin = loadedPlugin.plugin;
|
311 | if (propertiesPlugin && propertiesPlugin[_DYN_CONTEXT /* @min:%2econtext */] && propertiesPlugin[_DYN_CONTEXT /* @min:%2econtext */]._sessionManager) {
|
312 | propertiesPlugin[_DYN_CONTEXT /* @min:%2econtext */]._sessionManager.backup();
|
313 | }
|
314 | }
|
315 | }
|
316 | };
|
317 | var added_1 = false;
|
318 | if (!_houseKeepingNamespace) {
|
319 | _houseKeepingNamespace = mergeEvtNamespace(_evtNamespace, _core[STR_EVT_NAMESPACE /* @min:%2eevtNamespace */] && _core[STR_EVT_NAMESPACE /* @min:%2eevtNamespace */]());
|
320 | }
|
321 | // Will be recalled if any referenced config properties change
|
322 | _addUnloadHook(onConfigChange(_config, function (details) {
|
323 | var coreConfig = details.cfg;
|
324 | var analyticsPlugin = appInsightsInstance.appInsights;
|
325 | var ctx = createProcessTelemetryContext(null, coreConfig, analyticsPlugin.core);
|
326 | var extConfig = ctx.getExtCfg(analyticsPlugin.identifier || AnalyticsPluginIdentifier);
|
327 | // As we could get recalled, remove any previously registered event handlers first
|
328 | _removePageEventHandlers();
|
329 | var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents;
|
330 | if (!extConfig.disableFlushOnBeforeUnload) {
|
331 | // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
|
332 | // As just hooking the window does not always fire (on chrome) for page navigation's.
|
333 | if (addPageUnloadEventListener(performHousekeeping_1, excludePageUnloadEvents, _houseKeepingNamespace)) {
|
334 | added_1 = true;
|
335 | }
|
336 | // We also need to hook the pagehide and visibilitychange events as not all versions of Safari support load/unload events.
|
337 | if (addPageHideEventListener(performHousekeeping_1, excludePageUnloadEvents, _houseKeepingNamespace)) {
|
338 | added_1 = true;
|
339 | }
|
340 | // A reactNative app may not have a window and therefore the beforeunload/pagehide events -- so don't
|
341 | // log the failure in this case
|
342 | if (!added_1 && !isReactNative()) {
|
343 | _throwInternal(_core.logger, 1 /* eLoggingSeverity.CRITICAL */, 19 /* _eInternalMessageId.FailedToAddHandlerForOnBeforeUnload */, "Could not add handler for beforeunload and pagehide");
|
344 | }
|
345 | }
|
346 | if (!added_1 && !extConfig.disableFlushOnUnload) {
|
347 | // If we didn't add the normal set then attempt to add the pagehide and visibilitychange only
|
348 | addPageHideEventListener(performHousekeeping_1, excludePageUnloadEvents, _houseKeepingNamespace);
|
349 | }
|
350 | }));
|
351 | }
|
352 | };
|
353 | _self.getSender = function () {
|
354 | return _sender;
|
355 | };
|
356 | _self.unload = function (isAsync, unloadComplete, cbTimeout) {
|
357 | var unloadDone = false;
|
358 | var result;
|
359 | if (isAsync && !unloadComplete) {
|
360 | result = createPromise(function (resolve) {
|
361 | // Set the callback to the promise resolve callback
|
362 | unloadComplete = resolve;
|
363 | });
|
364 | }
|
365 | function _unloadCallback(unloadState) {
|
366 | if (!unloadDone) {
|
367 | unloadDone = true;
|
368 | _initDefaults();
|
369 | unloadComplete && unloadComplete(unloadState);
|
370 | }
|
371 | }
|
372 | _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */](isAsync);
|
373 | _removePageEventHandlers();
|
374 | _core.unload && _core.unload(isAsync, _unloadCallback, cbTimeout);
|
375 | return result;
|
376 | };
|
377 | proxyFunctions(_self, _analyticsPlugin, [
|
378 | STR_GET_COOKIE_MGR,
|
379 | STR_TRACK_EVENT,
|
380 | STR_TRACK_PAGE_VIEW,
|
381 | "trackPageViewPerformance",
|
382 | STR_TRACK_EXCEPTION,
|
383 | "_onerror",
|
384 | STR_TRACK_TRACE,
|
385 | STR_TRACK_METRIC,
|
386 | STR_START_TRACK_PAGE,
|
387 | STR_STOP_TRACK_PAGE,
|
388 | STR_START_TRACK_EVENT,
|
389 | STR_STOP_TRACK_EVENT
|
390 | ]);
|
391 | proxyFunctions(_self, _getCurrentDependencies, [
|
392 | STR_TRACK_DEPENDENCY_DATA,
|
393 | "addDependencyListener",
|
394 | "addDependencyInitializer"
|
395 | ]);
|
396 | proxyFunctions(_self, _core, [
|
397 | STR_ADD_TELEMETRY_INITIALIZER,
|
398 | STR_POLL_INTERNAL_LOGS,
|
399 | "stopPollingInternalLogs",
|
400 | STR_GET_PLUGIN,
|
401 | "addPlugin",
|
402 | STR_EVT_NAMESPACE,
|
403 | "addUnloadCb",
|
404 | "getTraceCtx",
|
405 | "updateCfg",
|
406 | "onCfgChange"
|
407 | ]);
|
408 | proxyFunctions(_self, function () {
|
409 | var context = properties[_DYN_CONTEXT /* @min:%2econtext */];
|
410 | return context ? context.user : null;
|
411 | }, [
|
412 | STR_SET_AUTHENTICATED_USER_CONTEXT,
|
413 | STR_CLEAR_AUTHENTICATED_USER_CONTEXT
|
414 | ]);
|
415 | // Using a function to support the dynamic adding / removal of plugins, so this will always return the current value
|
416 | function _getCurrentDependencies() {
|
417 | return dependencies;
|
418 | }
|
419 | function _initDefaults() {
|
420 | _evtNamespace = createUniqueNamespace("AISKU");
|
421 | _houseKeepingNamespace = null;
|
422 | dependencies = null;
|
423 | properties = null;
|
424 | _sender = null;
|
425 | _snippetVersion = null;
|
426 | _throttleMgr = null;
|
427 | _iKeySentMessage = false;
|
428 | _cdnSentMessage = false;
|
429 | _sdkVerSentMessage = false;
|
430 | _cfgSyncPlugin = new CfgSyncPlugin();
|
431 | }
|
432 | function _removePageEventHandlers() {
|
433 | // Remove any registered event handlers
|
434 | if (_houseKeepingNamespace) {
|
435 | removePageUnloadEventListener(null, _houseKeepingNamespace);
|
436 | removePageHideEventListener(null, _houseKeepingNamespace);
|
437 | }
|
438 | }
|
439 | function _addUnloadHook(hooks) {
|
440 | _core.addUnloadHook(hooks);
|
441 | }
|
442 | });
|
443 | }
|
444 | // Analytics Plugin
|
445 | // Removed Stub for AppInsightsSku.prototype.getCookieMgr.
|
446 | // Removed Stub for AppInsightsSku.prototype.trackEvent.
|
447 | // Removed Stub for AppInsightsSku.prototype.trackPageView.
|
448 | // Removed Stub for AppInsightsSku.prototype.trackPageViewPerformance.
|
449 | // Removed Stub for AppInsightsSku.prototype.trackException.
|
450 | // Removed Stub for AppInsightsSku.prototype._onerror.
|
451 | // Removed Stub for AppInsightsSku.prototype.trackTrace.
|
452 | // Removed Stub for AppInsightsSku.prototype.trackMetric.
|
453 | // Removed Stub for AppInsightsSku.prototype.startTrackPage.
|
454 | // Removed Stub for AppInsightsSku.prototype.stopTrackPage.
|
455 | // Removed Stub for AppInsightsSku.prototype.startTrackEvent.
|
456 | // Removed Stub for AppInsightsSku.prototype.stopTrackEvent.
|
457 | // Removed Stub for AppInsightsSku.prototype.addTelemetryInitializer.
|
458 | // Properties Plugin
|
459 | // Removed Stub for AppInsightsSku.prototype.setAuthenticatedUserContext.
|
460 | // Removed Stub for AppInsightsSku.prototype.clearAuthenticatedUserContext.
|
461 | // Dependencies Plugin
|
462 | // Removed Stub for AppInsightsSku.prototype.trackDependencyData.
|
463 | // Misc
|
464 | // Removed Stub for AppInsightsSku.prototype.flush.
|
465 | // Removed Stub for AppInsightsSku.prototype.onunloadFlush.
|
466 | // Removed Stub for AppInsightsSku.prototype.loadAppInsights.
|
467 | // Removed Stub for AppInsightsSku.prototype.updateSnippetDefinitions.
|
468 | // Removed Stub for AppInsightsSku.prototype.emptyQueue.
|
469 | // Removed Stub for AppInsightsSku.prototype.pollInternalLogs.
|
470 | // Removed Stub for AppInsightsSku.prototype.stopPollingInternalLogs.
|
471 | // Removed Stub for AppInsightsSku.prototype.addHousekeepingBeforeUnload.
|
472 | // Removed Stub for AppInsightsSku.prototype.getSender.
|
473 | // Removed Stub for AppInsightsSku.prototype.unload.
|
474 | // Removed Stub for AppInsightsSku.prototype.getPlugin.
|
475 | // Removed Stub for AppInsightsSku.prototype.addPlugin.
|
476 | // Removed Stub for AppInsightsSku.prototype.updateCfg.
|
477 | // Removed Stub for AppInsightsSku.prototype.evtNamespace.
|
478 | // Removed Stub for AppInsightsSku.prototype.addUnloadCb.
|
479 | // Removed Stub for AppInsightsSku.prototype.addDependencyListener.
|
480 | /**
|
481 | * Add an dependency telemetry initializer callback function to allow populating additional properties or drop the request.
|
482 | * It is called after the dependency call has completed and any available performance details are available. A dependency
|
483 | * initializer is similar to the TelemetryInitializer function but it allows you to block the reporting of the dependency
|
484 | * request so that it doesn't count against the `maxAjaxCallsPerView`.
|
485 | * @param dependencyInitializer - The Dependency Telemetry Initializer function
|
486 | * @returns - A IDependencyInitializerHandler to enable the initializer to be removed
|
487 | */
|
488 | AppInsightsSku.prototype.addDependencyInitializer = function (dependencyInitializer) {
|
489 | return null;
|
490 | };
|
491 | // Removed Stub for AppInsightsSku.prototype.getTraceCtx.
|
492 | // Removed Stub for AppInsightsSku.prototype.onCfgChange.
|
493 | return AppInsightsSku;
|
494 | }());
|
495 | export { AppInsightsSku };
|
496 | // tslint:disable-next-line
|
497 | export function _findSdkSourceFile() {
|
498 | if (_internalSdkSrc) {
|
499 | // Use the cached value
|
500 | return _internalSdkSrc;
|
501 | }
|
502 | var sdkSrc = null;
|
503 | var isModule = false;
|
504 | var cdns = [
|
505 | "://js.monitor.azure.com/",
|
506 | "://az416426.vo.msecnd.net/"
|
507 | ];
|
508 | try {
|
509 | // Try and determine whether the sdk is being loaded from the CDN
|
510 | // currentScript is only valid during initial processing
|
511 | var scrpt = (document || {}).currentScript;
|
512 | if (scrpt) {
|
513 | sdkSrc = scrpt.src;
|
514 | // } else {
|
515 | // // We need to update to at least typescript 2.9 for this to work :-(
|
516 | // // Leaving as a stub for now so after we upgrade this breadcrumb is available
|
517 | // let meta = import.meta;
|
518 | // sdkSrc = (meta || {}).url;
|
519 | // isModule = true;
|
520 | }
|
521 | }
|
522 | catch (e) {
|
523 | // eslint-disable-next-line no-empty
|
524 | }
|
525 | if (sdkSrc) {
|
526 | try {
|
527 | var url_1 = sdkSrc.toLowerCase();
|
528 | if (url_1) {
|
529 | var src_1 = "";
|
530 | arrForEach(cdns, function (value, idx) {
|
531 | if (strIndexOf(url_1, value) !== -1) {
|
532 | src_1 = "cdn" + (idx + 1);
|
533 | if (strIndexOf(url_1, "/scripts/") === -1) {
|
534 | if (strIndexOf(url_1, "/next/") !== -1) {
|
535 | src_1 += "-next";
|
536 | }
|
537 | else if (strIndexOf(url_1, "/beta/") !== -1) {
|
538 | src_1 += "-beta";
|
539 | }
|
540 | }
|
541 | _internalSdkSrc = src_1 + (isModule ? ".mod" : "");
|
542 | return -1;
|
543 | }
|
544 | });
|
545 | }
|
546 | }
|
547 | catch (e) {
|
548 | // eslint-disable-next-line no-empty
|
549 | }
|
550 | // Cache the found value so we don't have to look it up again
|
551 | _internalSdkSrc = sdkSrc;
|
552 | }
|
553 | return _internalSdkSrc;
|
554 | }
|
555 | //# sourceMappingURL=AISku.js.map |
\ | No newline at end of file |