@microsoft/applicationinsights-react-js 3.3.0-beta.2203-10 → 3.3.0-beta.2203-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - React Plugin, 3.3.0-beta.2203-10
2
+ * Application Insights JavaScript SDK - React Plugin, 3.3.0-beta.2203-11
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -738,6 +738,17 @@
738
738
  }
739
739
  }
740
740
  }
741
+ function proxyFunctions(target, source, functionsToProxy, overwriteTarget) {
742
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
743
+ if (target && source && isObject(target) && isArray(functionsToProxy)) {
744
+ arrForEach(functionsToProxy, function (theFuncName) {
745
+ if (isString(theFuncName)) {
746
+ proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
747
+ }
748
+ });
749
+ }
750
+ return target;
751
+ }
741
752
  function createEnumStyle(values) {
742
753
  var enumClass = {};
743
754
  objForEachKey(values, function (field, value) {
@@ -1269,7 +1280,7 @@
1269
1280
  }
1270
1281
 
1271
1282
  var _objDefineProperty = ObjDefineProperty;
1272
- var version = "2.7.3";
1283
+ var version = "2.8.0-beta.2203-11";
1273
1284
  var instanceName = "." + newId(6);
1274
1285
  var _dataUid = 0;
1275
1286
  function _createAccessor(target, prop, value) {
@@ -2148,7 +2159,7 @@
2148
2159
  eventName = (eventName || "") + theNamespace_1;
2149
2160
  }
2150
2161
  }
2151
- var parsedEvent = (eventNamespace.exec(eventName) || []);
2162
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
2152
2163
  return {
2153
2164
  type: parsedEvent[1],
2154
2165
  ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
@@ -2408,98 +2419,91 @@
2408
2419
  var ReactPlugin = /** @class */ (function (_super) {
2409
2420
  __extendsFn(ReactPlugin, _super);
2410
2421
  function ReactPlugin() {
2411
- var _this = _super !== null && _super.apply(this, arguments) || this;
2422
+ var _this = _super.call(this) || this;
2412
2423
  _this.priority = 185;
2413
2424
  _this.identifier = 'ReactPlugin';
2414
- return _this;
2415
- }
2416
- ReactPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
2417
- var _this = this;
2418
- _super.prototype.initialize.call(this, config, core, extensions, pluginChain);
2419
- this._extensionConfig =
2420
- config.extensionConfig && config.extensionConfig[this.identifier]
2421
- ? config.extensionConfig[this.identifier]
2422
- : { history: null };
2423
- arrForEach(extensions, function (ext) {
2424
- var identifier = ext.identifier;
2425
- if (identifier === 'ApplicationInsightsAnalytics') {
2426
- _this._analyticsPlugin = ext;
2425
+ var _analyticsPlugin;
2426
+ var _extensionConfig;
2427
+ var _unlisten;
2428
+ var _pageViewTimer;
2429
+ dynamicProto(ReactPlugin, _this, function (_self, _base) {
2430
+ _initDefaults();
2431
+ _self.initialize = function (config, core, extensions, pluginChain) {
2432
+ _super.prototype.initialize.call(_this, config, core, extensions, pluginChain);
2433
+ _extensionConfig =
2434
+ config.extensionConfig && config.extensionConfig[_self.identifier]
2435
+ ? config.extensionConfig[_self.identifier]
2436
+ : { history: null };
2437
+ arrForEach(extensions, function (ext) {
2438
+ var identifier = ext.identifier;
2439
+ if (identifier === 'ApplicationInsightsAnalytics') {
2440
+ _analyticsPlugin = ext;
2441
+ }
2442
+ });
2443
+ if (_extensionConfig.history) {
2444
+ _addHistoryListener(_extensionConfig.history);
2445
+ var pageViewTelemetry = {
2446
+ uri: _extensionConfig.history.location.pathname
2447
+ };
2448
+ _self.trackPageView(pageViewTelemetry);
2449
+ }
2450
+ };
2451
+ _self.getCookieMgr = function () {
2452
+ return safeGetCookieMgr(_self.core);
2453
+ };
2454
+ _self.getAppInsights = _getAnalytics;
2455
+ _self.processTelemetry = function (event, itemCtx) {
2456
+ _self.processNext(event, itemCtx);
2457
+ };
2458
+ _self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {
2459
+ if (isFunction(_unlisten)) {
2460
+ _unlisten();
2461
+ }
2462
+ if (_pageViewTimer) {
2463
+ clearTimeout(_pageViewTimer);
2464
+ }
2465
+ _initDefaults();
2466
+ };
2467
+ proxyFunctions(_self, _getAnalytics, [
2468
+ "trackMetric",
2469
+ "trackPageView",
2470
+ "trackEvent",
2471
+ "trackException",
2472
+ "trackTrace",
2473
+ ]);
2474
+ function _initDefaults() {
2475
+ _analyticsPlugin = null;
2476
+ _extensionConfig = null;
2477
+ _unlisten = null;
2478
+ _pageViewTimer = null;
2479
+ }
2480
+ function _getAnalytics() {
2481
+ if (!_analyticsPlugin) {
2482
+ _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2483
+ }
2484
+ return _analyticsPlugin;
2427
2485
  }
2486
+ function _addHistoryListener(history) {
2487
+ var locationListener = function (arg) {
2488
+ var locn = null;
2489
+ if ("location" in arg) {
2490
+ locn = arg["location"];
2491
+ }
2492
+ else {
2493
+ locn = arg;
2494
+ }
2495
+ _pageViewTimer = setTimeout(function () {
2496
+ _pageViewTimer = null;
2497
+ var pageViewTelemetry = { uri: locn.pathname };
2498
+ _self.trackPageView(pageViewTelemetry);
2499
+ }, 500);
2500
+ };
2501
+ _unlisten = history.listen(locationListener);
2502
+ }
2503
+ objDefineAccessors(_self, "_extensionConfig", function () { return _extensionConfig; });
2428
2504
  });
2429
- if (this._extensionConfig.history) {
2430
- this.addHistoryListener(this._extensionConfig.history);
2431
- var pageViewTelemetry = {
2432
- uri: this._extensionConfig.history.location.pathname
2433
- };
2434
- this.trackPageView(pageViewTelemetry);
2435
- }
2436
- };
2437
- ReactPlugin.prototype.getCookieMgr = function () {
2438
- return safeGetCookieMgr(this.core);
2439
- };
2440
- ReactPlugin.prototype.getAppInsights = function () {
2441
- return this._analyticsPlugin;
2442
- };
2443
- ReactPlugin.prototype.processTelemetry = function (event, itemCtx) {
2444
- this.processNext(event, itemCtx);
2445
- };
2446
- ReactPlugin.prototype.trackMetric = function (metric, customProperties) {
2447
- if (this._analyticsPlugin) {
2448
- this._analyticsPlugin.trackMetric(metric, customProperties);
2449
- }
2450
- else {
2451
- this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2452
- }
2453
- };
2454
- ReactPlugin.prototype.trackPageView = function (pageView) {
2455
- if (this._analyticsPlugin) {
2456
- this._analyticsPlugin.trackPageView(pageView);
2457
- }
2458
- else {
2459
- this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2460
- }
2461
- };
2462
- ReactPlugin.prototype.trackEvent = function (event, customProperties) {
2463
- if (this._analyticsPlugin) {
2464
- this._analyticsPlugin.trackEvent(event, customProperties);
2465
- }
2466
- else {
2467
- this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2468
- }
2469
- };
2470
- ReactPlugin.prototype.trackException = function (exception, customProperties) {
2471
- if (this._analyticsPlugin) {
2472
- this._analyticsPlugin.trackException(exception, customProperties);
2473
- }
2474
- else {
2475
- this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2476
- }
2477
- };
2478
- ReactPlugin.prototype.trackTrace = function (trace, customProperties) {
2479
- if (this._analyticsPlugin) {
2480
- this._analyticsPlugin.trackTrace(trace, customProperties);
2481
- }
2482
- else {
2483
- this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, React plugin telemetry will not be sent: ");
2484
- }
2485
- };
2486
- ReactPlugin.prototype.addHistoryListener = function (history) {
2487
- var _this = this;
2488
- var locationListener = function (arg) {
2489
- var locn = null;
2490
- if ("location" in arg) {
2491
- locn = arg["location"];
2492
- }
2493
- else {
2494
- locn = arg;
2495
- }
2496
- setTimeout(function () {
2497
- var pageViewTelemetry = { uri: locn.pathname };
2498
- _this.trackPageView(pageViewTelemetry);
2499
- }, 500);
2500
- };
2501
- history.listen(locationListener);
2502
- };
2505
+ return _this;
2506
+ }
2503
2507
  return ReactPlugin;
2504
2508
  }(BaseTelemetryPlugin));
2505
2509
  var ReactPlugin$1 = ReactPlugin;
@@ -2646,7 +2650,7 @@
2646
2650
  trackedData.idleCount * trackedData.idleTimeout) /
2647
2651
  1000);
2648
2652
  }
2649
- var useComponentTracking = function (reactPlugin, componentName) {
2653
+ var useComponentTracking = function (reactPlugin, componentName, customProperties) {
2650
2654
  var tracking = React.useRef({
2651
2655
  hookTimestamp: dateNow(),
2652
2656
  firstActiveTimestamp: 0,
@@ -2685,7 +2689,7 @@
2685
2689
  name: "React Component Engaged Time (seconds)",
2686
2690
  sampleCount: 1
2687
2691
  };
2688
- var additionalProperties = { "Component Name": componentName };
2692
+ var additionalProperties = __assignFn({ "Component Name": componentName }, customProperties);
2689
2693
  reactPlugin.trackMetric(metricData, additionalProperties);
2690
2694
  };
2691
2695
  }, []);