@microsoft/applicationinsights-react-js 3.3.2-nightly.2204-22 → 3.3.3-nightly.2205-03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-react-js.js +92 -452
- package/browser/applicationinsights-react-js.js.map +1 -1
- package/browser/applicationinsights-react-js.min.js +2 -2
- package/browser/applicationinsights-react-js.min.js.map +1 -1
- package/dist/applicationinsights-react-js.api.json +472 -1
- package/dist/applicationinsights-react-js.api.md +31 -0
- package/dist/applicationinsights-react-js.d.ts +23 -1
- package/dist/applicationinsights-react-js.js +92 -452
- package/dist/applicationinsights-react-js.js.map +1 -1
- package/dist/applicationinsights-react-js.min.js +2 -2
- package/dist/applicationinsights-react-js.min.js.map +1 -1
- package/dist/applicationinsights-react-js.rollup.d.ts +23 -1
- package/dist-esm/AppInsightsContext.js +1 -1
- package/dist-esm/AppInsightsErrorBoundary.js +1 -1
- package/dist-esm/Interfaces/IReactExtensionConfig.js +1 -1
- package/dist-esm/ReactPlugin.js +1 -1
- package/dist-esm/applicationinsights-react-js.js +3 -3
- package/dist-esm/applicationinsights-react-js.js.map +1 -1
- package/dist-esm/useTrackEvent.js +1 -1
- package/dist-esm/useTrackMetric.js +1 -1
- package/dist-esm/withAITracking.js +78 -64
- package/dist-esm/withAITracking.js.map +1 -1
- package/package.json +4 -4
- package/src/applicationinsights-react-js.ts +3 -2
- package/src/withAITracking.tsx +90 -70
- package/types/applicationinsights-react-js.d.ts +2 -2
- package/types/tsdoc-metadata.json +1 -1
- package/types/withAITracking.d.ts +21 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Microsoft Application Insights react plugin, 3.3.
|
|
2
|
+
* Microsoft Application Insights react plugin, 3.3.3-nightly.2205-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
*
|
|
@@ -38,6 +38,28 @@ import { SetStateAction } from 'react';
|
|
|
38
38
|
|
|
39
39
|
declare type AIReactCustomEvent<T> = Dispatch<SetStateAction<T>>;
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Higher-order component base class to hook Application Insights tracking
|
|
43
|
+
* in a React component's lifecycle.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class AITrackedComponentBase<P> extends React_2.Component<P> {
|
|
46
|
+
protected _mountTimestamp: number;
|
|
47
|
+
protected _firstActiveTimestamp: number;
|
|
48
|
+
protected _idleStartTimestamp: number;
|
|
49
|
+
protected _lastActiveTimestamp: number;
|
|
50
|
+
protected _totalIdleTime: number;
|
|
51
|
+
protected _idleCount: number;
|
|
52
|
+
protected _idleTimeout: number;
|
|
53
|
+
protected _intervalId?: any;
|
|
54
|
+
protected _componentName: string;
|
|
55
|
+
protected _reactPlugin: ReactPlugin;
|
|
56
|
+
constructor(props: P, reactPlugin: ReactPlugin, componentName: string);
|
|
57
|
+
componentDidMount(): void;
|
|
58
|
+
componentWillUnmount(): void;
|
|
59
|
+
protected trackActivity: (e: React_2.SyntheticEvent<any>) => void;
|
|
60
|
+
private getEngagementTimeSeconds;
|
|
61
|
+
}
|
|
62
|
+
|
|
41
63
|
export declare const AppInsightsContext: AppInsightsReactContext;
|
|
42
64
|
|
|
43
65
|
export declare class AppInsightsErrorBoundary extends React_3.Component<IAppInsightsErrorBoundaryProps, IAppInsightsErrorBoundaryState> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Plugin, 3.3.
|
|
2
|
+
* Application Insights JavaScript SDK - React Plugin, 3.3.3-nightly.2205-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
import { createContext, useContext } from "react";
|
package/dist-esm/ReactPlugin.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Plugin, 3.3.
|
|
2
|
+
* Application Insights JavaScript SDK - React Plugin, 3.3.3-nightly.2205-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import ReactPlugin from "./ReactPlugin";
|
|
8
|
-
import withAITracking from "./withAITracking";
|
|
8
|
+
import withAITracking, { AITrackedComponentBase } from "./withAITracking";
|
|
9
9
|
import AppInsightsErrorBoundary from "./AppInsightsErrorBoundary";
|
|
10
10
|
import { AppInsightsContext, useAppInsightsContext } from "./AppInsightsContext";
|
|
11
11
|
import useTrackEvent from "./useTrackEvent";
|
|
12
12
|
import useTrackMetric from "./useTrackMetric";
|
|
13
|
-
export { ReactPlugin, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric };
|
|
13
|
+
export { ReactPlugin, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric, AITrackedComponentBase };
|
|
14
14
|
//# sourceMappingURL=applicationinsights-react-js.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationinsights-react-js.js.map","sources":["applicationinsights-react-js.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport ReactPlugin from \"./ReactPlugin\";\r\nimport withAITracking from \"./withAITracking\";\r\nimport AppInsightsErrorBoundary from \"./AppInsightsErrorBoundary\";\r\nimport { AppInsightsContext, useAppInsightsContext } from \"./AppInsightsContext\";\r\nimport useTrackEvent from \"./useTrackEvent\";\r\nimport useTrackMetric from \"./useTrackMetric\";\r\nexport { ReactPlugin, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric };\r\n//# sourceMappingURL=applicationinsights-react-js.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"applicationinsights-react-js.js.map","sources":["applicationinsights-react-js.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport ReactPlugin from \"./ReactPlugin\";\r\nimport withAITracking, { AITrackedComponentBase } from \"./withAITracking\";\r\nimport AppInsightsErrorBoundary from \"./AppInsightsErrorBoundary\";\r\nimport { AppInsightsContext, useAppInsightsContext } from \"./AppInsightsContext\";\r\nimport useTrackEvent from \"./useTrackEvent\";\r\nimport useTrackMetric from \"./useTrackMetric\";\r\nexport { ReactPlugin, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric, AITrackedComponentBase };\r\n//# sourceMappingURL=applicationinsights-react-js.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Plugin, 3.3.
|
|
2
|
+
* Application Insights JavaScript SDK - React Plugin, 3.3.3-nightly.2205-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
import { __assignFn as __assign } from "@microsoft/applicationinsights-shims";
|
|
@@ -1,12 +1,85 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Plugin, 3.3.
|
|
2
|
+
* Application Insights JavaScript SDK - React Plugin, 3.3.3-nightly.2205-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import { __assignFn as __assign, __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
|
|
8
|
-
import {
|
|
8
|
+
import { dateNow } from '@microsoft/applicationinsights-core-js';
|
|
9
9
|
import * as React from 'react';
|
|
10
|
+
/**
|
|
11
|
+
* Higher-order component base class to hook Application Insights tracking
|
|
12
|
+
* in a React component's lifecycle.
|
|
13
|
+
*/
|
|
14
|
+
var AITrackedComponentBase = /** @class */ (function (_super) {
|
|
15
|
+
__extends(AITrackedComponentBase, _super);
|
|
16
|
+
function AITrackedComponentBase(props, reactPlugin, componentName) {
|
|
17
|
+
var _this = _super.call(this, props) || this;
|
|
18
|
+
_this._mountTimestamp = 0;
|
|
19
|
+
_this._firstActiveTimestamp = 0;
|
|
20
|
+
_this._idleStartTimestamp = 0;
|
|
21
|
+
_this._lastActiveTimestamp = 0;
|
|
22
|
+
_this._totalIdleTime = 0;
|
|
23
|
+
_this._idleCount = 0;
|
|
24
|
+
_this._idleTimeout = 5000;
|
|
25
|
+
_this.trackActivity = function (e) {
|
|
26
|
+
if (_this._firstActiveTimestamp === 0) {
|
|
27
|
+
_this._firstActiveTimestamp = dateNow();
|
|
28
|
+
_this._lastActiveTimestamp = _this._firstActiveTimestamp;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
_this._lastActiveTimestamp = dateNow();
|
|
32
|
+
}
|
|
33
|
+
if (_this._idleStartTimestamp > 0) {
|
|
34
|
+
var lastIdleTime = _this._lastActiveTimestamp - _this._idleStartTimestamp;
|
|
35
|
+
_this._totalIdleTime += lastIdleTime;
|
|
36
|
+
_this._idleStartTimestamp = 0;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
_this._reactPlugin = reactPlugin;
|
|
40
|
+
_this._componentName = componentName;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
AITrackedComponentBase.prototype.componentDidMount = function () {
|
|
44
|
+
var _this = this;
|
|
45
|
+
this._mountTimestamp = dateNow();
|
|
46
|
+
this._firstActiveTimestamp = 0;
|
|
47
|
+
this._totalIdleTime = 0;
|
|
48
|
+
this._lastActiveTimestamp = 0;
|
|
49
|
+
this._idleStartTimestamp = 0;
|
|
50
|
+
this._idleCount = 0;
|
|
51
|
+
this._intervalId = setInterval(function () {
|
|
52
|
+
if (_this._lastActiveTimestamp > 0 && _this._idleStartTimestamp === 0 && dateNow() - _this._lastActiveTimestamp >= _this._idleTimeout) {
|
|
53
|
+
_this._idleStartTimestamp = dateNow();
|
|
54
|
+
_this._idleCount++;
|
|
55
|
+
}
|
|
56
|
+
}, 100);
|
|
57
|
+
};
|
|
58
|
+
AITrackedComponentBase.prototype.componentWillUnmount = function () {
|
|
59
|
+
if (this._mountTimestamp === 0) {
|
|
60
|
+
throw new Error('withAITracking:componentWillUnmount: mountTimestamp is not initialized.');
|
|
61
|
+
}
|
|
62
|
+
if (this._intervalId) {
|
|
63
|
+
clearInterval(this._intervalId);
|
|
64
|
+
}
|
|
65
|
+
if (this._firstActiveTimestamp === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var engagementTime = this.getEngagementTimeSeconds();
|
|
69
|
+
var metricData = {
|
|
70
|
+
average: engagementTime,
|
|
71
|
+
name: 'React Component Engaged Time (seconds)',
|
|
72
|
+
sampleCount: 1
|
|
73
|
+
};
|
|
74
|
+
var additionalProperties = { 'Component Name': this._componentName };
|
|
75
|
+
this._reactPlugin.trackMetric(metricData, additionalProperties);
|
|
76
|
+
};
|
|
77
|
+
AITrackedComponentBase.prototype.getEngagementTimeSeconds = function () {
|
|
78
|
+
return (dateNow() - this._firstActiveTimestamp - this._totalIdleTime - this._idleCount * this._idleTimeout) / 1000;
|
|
79
|
+
};
|
|
80
|
+
return AITrackedComponentBase;
|
|
81
|
+
}(React.Component));
|
|
82
|
+
export { AITrackedComponentBase };
|
|
10
83
|
/**
|
|
11
84
|
* Higher-order component function to hook Application Insights tracking
|
|
12
85
|
* in a React component's lifecycle.
|
|
@@ -28,73 +101,14 @@ export default function withAITracking(reactPlugin, Component, componentName, cl
|
|
|
28
101
|
}
|
|
29
102
|
return /** @class */ (function (_super) {
|
|
30
103
|
__extends(class_1, _super);
|
|
31
|
-
function class_1() {
|
|
32
|
-
|
|
33
|
-
_this._mountTimestamp = 0;
|
|
34
|
-
_this._firstActiveTimestamp = 0;
|
|
35
|
-
_this._idleStartTimestamp = 0;
|
|
36
|
-
_this._lastActiveTimestamp = 0;
|
|
37
|
-
_this._totalIdleTime = 0;
|
|
38
|
-
_this._idleCount = 0;
|
|
39
|
-
_this._idleTimeout = 5000;
|
|
40
|
-
_this.trackActivity = function (e) {
|
|
41
|
-
if (_this._firstActiveTimestamp === 0) {
|
|
42
|
-
_this._firstActiveTimestamp = CoreUtils.dateNow();
|
|
43
|
-
_this._lastActiveTimestamp = _this._firstActiveTimestamp;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
_this._lastActiveTimestamp = CoreUtils.dateNow();
|
|
47
|
-
}
|
|
48
|
-
if (_this._idleStartTimestamp > 0) {
|
|
49
|
-
var lastIdleTime = _this._lastActiveTimestamp - _this._idleStartTimestamp;
|
|
50
|
-
_this._totalIdleTime += lastIdleTime;
|
|
51
|
-
_this._idleStartTimestamp = 0;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return _this;
|
|
104
|
+
function class_1(props) {
|
|
105
|
+
return _super.call(this, props, reactPlugin, componentName) || this;
|
|
55
106
|
}
|
|
56
|
-
class_1.prototype.componentDidMount = function () {
|
|
57
|
-
var _this = this;
|
|
58
|
-
this._mountTimestamp = CoreUtils.dateNow();
|
|
59
|
-
this._firstActiveTimestamp = 0;
|
|
60
|
-
this._totalIdleTime = 0;
|
|
61
|
-
this._lastActiveTimestamp = 0;
|
|
62
|
-
this._idleStartTimestamp = 0;
|
|
63
|
-
this._idleCount = 0;
|
|
64
|
-
this._intervalId = setInterval(function () {
|
|
65
|
-
if (_this._lastActiveTimestamp > 0 && _this._idleStartTimestamp === 0 && CoreUtils.dateNow() - _this._lastActiveTimestamp >= _this._idleTimeout) {
|
|
66
|
-
_this._idleStartTimestamp = CoreUtils.dateNow();
|
|
67
|
-
_this._idleCount++;
|
|
68
|
-
}
|
|
69
|
-
}, 100);
|
|
70
|
-
};
|
|
71
|
-
class_1.prototype.componentWillUnmount = function () {
|
|
72
|
-
if (this._mountTimestamp === 0) {
|
|
73
|
-
throw new Error('withAITracking:componentWillUnmount: mountTimestamp is not initialized.');
|
|
74
|
-
}
|
|
75
|
-
if (this._intervalId) {
|
|
76
|
-
clearInterval(this._intervalId);
|
|
77
|
-
}
|
|
78
|
-
if (this._firstActiveTimestamp === 0) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
var engagementTime = this.getEngagementTimeSeconds();
|
|
82
|
-
var metricData = {
|
|
83
|
-
average: engagementTime,
|
|
84
|
-
name: 'React Component Engaged Time (seconds)',
|
|
85
|
-
sampleCount: 1
|
|
86
|
-
};
|
|
87
|
-
var additionalProperties = { 'Component Name': componentName };
|
|
88
|
-
reactPlugin.trackMetric(metricData, additionalProperties);
|
|
89
|
-
};
|
|
90
107
|
class_1.prototype.render = function () {
|
|
91
108
|
return (React.createElement("div", { onKeyDown: this.trackActivity, onMouseMove: this.trackActivity, onScroll: this.trackActivity, onMouseDown: this.trackActivity, onTouchStart: this.trackActivity, onTouchMove: this.trackActivity, className: className },
|
|
92
109
|
React.createElement(Component, __assign({}, this.props))));
|
|
93
110
|
};
|
|
94
|
-
class_1.prototype.getEngagementTimeSeconds = function () {
|
|
95
|
-
return (CoreUtils.dateNow() - this._firstActiveTimestamp - this._totalIdleTime - this._idleCount * this._idleTimeout) / 1000;
|
|
96
|
-
};
|
|
97
111
|
return class_1;
|
|
98
|
-
}(
|
|
112
|
+
}(AITrackedComponentBase));
|
|
99
113
|
}
|
|
100
114
|
//# sourceMappingURL=withAITracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAITracking.js.map","sources":["withAITracking.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { __assign, __extends } from \"tslib\";\r\nimport {
|
|
1
|
+
{"version":3,"file":"withAITracking.js.map","sources":["withAITracking.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { __assign, __extends } from \"tslib\";\r\nimport { dateNow } from '@microsoft/applicationinsights-core-js';\r\nimport * as React from 'react';\r\n/**\r\n * Higher-order component base class to hook Application Insights tracking\r\n * in a React component's lifecycle.\r\n */\r\nvar AITrackedComponentBase = /** @class */ (function (_super) {\r\n __extends(AITrackedComponentBase, _super);\r\n function AITrackedComponentBase(props, reactPlugin, componentName) {\r\n var _this = _super.call(this, props) || this;\r\n _this._mountTimestamp = 0;\r\n _this._firstActiveTimestamp = 0;\r\n _this._idleStartTimestamp = 0;\r\n _this._lastActiveTimestamp = 0;\r\n _this._totalIdleTime = 0;\r\n _this._idleCount = 0;\r\n _this._idleTimeout = 5000;\r\n _this.trackActivity = function (e) {\r\n if (_this._firstActiveTimestamp === 0) {\r\n _this._firstActiveTimestamp = dateNow();\r\n _this._lastActiveTimestamp = _this._firstActiveTimestamp;\r\n }\r\n else {\r\n _this._lastActiveTimestamp = dateNow();\r\n }\r\n if (_this._idleStartTimestamp > 0) {\r\n var lastIdleTime = _this._lastActiveTimestamp - _this._idleStartTimestamp;\r\n _this._totalIdleTime += lastIdleTime;\r\n _this._idleStartTimestamp = 0;\r\n }\r\n };\r\n _this._reactPlugin = reactPlugin;\r\n _this._componentName = componentName;\r\n return _this;\r\n }\r\n AITrackedComponentBase.prototype.componentDidMount = function () {\r\n var _this = this;\r\n this._mountTimestamp = dateNow();\r\n this._firstActiveTimestamp = 0;\r\n this._totalIdleTime = 0;\r\n this._lastActiveTimestamp = 0;\r\n this._idleStartTimestamp = 0;\r\n this._idleCount = 0;\r\n this._intervalId = setInterval(function () {\r\n if (_this._lastActiveTimestamp > 0 && _this._idleStartTimestamp === 0 && dateNow() - _this._lastActiveTimestamp >= _this._idleTimeout) {\r\n _this._idleStartTimestamp = dateNow();\r\n _this._idleCount++;\r\n }\r\n }, 100);\r\n };\r\n AITrackedComponentBase.prototype.componentWillUnmount = function () {\r\n if (this._mountTimestamp === 0) {\r\n throw new Error('withAITracking:componentWillUnmount: mountTimestamp is not initialized.');\r\n }\r\n if (this._intervalId) {\r\n clearInterval(this._intervalId);\r\n }\r\n if (this._firstActiveTimestamp === 0) {\r\n return;\r\n }\r\n var engagementTime = this.getEngagementTimeSeconds();\r\n var metricData = {\r\n average: engagementTime,\r\n name: 'React Component Engaged Time (seconds)',\r\n sampleCount: 1\r\n };\r\n var additionalProperties = { 'Component Name': this._componentName };\r\n this._reactPlugin.trackMetric(metricData, additionalProperties);\r\n };\r\n AITrackedComponentBase.prototype.getEngagementTimeSeconds = function () {\r\n return (dateNow() - this._firstActiveTimestamp - this._totalIdleTime - this._idleCount * this._idleTimeout) / 1000;\r\n };\r\n return AITrackedComponentBase;\r\n}(React.Component));\r\nexport { AITrackedComponentBase };\r\n/**\r\n * Higher-order component function to hook Application Insights tracking\r\n * in a React component's lifecycle.\r\n *\r\n * @param reactPlugin ReactPlugin instance\r\n * @param Component the React component to be instrumented\r\n * @param componentName (optional) component name\r\n * @param className (optional) className of the HOC div\r\n */\r\nexport default function withAITracking(reactPlugin, Component, componentName, className) {\r\n if (componentName === undefined || componentName === null || typeof componentName !== 'string') {\r\n componentName = Component.prototype &&\r\n Component.prototype.constructor &&\r\n Component.prototype.constructor.name ||\r\n 'Unknown';\r\n }\r\n if (className === undefined || className === null || typeof className !== 'string') {\r\n className = '';\r\n }\r\n return /** @class */ (function (_super) {\r\n __extends(class_1, _super);\r\n function class_1(props) {\r\n return _super.call(this, props, reactPlugin, componentName) || this;\r\n }\r\n class_1.prototype.render = function () {\r\n return (React.createElement(\"div\", { onKeyDown: this.trackActivity, onMouseMove: this.trackActivity, onScroll: this.trackActivity, onMouseDown: this.trackActivity, onTouchStart: this.trackActivity, onTouchMove: this.trackActivity, className: className },\r\n React.createElement(Component, __assign({}, this.props))));\r\n };\r\n return class_1;\r\n }(AITrackedComponentBase));\r\n}\r\n//# sourceMappingURL=withAITracking.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC,wGAA4C;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/applicationinsights-react-js",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3-nightly.2205-03",
|
|
4
4
|
"description": "Microsoft Application Insights React plugin",
|
|
5
5
|
"main": "dist/applicationinsights-react-js.js",
|
|
6
6
|
"module": "dist-esm/applicationinsights-react-js.js",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@microsoft/applicationinsights-shims": "2.0.1",
|
|
61
|
-
"@microsoft/applicationinsights-core-js": "2.8.
|
|
62
|
-
"@microsoft/applicationinsights-common": "2.8.
|
|
63
|
-
"@microsoft/dynamicproto-js": "^1.1.
|
|
61
|
+
"@microsoft/applicationinsights-core-js": "2.8.3-nightly.2205-03",
|
|
62
|
+
"@microsoft/applicationinsights-common": "2.8.3-nightly.2205-03",
|
|
63
|
+
"@microsoft/dynamicproto-js": "^1.1.6"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"tslib": "*",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { IReactExtensionConfig } from "./Interfaces/IReactExtensionConfig";
|
|
5
5
|
import ReactPlugin from "./ReactPlugin";
|
|
6
|
-
import withAITracking from "./withAITracking";
|
|
6
|
+
import withAITracking, { AITrackedComponentBase } from "./withAITracking";
|
|
7
7
|
import AppInsightsErrorBoundary from "./AppInsightsErrorBoundary"
|
|
8
8
|
import {
|
|
9
9
|
AppInsightsContext,
|
|
@@ -20,5 +20,6 @@ export {
|
|
|
20
20
|
AppInsightsContext,
|
|
21
21
|
useAppInsightsContext,
|
|
22
22
|
useTrackEvent,
|
|
23
|
-
useTrackMetric
|
|
23
|
+
useTrackMetric,
|
|
24
|
+
AITrackedComponentBase
|
|
24
25
|
};
|
package/src/withAITracking.tsx
CHANGED
|
@@ -2,10 +2,92 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import { IMetricTelemetry } from '@microsoft/applicationinsights-common';
|
|
5
|
-
import {
|
|
5
|
+
import { dateNow } from '@microsoft/applicationinsights-core-js';
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import ReactPlugin from './ReactPlugin';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Higher-order component base class to hook Application Insights tracking
|
|
11
|
+
* in a React component's lifecycle.
|
|
12
|
+
*/
|
|
13
|
+
export abstract class AITrackedComponentBase<P> extends React.Component<P> {
|
|
14
|
+
protected _mountTimestamp: number = 0;
|
|
15
|
+
protected _firstActiveTimestamp: number = 0;
|
|
16
|
+
protected _idleStartTimestamp: number = 0;
|
|
17
|
+
protected _lastActiveTimestamp: number = 0;
|
|
18
|
+
protected _totalIdleTime: number = 0;
|
|
19
|
+
protected _idleCount: number = 0;
|
|
20
|
+
protected _idleTimeout: number = 5000;
|
|
21
|
+
protected _intervalId?: any;
|
|
22
|
+
protected _componentName: string;
|
|
23
|
+
protected _reactPlugin: ReactPlugin;
|
|
24
|
+
|
|
25
|
+
public constructor(props: P, reactPlugin: ReactPlugin, componentName: string) {
|
|
26
|
+
super(props);
|
|
27
|
+
|
|
28
|
+
this._reactPlugin = reactPlugin;
|
|
29
|
+
this._componentName = componentName;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public componentDidMount() {
|
|
33
|
+
this._mountTimestamp = dateNow();
|
|
34
|
+
this._firstActiveTimestamp = 0;
|
|
35
|
+
this._totalIdleTime = 0;
|
|
36
|
+
this._lastActiveTimestamp = 0;
|
|
37
|
+
this._idleStartTimestamp = 0;
|
|
38
|
+
this._idleCount = 0;
|
|
39
|
+
|
|
40
|
+
this._intervalId = setInterval(() => {
|
|
41
|
+
if (this._lastActiveTimestamp > 0 && this._idleStartTimestamp === 0 && dateNow() - this._lastActiveTimestamp >= this._idleTimeout) {
|
|
42
|
+
this._idleStartTimestamp = dateNow();
|
|
43
|
+
this._idleCount++;
|
|
44
|
+
}
|
|
45
|
+
}, 100);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public componentWillUnmount() {
|
|
49
|
+
if (this._mountTimestamp === 0) {
|
|
50
|
+
throw new Error('withAITracking:componentWillUnmount: mountTimestamp is not initialized.');
|
|
51
|
+
}
|
|
52
|
+
if (this._intervalId) {
|
|
53
|
+
clearInterval(this._intervalId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (this._firstActiveTimestamp === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const engagementTime = this.getEngagementTimeSeconds();
|
|
61
|
+
const metricData: IMetricTelemetry = {
|
|
62
|
+
average: engagementTime,
|
|
63
|
+
name: 'React Component Engaged Time (seconds)',
|
|
64
|
+
sampleCount: 1
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const additionalProperties: { [key: string]: any } = { 'Component Name': this._componentName };
|
|
68
|
+
this._reactPlugin.trackMetric(metricData, additionalProperties);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected trackActivity = (e: React.SyntheticEvent<any>): void => {
|
|
72
|
+
if (this._firstActiveTimestamp === 0) {
|
|
73
|
+
this._firstActiveTimestamp = dateNow();
|
|
74
|
+
this._lastActiveTimestamp = this._firstActiveTimestamp;
|
|
75
|
+
} else {
|
|
76
|
+
this._lastActiveTimestamp = dateNow();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (this._idleStartTimestamp > 0) {
|
|
80
|
+
const lastIdleTime = this._lastActiveTimestamp - this._idleStartTimestamp;
|
|
81
|
+
this._totalIdleTime += lastIdleTime;
|
|
82
|
+
this._idleStartTimestamp = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private getEngagementTimeSeconds(): number {
|
|
87
|
+
return (dateNow() - this._firstActiveTimestamp - this._totalIdleTime - this._idleCount * this._idleTimeout) / 1000;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
9
91
|
/**
|
|
10
92
|
* Higher-order component function to hook Application Insights tracking
|
|
11
93
|
* in a React component's lifecycle.
|
|
@@ -18,63 +100,20 @@ import ReactPlugin from './ReactPlugin';
|
|
|
18
100
|
export default function withAITracking<P>(reactPlugin: ReactPlugin, Component: React.ComponentType<P>, componentName?: string, className?: string): React.ComponentClass<P> {
|
|
19
101
|
|
|
20
102
|
if (componentName === undefined || componentName === null || typeof componentName !== 'string') {
|
|
21
|
-
componentName = Component.prototype &&
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
103
|
+
componentName = Component.prototype &&
|
|
104
|
+
Component.prototype.constructor &&
|
|
105
|
+
Component.prototype.constructor.name ||
|
|
106
|
+
'Unknown';
|
|
25
107
|
}
|
|
26
108
|
|
|
27
109
|
if (className === undefined || className === null || typeof className !== 'string') {
|
|
28
110
|
className = '';
|
|
29
111
|
}
|
|
30
112
|
|
|
31
|
-
return class extends
|
|
32
|
-
private _mountTimestamp: number = 0;
|
|
33
|
-
private _firstActiveTimestamp: number = 0;
|
|
34
|
-
private _idleStartTimestamp: number = 0;
|
|
35
|
-
private _lastActiveTimestamp: number = 0;
|
|
36
|
-
private _totalIdleTime: number = 0;
|
|
37
|
-
private _idleCount: number = 0;
|
|
38
|
-
private _idleTimeout: number = 5000;
|
|
39
|
-
private _intervalId?: any;
|
|
40
|
-
|
|
41
|
-
public componentDidMount() {
|
|
42
|
-
this._mountTimestamp = CoreUtils.dateNow();
|
|
43
|
-
this._firstActiveTimestamp = 0;
|
|
44
|
-
this._totalIdleTime = 0;
|
|
45
|
-
this._lastActiveTimestamp = 0;
|
|
46
|
-
this._idleStartTimestamp = 0;
|
|
47
|
-
this._idleCount = 0;
|
|
48
|
-
|
|
49
|
-
this._intervalId = setInterval(() => {
|
|
50
|
-
if (this._lastActiveTimestamp > 0 && this._idleStartTimestamp === 0 && CoreUtils.dateNow() - this._lastActiveTimestamp >= this._idleTimeout) {
|
|
51
|
-
this._idleStartTimestamp = CoreUtils.dateNow();
|
|
52
|
-
this._idleCount++;
|
|
53
|
-
}
|
|
54
|
-
}, 100);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public componentWillUnmount() {
|
|
58
|
-
if (this._mountTimestamp === 0) {
|
|
59
|
-
throw new Error('withAITracking:componentWillUnmount: mountTimestamp is not initialized.');
|
|
60
|
-
}
|
|
61
|
-
if (this._intervalId) {
|
|
62
|
-
clearInterval(this._intervalId);
|
|
63
|
-
}
|
|
113
|
+
return class extends AITrackedComponentBase<P> {
|
|
64
114
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const engagementTime = this.getEngagementTimeSeconds();
|
|
70
|
-
const metricData: IMetricTelemetry = {
|
|
71
|
-
average: engagementTime,
|
|
72
|
-
name: 'React Component Engaged Time (seconds)',
|
|
73
|
-
sampleCount: 1
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const additionalProperties: { [key: string]: any } = { 'Component Name': componentName };
|
|
77
|
-
reactPlugin.trackMetric(metricData, additionalProperties);
|
|
115
|
+
public constructor(props: P) {
|
|
116
|
+
super(props, reactPlugin, componentName);
|
|
78
117
|
}
|
|
79
118
|
|
|
80
119
|
public render() {
|
|
@@ -92,24 +131,5 @@ export default function withAITracking<P>(reactPlugin: ReactPlugin, Component: R
|
|
|
92
131
|
</div>
|
|
93
132
|
);
|
|
94
133
|
}
|
|
95
|
-
|
|
96
|
-
private trackActivity = (e: React.SyntheticEvent<any>): void => {
|
|
97
|
-
if (this._firstActiveTimestamp === 0) {
|
|
98
|
-
this._firstActiveTimestamp = CoreUtils.dateNow();
|
|
99
|
-
this._lastActiveTimestamp = this._firstActiveTimestamp;
|
|
100
|
-
} else {
|
|
101
|
-
this._lastActiveTimestamp = CoreUtils.dateNow();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (this._idleStartTimestamp > 0) {
|
|
105
|
-
const lastIdleTime = this._lastActiveTimestamp - this._idleStartTimestamp;
|
|
106
|
-
this._totalIdleTime += lastIdleTime;
|
|
107
|
-
this._idleStartTimestamp = 0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private getEngagementTimeSeconds(): number {
|
|
112
|
-
return (CoreUtils.dateNow() - this._firstActiveTimestamp - this._totalIdleTime - this._idleCount * this._idleTimeout) / 1000;
|
|
113
|
-
}
|
|
114
134
|
}
|
|
115
135
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IReactExtensionConfig } from "./Interfaces/IReactExtensionConfig";
|
|
2
2
|
import ReactPlugin from "./ReactPlugin";
|
|
3
|
-
import withAITracking from "./withAITracking";
|
|
3
|
+
import withAITracking, { AITrackedComponentBase } from "./withAITracking";
|
|
4
4
|
import AppInsightsErrorBoundary from "./AppInsightsErrorBoundary";
|
|
5
5
|
import { AppInsightsContext, useAppInsightsContext } from "./AppInsightsContext";
|
|
6
6
|
import useTrackEvent from "./useTrackEvent";
|
|
7
7
|
import useTrackMetric from "./useTrackMetric";
|
|
8
|
-
export { ReactPlugin, IReactExtensionConfig, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric };
|
|
8
|
+
export { ReactPlugin, IReactExtensionConfig, withAITracking, AppInsightsErrorBoundary, AppInsightsContext, useAppInsightsContext, useTrackEvent, useTrackMetric, AITrackedComponentBase };
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import ReactPlugin from './ReactPlugin';
|
|
3
|
+
/**
|
|
4
|
+
* Higher-order component base class to hook Application Insights tracking
|
|
5
|
+
* in a React component's lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AITrackedComponentBase<P> extends React.Component<P> {
|
|
8
|
+
protected _mountTimestamp: number;
|
|
9
|
+
protected _firstActiveTimestamp: number;
|
|
10
|
+
protected _idleStartTimestamp: number;
|
|
11
|
+
protected _lastActiveTimestamp: number;
|
|
12
|
+
protected _totalIdleTime: number;
|
|
13
|
+
protected _idleCount: number;
|
|
14
|
+
protected _idleTimeout: number;
|
|
15
|
+
protected _intervalId?: any;
|
|
16
|
+
protected _componentName: string;
|
|
17
|
+
protected _reactPlugin: ReactPlugin;
|
|
18
|
+
constructor(props: P, reactPlugin: ReactPlugin, componentName: string);
|
|
19
|
+
componentDidMount(): void;
|
|
20
|
+
componentWillUnmount(): void;
|
|
21
|
+
protected trackActivity: (e: React.SyntheticEvent<any>) => void;
|
|
22
|
+
private getEngagementTimeSeconds;
|
|
23
|
+
}
|
|
3
24
|
/**
|
|
4
25
|
* Higher-order component function to hook Application Insights tracking
|
|
5
26
|
* in a React component's lifecycle.
|