@atlaskit/editor-plugin-metrics
Version:
Metrics plugin for @atlaskit/editor-core
62 lines • 3.06 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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; }
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; }
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
import { getNodeChanges } from './get-node-changes';
export var getAnalyticsPayload = function getAnalyticsPayload(_ref) {
var _pluginState$actionTy;
var currentContent = _ref.currentContent,
pluginState = _ref.pluginState,
toolbarDocking = _ref.toolbarDocking;
var nodeChanges = getNodeChanges({
currentContent: currentContent,
pluginState: pluginState
});
var getActionCountByTypeSum = function getActionCountByTypeSum() {
var actionCountByTypeSum = 0;
Object.entries(pluginState.actionTypeCount).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
_actionType = _ref3[0],
count = _ref3[1];
actionCountByTypeSum += count;
});
return pluginState.totalActionCount - actionCountByTypeSum;
};
var nodeInsertionCount = 0;
var nodeDeletionCount = 0;
Object.entries(nodeChanges).forEach(function (_ref4) {
var _ref5 = _slicedToArray(_ref4, 2),
_ = _ref5[0],
change = _ref5[1];
if (change > 0) {
nodeInsertionCount += change;
} else if (change < 0) {
nodeDeletionCount += Math.abs(change);
}
});
return {
action: ACTION.ENDED,
actionSubject: ACTION_SUBJECT.ACTIVITY_SESSION,
actionSubjectId: ACTION_SUBJECT_ID.ACTIVITY,
attributes: {
efficiency: {
totalActiveTime: pluginState.activeSessionTime / 1000,
totalActionCount: pluginState.totalActionCount,
actionByTypeCount: _objectSpread(_objectSpread({}, (_pluginState$actionTy = pluginState.actionTypeCount) !== null && _pluginState$actionTy !== void 0 ? _pluginState$actionTy : {}), {}, {
nodeDeletionCount: nodeDeletionCount,
nodeInsertionCount: nodeInsertionCount,
other: getActionCountByTypeSum()
})
},
effectiveness: {
undoCount: pluginState.actionTypeCount.undoCount,
repeatedActionCount: pluginState.repeatedActionCount,
safeInsertCount: pluginState.safeInsertCount
},
contentSizeChanged: pluginState.contentSizeChanged,
toolbarDocking: toolbarDocking
},
eventType: EVENT_TYPE.TRACK
};
};