UNPKG

@atlaskit/editor-plugin-collab-edit

Version:

Collab Edit plugin for @atlaskit/editor-core

66 lines (65 loc) 2.65 kB
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics'; import { getDocStructure } from '@atlaskit/editor-common/core-utils'; import { sniffUserBrowserExtensions } from '@atlaskit/editor-common/utils'; export const addSynchronyErrorAnalytics = (state, tr, featureFlags, editorAnalyticsApi) => { return error => { const browserExtensions = sniffUserBrowserExtensions({ extensions: ['grammarly'] }); const payload = { action: ACTION.SYNCHRONY_ERROR, actionSubject: ACTION_SUBJECT.EDITOR, eventType: EVENT_TYPE.OPERATIONAL, attributes: { error, browserExtensions } }; if (featureFlags.synchronyErrorDocStructure) { // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion payload.attributes.docStructure = getDocStructure(state.doc, { compact: true }); } editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(payload)(tr); return tr; }; }; /** * Builds the `agentEditShimmerNotShown` operational event fired when an agent-authored edit applied * instantly without the skeleton shimmer/telepointer. Success is the ABSENCE of this event; a * neutral action + `reason` keeps expected degrades out of error dashboards. Attributes are non-PII: * only the agent kind and a sanitised error name/message (never the raw Error or any doc content). */ export const getAgentEditShimmerNotShownPayload = (reason, agentType, error) => ({ action: ACTION.AGENT_EDIT_SHIMMER_NOT_SHOWN, actionSubject: ACTION_SUBJECT.COLLAB, eventType: EVENT_TYPE.OPERATIONAL, attributes: { reason, // Spread conditionally so absent context isn't emitted as `undefined` (the teardown path has no // single agent, and non-throw reasons have no error). ...(agentType ? { agentType } : {}), ...(error ? { error: `${error.name}: ${error.message}` } : {}) } }); export const addSynchronyEntityAnalytics = (state, tr) => { return (type, editorAnalyticsApi) => { editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({ action: type === 'error' ? ACTION.SYNCHRONY_ENTITY_ERROR : ACTION.SYNCHRONY_DISCONNECTED, actionSubject: ACTION_SUBJECT.EDITOR, eventType: EVENT_TYPE.OPERATIONAL, attributes: { // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine onLine: navigator.onLine, visibilityState: document.visibilityState } })(tr); return tr; }; };