@atlaskit/editor-plugin-metrics 2.0.0 → 3.0.1
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/CHANGELOG.md +18 -0
- package/dist/cjs/metricsPlugin.js +1 -0
- package/dist/cjs/pm-plugins/main.js +10 -4
- package/dist/cjs/pm-plugins/utils/analytics.js +29 -2
- package/dist/cjs/pm-plugins/utils/get-node-changes.js +36 -0
- package/dist/es2019/metricsPlugin.js +1 -0
- package/dist/es2019/pm-plugins/main.js +12 -4
- package/dist/es2019/pm-plugins/utils/analytics.js +40 -18
- package/dist/es2019/pm-plugins/utils/get-node-changes.js +28 -0
- package/dist/esm/metricsPlugin.js +1 -0
- package/dist/esm/pm-plugins/main.js +10 -4
- package/dist/esm/pm-plugins/utils/analytics.js +28 -2
- package/dist/esm/pm-plugins/utils/get-node-changes.js +29 -0
- package/dist/types/pm-plugins/main.d.ts +2 -0
- package/dist/types/pm-plugins/utils/analytics.d.ts +3 -1
- package/dist/types/pm-plugins/utils/get-node-changes.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/utils/analytics.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/utils/get-node-changes.d.ts +6 -0
- package/package.json +6 -6
- /package/dist/cjs/pm-plugins/utils/{isNonTextUndo.js → is-non-text-undo.js} +0 -0
- /package/dist/es2019/pm-plugins/utils/{isNonTextUndo.js → is-non-text-undo.js} +0 -0
- /package/dist/esm/pm-plugins/utils/{isNonTextUndo.js → is-non-text-undo.js} +0 -0
- /package/dist/types/pm-plugins/utils/{isNonTextUndo.d.ts → is-non-text-undo.d.ts} +0 -0
- /package/dist/types-ts4.5/pm-plugins/utils/{isNonTextUndo.d.ts → is-non-text-undo.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-metrics
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 3.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [#109060](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109060)
|
|
14
|
+
[`4660ec858a305`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4660ec858a305) -
|
|
15
|
+
Update `React` from v16 to v18
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 2.0.0
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
|
@@ -33,6 +33,7 @@ var metricsPlugin = exports.metricsPlugin = function metricsPlugin(_ref) {
|
|
|
33
33
|
var pluginState = api === null || api === void 0 ? void 0 : api.metrics.sharedState.currentState();
|
|
34
34
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
35
35
|
var payloadToSend = (0, _analytics.getAnalyticsPayload)({
|
|
36
|
+
currentContent: tr.doc.content,
|
|
36
37
|
pluginState: pluginState
|
|
37
38
|
});
|
|
38
39
|
api === null || api === void 0 || api.analytics.actions.attachAnalyticsEvent(payloadToSend)(newTr);
|
|
@@ -13,7 +13,7 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
13
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
14
|
var _activeSessionTimer = require("./utils/active-session-timer");
|
|
15
15
|
var _analytics = require("./utils/analytics");
|
|
16
|
-
var _isNonTextUndo = require("./utils/
|
|
16
|
+
var _isNonTextUndo = require("./utils/is-non-text-undo");
|
|
17
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
19
|
var metricsKey = exports.metricsKey = new _state.PluginKey('metricsPlugin');
|
|
@@ -24,6 +24,7 @@ var initialPluginState = exports.initialPluginState = {
|
|
|
24
24
|
totalActionCount: 0,
|
|
25
25
|
contentSizeChanged: 0,
|
|
26
26
|
timeOfLastTextInput: undefined,
|
|
27
|
+
initialContent: undefined,
|
|
27
28
|
actionTypeCount: {
|
|
28
29
|
textInputCount: 0,
|
|
29
30
|
nodeInsertionCount: 0,
|
|
@@ -38,15 +39,19 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
38
39
|
return new _safePlugin.SafePlugin({
|
|
39
40
|
key: metricsKey,
|
|
40
41
|
state: {
|
|
41
|
-
init: function init() {
|
|
42
|
-
return initialPluginState
|
|
42
|
+
init: function init(_, state) {
|
|
43
|
+
return _objectSpread(_objectSpread({}, initialPluginState), {}, {
|
|
44
|
+
initialContent: state.doc.content
|
|
45
|
+
});
|
|
43
46
|
},
|
|
44
47
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
45
48
|
apply: function apply(tr, pluginState, oldState, newState) {
|
|
46
49
|
var meta = tr.getMeta(metricsKey);
|
|
47
50
|
var intentToStartEditTime = (meta === null || meta === void 0 ? void 0 : meta.intentToStartEditTime) || pluginState.intentToStartEditTime;
|
|
48
51
|
if (meta && meta.stopActiveSession) {
|
|
49
|
-
return initialPluginState
|
|
52
|
+
return _objectSpread(_objectSpread({}, initialPluginState), {}, {
|
|
53
|
+
initialContent: newState.doc.content
|
|
54
|
+
});
|
|
50
55
|
}
|
|
51
56
|
if (!intentToStartEditTime) {
|
|
52
57
|
if (tr.docChanged && !tr.getMeta('replaceDocument')) {
|
|
@@ -108,6 +113,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
115
|
var payloadToSend = (0, _analytics.getAnalyticsPayload)({
|
|
116
|
+
currentContent: _view.state.doc.content,
|
|
111
117
|
pluginState: pluginState
|
|
112
118
|
});
|
|
113
119
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.getPayloadAttributes = exports.getAnalyticsPayload = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
7
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _getNodeChanges = require("./get-node-changes");
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
14
|
var getPayloadAttributes = exports.getPayloadAttributes = function getPayloadAttributes(_ref) {
|
|
9
15
|
var pluginState = _ref.pluginState,
|
|
10
16
|
contentSizeChanged = _ref.contentSizeChanged;
|
|
@@ -23,7 +29,25 @@ var getPayloadAttributes = exports.getPayloadAttributes = function getPayloadAtt
|
|
|
23
29
|
};
|
|
24
30
|
};
|
|
25
31
|
var getAnalyticsPayload = exports.getAnalyticsPayload = function getAnalyticsPayload(_ref2) {
|
|
26
|
-
var
|
|
32
|
+
var _pluginState$actionTy;
|
|
33
|
+
var currentContent = _ref2.currentContent,
|
|
34
|
+
pluginState = _ref2.pluginState;
|
|
35
|
+
var nodeChanges = (0, _getNodeChanges.getNodeChanges)({
|
|
36
|
+
currentContent: currentContent,
|
|
37
|
+
pluginState: pluginState
|
|
38
|
+
});
|
|
39
|
+
var nodeInsertionCount = 0;
|
|
40
|
+
var nodeDeletionCount = 0;
|
|
41
|
+
Object.entries(nodeChanges).forEach(function (_ref3) {
|
|
42
|
+
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
43
|
+
_ = _ref4[0],
|
|
44
|
+
change = _ref4[1];
|
|
45
|
+
if (change > 0) {
|
|
46
|
+
nodeInsertionCount += change;
|
|
47
|
+
} else if (change < 0) {
|
|
48
|
+
nodeDeletionCount += Math.abs(change);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
27
51
|
return {
|
|
28
52
|
action: _analytics.ACTION.ENDED,
|
|
29
53
|
actionSubject: _analytics.ACTION_SUBJECT.ACTIVITY_SESSION,
|
|
@@ -32,7 +56,10 @@ var getAnalyticsPayload = exports.getAnalyticsPayload = function getAnalyticsPay
|
|
|
32
56
|
efficiency: {
|
|
33
57
|
totalActiveTime: pluginState.activeSessionTime,
|
|
34
58
|
totalActionCount: pluginState.totalActionCount,
|
|
35
|
-
actionByTypeCount: pluginState.actionTypeCount
|
|
59
|
+
actionByTypeCount: _objectSpread(_objectSpread({}, (_pluginState$actionTy = pluginState.actionTypeCount) !== null && _pluginState$actionTy !== void 0 ? _pluginState$actionTy : {}), {}, {
|
|
60
|
+
nodeDeletionCount: nodeDeletionCount,
|
|
61
|
+
nodeInsertionCount: nodeInsertionCount
|
|
62
|
+
})
|
|
36
63
|
},
|
|
37
64
|
effectiveness: {
|
|
38
65
|
undoCount: pluginState.actionTypeCount.undoCount,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getNodeChanges = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function countNodesByType(fragment) {
|
|
12
|
+
var counts = {};
|
|
13
|
+
fragment.forEach(function (node) {
|
|
14
|
+
counts[node.type.name] = (counts[node.type.name] || 0) + 1;
|
|
15
|
+
});
|
|
16
|
+
return counts;
|
|
17
|
+
}
|
|
18
|
+
var getNodeChanges = exports.getNodeChanges = function getNodeChanges(_ref) {
|
|
19
|
+
var currentContent = _ref.currentContent,
|
|
20
|
+
pluginState = _ref.pluginState;
|
|
21
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.initialContent) {
|
|
22
|
+
var initialCounts = countNodesByType(pluginState.initialContent);
|
|
23
|
+
var currentCounts = countNodesByType(currentContent);
|
|
24
|
+
var netChanges = Object.keys(_objectSpread(_objectSpread({}, initialCounts), currentCounts)).filter(function (value) {
|
|
25
|
+
return !['paragraph', 'heading'].includes(value);
|
|
26
|
+
}).reduce(function (changes, nodeType) {
|
|
27
|
+
var change = (currentCounts[nodeType] || 0) - (initialCounts[nodeType] || 0);
|
|
28
|
+
if (change !== 0) {
|
|
29
|
+
changes[nodeType] = change;
|
|
30
|
+
}
|
|
31
|
+
return changes;
|
|
32
|
+
}, {});
|
|
33
|
+
return netChanges;
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
};
|
|
@@ -25,6 +25,7 @@ export const metricsPlugin = ({
|
|
|
25
25
|
const pluginState = api === null || api === void 0 ? void 0 : api.metrics.sharedState.currentState();
|
|
26
26
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
27
27
|
const payloadToSend = getAnalyticsPayload({
|
|
28
|
+
currentContent: tr.doc.content,
|
|
28
29
|
pluginState
|
|
29
30
|
});
|
|
30
31
|
api === null || api === void 0 ? void 0 : api.analytics.actions.attachAnalyticsEvent(payloadToSend)(newTr);
|
|
@@ -5,7 +5,7 @@ import { isTextInput } from '@atlaskit/editor-common/utils';
|
|
|
5
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { ActiveSessionTimer } from './utils/active-session-timer';
|
|
7
7
|
import { getAnalyticsPayload } from './utils/analytics';
|
|
8
|
-
import { isNonTextUndo } from './utils/
|
|
8
|
+
import { isNonTextUndo } from './utils/is-non-text-undo';
|
|
9
9
|
export const metricsKey = new PluginKey('metricsPlugin');
|
|
10
10
|
export const initialPluginState = {
|
|
11
11
|
intentToStartEditTime: undefined,
|
|
@@ -14,6 +14,7 @@ export const initialPluginState = {
|
|
|
14
14
|
totalActionCount: 0,
|
|
15
15
|
contentSizeChanged: 0,
|
|
16
16
|
timeOfLastTextInput: undefined,
|
|
17
|
+
initialContent: undefined,
|
|
17
18
|
actionTypeCount: {
|
|
18
19
|
textInputCount: 0,
|
|
19
20
|
nodeInsertionCount: 0,
|
|
@@ -28,15 +29,21 @@ export const createPlugin = api => {
|
|
|
28
29
|
return new SafePlugin({
|
|
29
30
|
key: metricsKey,
|
|
30
31
|
state: {
|
|
31
|
-
init: () => {
|
|
32
|
-
return
|
|
32
|
+
init: (_, state) => {
|
|
33
|
+
return {
|
|
34
|
+
...initialPluginState,
|
|
35
|
+
initialContent: state.doc.content
|
|
36
|
+
};
|
|
33
37
|
},
|
|
34
38
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
35
39
|
apply(tr, pluginState, oldState, newState) {
|
|
36
40
|
const meta = tr.getMeta(metricsKey);
|
|
37
41
|
let intentToStartEditTime = (meta === null || meta === void 0 ? void 0 : meta.intentToStartEditTime) || pluginState.intentToStartEditTime;
|
|
38
42
|
if (meta && meta.stopActiveSession) {
|
|
39
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
...initialPluginState,
|
|
45
|
+
initialContent: newState.doc.content
|
|
46
|
+
};
|
|
40
47
|
}
|
|
41
48
|
if (!intentToStartEditTime) {
|
|
42
49
|
if (tr.docChanged && !tr.getMeta('replaceDocument')) {
|
|
@@ -101,6 +108,7 @@ export const createPlugin = api => {
|
|
|
101
108
|
return;
|
|
102
109
|
}
|
|
103
110
|
const payloadToSend = getAnalyticsPayload({
|
|
111
|
+
currentContent: view.state.doc.content,
|
|
104
112
|
pluginState
|
|
105
113
|
});
|
|
106
114
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { getNodeChanges } from './get-node-changes';
|
|
2
3
|
export const getPayloadAttributes = ({
|
|
3
4
|
pluginState,
|
|
4
5
|
contentSizeChanged
|
|
@@ -16,23 +17,44 @@ export const getPayloadAttributes = ({
|
|
|
16
17
|
contentSizeChanged
|
|
17
18
|
});
|
|
18
19
|
export const getAnalyticsPayload = ({
|
|
20
|
+
currentContent,
|
|
19
21
|
pluginState
|
|
20
|
-
}) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
}) => {
|
|
23
|
+
var _pluginState$actionTy;
|
|
24
|
+
const nodeChanges = getNodeChanges({
|
|
25
|
+
currentContent,
|
|
26
|
+
pluginState
|
|
27
|
+
});
|
|
28
|
+
let nodeInsertionCount = 0;
|
|
29
|
+
let nodeDeletionCount = 0;
|
|
30
|
+
Object.entries(nodeChanges).forEach(([_, change]) => {
|
|
31
|
+
if (change > 0) {
|
|
32
|
+
nodeInsertionCount += change;
|
|
33
|
+
} else if (change < 0) {
|
|
34
|
+
nodeDeletionCount += Math.abs(change);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
action: ACTION.ENDED,
|
|
39
|
+
actionSubject: ACTION_SUBJECT.ACTIVITY_SESSION,
|
|
40
|
+
actionSubjectId: ACTION_SUBJECT_ID.ACTIVITY,
|
|
41
|
+
attributes: {
|
|
42
|
+
efficiency: {
|
|
43
|
+
totalActiveTime: pluginState.activeSessionTime,
|
|
44
|
+
totalActionCount: pluginState.totalActionCount,
|
|
45
|
+
actionByTypeCount: {
|
|
46
|
+
...((_pluginState$actionTy = pluginState.actionTypeCount) !== null && _pluginState$actionTy !== void 0 ? _pluginState$actionTy : {}),
|
|
47
|
+
nodeDeletionCount,
|
|
48
|
+
nodeInsertionCount
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
effectiveness: {
|
|
52
|
+
undoCount: pluginState.actionTypeCount.undoCount,
|
|
53
|
+
repeatedActionCount: 0,
|
|
54
|
+
safeInsertCount: 0
|
|
55
|
+
},
|
|
56
|
+
contentSizeChanged: pluginState.contentSizeChanged
|
|
34
57
|
},
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
});
|
|
58
|
+
eventType: EVENT_TYPE.TRACK
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function countNodesByType(fragment) {
|
|
2
|
+
const counts = {};
|
|
3
|
+
fragment.forEach(node => {
|
|
4
|
+
counts[node.type.name] = (counts[node.type.name] || 0) + 1;
|
|
5
|
+
});
|
|
6
|
+
return counts;
|
|
7
|
+
}
|
|
8
|
+
export const getNodeChanges = ({
|
|
9
|
+
currentContent,
|
|
10
|
+
pluginState
|
|
11
|
+
}) => {
|
|
12
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.initialContent) {
|
|
13
|
+
const initialCounts = countNodesByType(pluginState.initialContent);
|
|
14
|
+
const currentCounts = countNodesByType(currentContent);
|
|
15
|
+
const netChanges = Object.keys({
|
|
16
|
+
...initialCounts,
|
|
17
|
+
...currentCounts
|
|
18
|
+
}).filter(value => !['paragraph', 'heading'].includes(value)).reduce((changes, nodeType) => {
|
|
19
|
+
const change = (currentCounts[nodeType] || 0) - (initialCounts[nodeType] || 0);
|
|
20
|
+
if (change !== 0) {
|
|
21
|
+
changes[nodeType] = change;
|
|
22
|
+
}
|
|
23
|
+
return changes;
|
|
24
|
+
}, {});
|
|
25
|
+
return netChanges;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
@@ -27,6 +27,7 @@ export var metricsPlugin = function metricsPlugin(_ref) {
|
|
|
27
27
|
var pluginState = api === null || api === void 0 ? void 0 : api.metrics.sharedState.currentState();
|
|
28
28
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
29
29
|
var payloadToSend = getAnalyticsPayload({
|
|
30
|
+
currentContent: tr.doc.content,
|
|
30
31
|
pluginState: pluginState
|
|
31
32
|
});
|
|
32
33
|
api === null || api === void 0 || api.analytics.actions.attachAnalyticsEvent(payloadToSend)(newTr);
|
|
@@ -8,7 +8,7 @@ import { isTextInput } from '@atlaskit/editor-common/utils';
|
|
|
8
8
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { ActiveSessionTimer } from './utils/active-session-timer';
|
|
10
10
|
import { getAnalyticsPayload } from './utils/analytics';
|
|
11
|
-
import { isNonTextUndo } from './utils/
|
|
11
|
+
import { isNonTextUndo } from './utils/is-non-text-undo';
|
|
12
12
|
export var metricsKey = new PluginKey('metricsPlugin');
|
|
13
13
|
export var initialPluginState = {
|
|
14
14
|
intentToStartEditTime: undefined,
|
|
@@ -17,6 +17,7 @@ export var initialPluginState = {
|
|
|
17
17
|
totalActionCount: 0,
|
|
18
18
|
contentSizeChanged: 0,
|
|
19
19
|
timeOfLastTextInput: undefined,
|
|
20
|
+
initialContent: undefined,
|
|
20
21
|
actionTypeCount: {
|
|
21
22
|
textInputCount: 0,
|
|
22
23
|
nodeInsertionCount: 0,
|
|
@@ -31,15 +32,19 @@ export var createPlugin = function createPlugin(api) {
|
|
|
31
32
|
return new SafePlugin({
|
|
32
33
|
key: metricsKey,
|
|
33
34
|
state: {
|
|
34
|
-
init: function init() {
|
|
35
|
-
return initialPluginState
|
|
35
|
+
init: function init(_, state) {
|
|
36
|
+
return _objectSpread(_objectSpread({}, initialPluginState), {}, {
|
|
37
|
+
initialContent: state.doc.content
|
|
38
|
+
});
|
|
36
39
|
},
|
|
37
40
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
38
41
|
apply: function apply(tr, pluginState, oldState, newState) {
|
|
39
42
|
var meta = tr.getMeta(metricsKey);
|
|
40
43
|
var intentToStartEditTime = (meta === null || meta === void 0 ? void 0 : meta.intentToStartEditTime) || pluginState.intentToStartEditTime;
|
|
41
44
|
if (meta && meta.stopActiveSession) {
|
|
42
|
-
return initialPluginState
|
|
45
|
+
return _objectSpread(_objectSpread({}, initialPluginState), {}, {
|
|
46
|
+
initialContent: newState.doc.content
|
|
47
|
+
});
|
|
43
48
|
}
|
|
44
49
|
if (!intentToStartEditTime) {
|
|
45
50
|
if (tr.docChanged && !tr.getMeta('replaceDocument')) {
|
|
@@ -101,6 +106,7 @@ export var createPlugin = function createPlugin(api) {
|
|
|
101
106
|
return;
|
|
102
107
|
}
|
|
103
108
|
var payloadToSend = getAnalyticsPayload({
|
|
109
|
+
currentContent: _view.state.doc.content,
|
|
104
110
|
pluginState: pluginState
|
|
105
111
|
});
|
|
106
112
|
if (pluginState && pluginState.totalActionCount > 0 && pluginState.activeSessionTime > 0) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1
5
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { getNodeChanges } from './get-node-changes';
|
|
2
7
|
export var getPayloadAttributes = function getPayloadAttributes(_ref) {
|
|
3
8
|
var pluginState = _ref.pluginState,
|
|
4
9
|
contentSizeChanged = _ref.contentSizeChanged;
|
|
@@ -17,7 +22,25 @@ export var getPayloadAttributes = function getPayloadAttributes(_ref) {
|
|
|
17
22
|
};
|
|
18
23
|
};
|
|
19
24
|
export var getAnalyticsPayload = function getAnalyticsPayload(_ref2) {
|
|
20
|
-
var
|
|
25
|
+
var _pluginState$actionTy;
|
|
26
|
+
var currentContent = _ref2.currentContent,
|
|
27
|
+
pluginState = _ref2.pluginState;
|
|
28
|
+
var nodeChanges = getNodeChanges({
|
|
29
|
+
currentContent: currentContent,
|
|
30
|
+
pluginState: pluginState
|
|
31
|
+
});
|
|
32
|
+
var nodeInsertionCount = 0;
|
|
33
|
+
var nodeDeletionCount = 0;
|
|
34
|
+
Object.entries(nodeChanges).forEach(function (_ref3) {
|
|
35
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
36
|
+
_ = _ref4[0],
|
|
37
|
+
change = _ref4[1];
|
|
38
|
+
if (change > 0) {
|
|
39
|
+
nodeInsertionCount += change;
|
|
40
|
+
} else if (change < 0) {
|
|
41
|
+
nodeDeletionCount += Math.abs(change);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
21
44
|
return {
|
|
22
45
|
action: ACTION.ENDED,
|
|
23
46
|
actionSubject: ACTION_SUBJECT.ACTIVITY_SESSION,
|
|
@@ -26,7 +49,10 @@ export var getAnalyticsPayload = function getAnalyticsPayload(_ref2) {
|
|
|
26
49
|
efficiency: {
|
|
27
50
|
totalActiveTime: pluginState.activeSessionTime,
|
|
28
51
|
totalActionCount: pluginState.totalActionCount,
|
|
29
|
-
actionByTypeCount: pluginState.actionTypeCount
|
|
52
|
+
actionByTypeCount: _objectSpread(_objectSpread({}, (_pluginState$actionTy = pluginState.actionTypeCount) !== null && _pluginState$actionTy !== void 0 ? _pluginState$actionTy : {}), {}, {
|
|
53
|
+
nodeDeletionCount: nodeDeletionCount,
|
|
54
|
+
nodeInsertionCount: nodeInsertionCount
|
|
55
|
+
})
|
|
30
56
|
},
|
|
31
57
|
effectiveness: {
|
|
32
58
|
undoCount: pluginState.actionTypeCount.undoCount,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function countNodesByType(fragment) {
|
|
5
|
+
var counts = {};
|
|
6
|
+
fragment.forEach(function (node) {
|
|
7
|
+
counts[node.type.name] = (counts[node.type.name] || 0) + 1;
|
|
8
|
+
});
|
|
9
|
+
return counts;
|
|
10
|
+
}
|
|
11
|
+
export var getNodeChanges = function getNodeChanges(_ref) {
|
|
12
|
+
var currentContent = _ref.currentContent,
|
|
13
|
+
pluginState = _ref.pluginState;
|
|
14
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.initialContent) {
|
|
15
|
+
var initialCounts = countNodesByType(pluginState.initialContent);
|
|
16
|
+
var currentCounts = countNodesByType(currentContent);
|
|
17
|
+
var netChanges = Object.keys(_objectSpread(_objectSpread({}, initialCounts), currentCounts)).filter(function (value) {
|
|
18
|
+
return !['paragraph', 'heading'].includes(value);
|
|
19
|
+
}).reduce(function (changes, nodeType) {
|
|
20
|
+
var change = (currentCounts[nodeType] || 0) - (initialCounts[nodeType] || 0);
|
|
21
|
+
if (change !== 0) {
|
|
22
|
+
changes[nodeType] = change;
|
|
23
|
+
}
|
|
24
|
+
return changes;
|
|
25
|
+
}, {});
|
|
26
|
+
return netChanges;
|
|
27
|
+
}
|
|
28
|
+
return {};
|
|
29
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import { type MetricsPlugin } from '../metricsPluginType';
|
|
5
6
|
export declare const metricsKey: PluginKey<any>;
|
|
@@ -11,6 +12,7 @@ export type MetricsState = {
|
|
|
11
12
|
lastSelection?: Selection;
|
|
12
13
|
actionTypeCount: ActionByType;
|
|
13
14
|
timeOfLastTextInput?: number;
|
|
15
|
+
initialContent?: Fragment;
|
|
14
16
|
};
|
|
15
17
|
export type ActionByType = {
|
|
16
18
|
textInputCount: number;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type ActiveSessionEventPayload, type ActiveSessionEventAttributes } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { MetricsState } from '../main';
|
|
3
4
|
type Props = {
|
|
4
5
|
pluginState: MetricsState;
|
|
5
6
|
contentSizeChanged: number;
|
|
6
7
|
};
|
|
7
8
|
export declare const getPayloadAttributes: ({ pluginState, contentSizeChanged, }: Props) => ActiveSessionEventAttributes;
|
|
8
|
-
export declare const getAnalyticsPayload: ({ pluginState, }: {
|
|
9
|
+
export declare const getAnalyticsPayload: ({ currentContent, pluginState, }: {
|
|
10
|
+
currentContent: Fragment;
|
|
9
11
|
pluginState: MetricsState;
|
|
10
12
|
}) => ActiveSessionEventPayload;
|
|
11
13
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { MetricsState } from '../main';
|
|
3
|
+
export declare const getNodeChanges: ({ currentContent, pluginState, }: {
|
|
4
|
+
currentContent: Fragment;
|
|
5
|
+
pluginState?: MetricsState | undefined;
|
|
6
|
+
}) => Record<string, number>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import { type MetricsPlugin } from '../metricsPluginType';
|
|
5
6
|
export declare const metricsKey: PluginKey<any>;
|
|
@@ -11,6 +12,7 @@ export type MetricsState = {
|
|
|
11
12
|
lastSelection?: Selection;
|
|
12
13
|
actionTypeCount: ActionByType;
|
|
13
14
|
timeOfLastTextInput?: number;
|
|
15
|
+
initialContent?: Fragment;
|
|
14
16
|
};
|
|
15
17
|
export type ActionByType = {
|
|
16
18
|
textInputCount: number;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type ActiveSessionEventPayload, type ActiveSessionEventAttributes } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { MetricsState } from '../main';
|
|
3
4
|
type Props = {
|
|
4
5
|
pluginState: MetricsState;
|
|
5
6
|
contentSizeChanged: number;
|
|
6
7
|
};
|
|
7
8
|
export declare const getPayloadAttributes: ({ pluginState, contentSizeChanged, }: Props) => ActiveSessionEventAttributes;
|
|
8
|
-
export declare const getAnalyticsPayload: ({ pluginState, }: {
|
|
9
|
+
export declare const getAnalyticsPayload: ({ currentContent, pluginState, }: {
|
|
10
|
+
currentContent: Fragment;
|
|
9
11
|
pluginState: MetricsState;
|
|
10
12
|
}) => ActiveSessionEventPayload;
|
|
11
13
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { MetricsState } from '../main';
|
|
3
|
+
export declare const getNodeChanges: ({ currentContent, pluginState, }: {
|
|
4
|
+
currentContent: Fragment;
|
|
5
|
+
pluginState?: MetricsState | undefined;
|
|
6
|
+
}) => Record<string, number>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-metrics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Metrics plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
28
|
-
"@atlaskit/editor-common": "^99.
|
|
28
|
+
"@atlaskit/editor-common": "^99.7.0",
|
|
29
29
|
"@atlaskit/editor-plugin-analytics": "^1.11.0",
|
|
30
30
|
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
31
|
-
"@atlaskit/platform-feature-flags": "^0.
|
|
31
|
+
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
32
32
|
"@babel/runtime": "^7.0.0",
|
|
33
33
|
"bind-event-listener": "^3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": "^
|
|
36
|
+
"react": "^18.2.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@testing-library/react": "^
|
|
40
|
-
"react-dom": "^
|
|
39
|
+
"@testing-library/react": "^13.4.0",
|
|
40
|
+
"react-dom": "^18.2.0",
|
|
41
41
|
"typescript": "~5.4.2"
|
|
42
42
|
},
|
|
43
43
|
"techstack": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|