TabMetrics.sys.mjs (2363B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /** 6 * A common list of systems, surfaces, controls, etc. from which user 7 * interactions with tabs could originate. These "source" values 8 * should be sent as extra data with tab-related metrics events. 9 */ 10 const METRIC_SOURCE = Object.freeze({ 11 // Tab overflow menu/"list all tabs" menu 12 TAB_OVERFLOW_MENU: "tab_overflow", 13 // Tab group context menu (right-clicking on a tab group label) 14 TAB_GROUP_MENU: "tab_group", 15 CANCEL_TAB_GROUP_CREATION: "cancel_create", 16 // Tab context menu (right-clicking on a tab) 17 TAB_MENU: "tab_menu", 18 TAB_STRIP: "tab_strip", 19 DRAG_AND_DROP: "drag", 20 // "Search & Suggest," i.e. URL bar suggested actions while typing 21 SUGGEST: "suggest", 22 // History > Recently Closed Tabs menu, undo recently closed tab, etc. 23 RECENT_TABS: "recent", 24 UNKNOWN: "unknown", 25 }); 26 27 const METRIC_TABS_LAYOUT = Object.freeze({ 28 HORIZONTAL: "horizontal", 29 VERTICAL: "vertical", 30 }); 31 32 const METRIC_REOPEN_TYPE = Object.freeze({ 33 SAVED: "saved", 34 DELETED: "deleted", 35 }); 36 37 const METRIC_GROUP_TYPE = Object.freeze({ 38 EXPANDED: "expanded", 39 COLLAPSED: "collapsed", 40 SAVED: "saved", 41 }); 42 43 /** 44 * @typedef {object} TabMetricsContext 45 * @property {boolean} [isUserTriggered=false] 46 * Should be true if there was an explicit action/request from the user 47 * (as opposed to some action being taken internally or for technical 48 * bookkeeping reasons alone). This causes telemetry events to fire. 49 * @property {string} [telemetrySource="unknown"] 50 * The system, surface, or control the user used to take this action. 51 * @see TabMetrics.METRIC_SOURCE for possible values. 52 * Defaults to "unknown". 53 */ 54 55 /** 56 * Creates a `TabMetricsContext` object for a user event originating from 57 * the specified source. 58 * 59 * @param {string} telemetrySource 60 * @see TabMetrics.METRIC_SOURCE 61 * @returns {TabMetricsContext} 62 */ 63 function userTriggeredContext(telemetrySource) { 64 telemetrySource = telemetrySource || METRIC_SOURCE.UNKNOWN; 65 return { 66 isUserTriggered: true, 67 telemetrySource, 68 }; 69 } 70 71 export const TabMetrics = { 72 METRIC_SOURCE, 73 METRIC_TABS_LAYOUT, 74 METRIC_REOPEN_TYPE, 75 METRIC_GROUP_TYPE, 76 userTriggeredContext, 77 };