UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

39 lines (36 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fireInteractivityEvent = fireInteractivityEvent; var _enums = require("@atlaskit/editor-common/analytics/types/enums"); /** The reasons that mean the page may not be around long enough to deliver a queued event. */ var REASONS_THE_PAGE_MAY_NOT_OUTLIVE = ['hidden', 'pagehide', 'unmount']; /** * The `editor interactivity` operational event. * * `editorSessionId` arrives without being set here: `@atlaskit/analytics-listeners` merges * the editor analytics context into the attributes of every event on the editor channel. * `objectId` comes both from that context and from the snapshot, which carries the value * the session was collected against. */ /** * Sends a snapshot as the `editor interactivity` event. * * Does nothing without the analytics plugin: an editor without it has nowhere to send events, * and the collector keeps measuring either way. */ function fireInteractivityEvent(analytics, snapshot) { analytics === null || analytics === void 0 || analytics.fireAnalyticsEvent({ action: 'interactivity', actionSubject: _enums.ACTION_SUBJECT.EDITOR, eventType: _enums.EVENT_TYPE.OPERATIONAL, attributes: snapshot }, undefined, // Events are queued into an idle callback by default, which a page being unloaded never // runs and a backgrounded tab throttles. The snapshots taken because the page is going // away go immediately; the rest can wait their turn. { immediate: REASONS_THE_PAGE_MAY_NOT_OUTLIVE.includes(snapshot.reason) }); }