您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AnalyticsEvents.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /**
  2. * The constant for the event type 'track'.
  3. * TODO: keep these constants in a single place. Can we import them from
  4. * lib-jitsi-meet's AnalyticsEvents somehow?
  5. * @type {string}
  6. */
  7. const TYPE_TRACK = 'track';
  8. /**
  9. * The constant for the event type 'UI' (User Interaction).
  10. * TODO: keep these constants in a single place. Can we import them from
  11. * lib-jitsi-meet's AnalyticsEvents somehow?
  12. * @type {string}
  13. */
  14. const TYPE_UI = 'ui';
  15. /**
  16. * The identifier for the "pinned" action. The local participant has pinned a
  17. * participant to remain on large video.
  18. *
  19. * @type {String}
  20. */
  21. export const ACTION_PINNED = 'pinned';
  22. /**
  23. * The identifier for the "unpinned" action. The local participant has unpinned
  24. * a participant so the participant doesn't remain permanently on local large
  25. * video.
  26. *
  27. * @type {String}
  28. */
  29. export const ACTION_UNPINNED = 'unpinned';
  30. /**
  31. * The identifier for the "pressed" action for shortcut events. This action
  32. * means that a button was pressed (and not yet released).
  33. *
  34. * @type {String}
  35. */
  36. export const ACTION_SHORTCUT_PRESSED = 'pressed';
  37. /**
  38. * The identifier for the "released" action for shortcut events. This action
  39. * means that a button which was previously pressed was released.
  40. *
  41. * @type {String}
  42. */
  43. export const ACTION_SHORTCUT_RELEASED = 'released';
  44. /**
  45. * The identifier for the "triggered" action for shortcut events. This action
  46. * means that a button was pressed, and we don't care about whether it was
  47. * released or will be released in the future.
  48. *
  49. * @type {String}
  50. */
  51. export const ACTION_SHORTCUT_TRIGGERED = 'triggered';
  52. /**
  53. * The name of the keyboard shortcut or toolbar button for muting audio.
  54. */
  55. export const AUDIO_MUTE = 'audio.mute';
  56. /**
  57. * The name of the keyboard shortcut or toolbar button for muting video.
  58. */
  59. export const VIDEO_MUTE = 'video.mute';
  60. /**
  61. * Creates an event which indicates that a certain action was requested through
  62. * the jitsi-meet API.
  63. *
  64. * @param {Object} action - The action which was requested through the
  65. * jitsi-meet API.
  66. * @param {Object} attributes - Attributes to attach to the event.
  67. * @returns {Object} The event in a format suitable for sending via
  68. * sendAnalytics.
  69. */
  70. export function createApiEvent(action, attributes = {}) {
  71. return {
  72. action,
  73. attributes,
  74. source: 'jitsi-meet-api'
  75. };
  76. }
  77. /**
  78. * Creates an event which indicates that the audio-only mode has been changed.
  79. *
  80. * @param {boolean} enabled - True if audio-only is enabled, false otherwise.
  81. * @returns {Object} The event in a format suitable for sending via
  82. * sendAnalytics.
  83. */
  84. export function createAudioOnlyChangedEvent(enabled) {
  85. return {
  86. action: `audio.only.${enabled ? 'enabled' : 'disabled'}`
  87. };
  88. }
  89. /**
  90. * Creates an event which indicates that a device was changed.
  91. *
  92. * @param {string} mediaType - The media type of the device ('audio' or
  93. * 'video').
  94. * @param {string} deviceType - The type of the device ('input' or 'output').
  95. * @returns {Object} The event in a format suitable for sending via
  96. * sendAnalytics.
  97. */
  98. export function createDeviceChangedEvent(mediaType, deviceType) {
  99. return {
  100. action: 'device.changed',
  101. attributes: {
  102. 'device_type': deviceType,
  103. 'media_type': mediaType
  104. }
  105. };
  106. }
  107. /**
  108. * Creates an event which specifies that the feedback dialog has been opened.
  109. *
  110. * @returns {Object} The event in a format suitable for sending via
  111. * sendAnalytics.
  112. */
  113. export function createFeedbackOpenEvent() {
  114. return {
  115. action: 'feedback.opened'
  116. };
  117. }
  118. /**
  119. * Creates an event for an action regarding the AddPeopleDialog (invites).
  120. *
  121. * @param {string} action - The action that the event represents.
  122. * @param {string} actionSubject - The subject that was acted upon.
  123. * @param {boolean} attributes - Additional attributes to attach to the event.
  124. * @returns {Object} The event in a format suitable for sending via
  125. * sendAnalytics.
  126. */
  127. export function createInviteDialogEvent(
  128. action, actionSubject, attributes = {}) {
  129. return {
  130. action,
  131. actionSubject,
  132. attributes,
  133. source: 'inviteDialog'
  134. };
  135. }
  136. /**
  137. * Creates a "page reload" event.
  138. *
  139. * @param {string} reason - The reason for the reload.
  140. * @param {number} timeout - The timeout in seconds after which the page is
  141. * scheduled to reload.
  142. * @param {Object} details - The details for the error.
  143. * @returns {Object} The event in a format suitable for sending via
  144. * sendAnalytics.
  145. */
  146. export function createPageReloadScheduledEvent(reason, timeout, details) {
  147. return {
  148. action: 'page.reload.scheduled',
  149. attributes: {
  150. reason,
  151. timeout,
  152. ...details
  153. }
  154. };
  155. }
  156. /**
  157. * Creates a "pinned" or "unpinned" event.
  158. *
  159. * @param {string} action - The action ("pinned" or "unpinned").
  160. * @param {string} participantId - The ID of the participant which was pinned.
  161. * @param {Object} attributes - Attributes to attach to the event.
  162. * @returns {Object} The event in a format suitable for sending via
  163. * sendAnalytics.
  164. */
  165. export function createPinnedEvent(action, participantId, attributes) {
  166. return {
  167. type: TYPE_TRACK,
  168. action,
  169. actionSubject: 'participant',
  170. objectType: 'participant',
  171. objectId: participantId,
  172. attributes
  173. };
  174. }
  175. /**
  176. * Creates an event which indicates that a button in the profile panel was
  177. * clicked.
  178. *
  179. * @param {string} buttonName - The name of the button.
  180. * @param {Object} attributes - Attributes to attach to the event.
  181. * @returns {Object} The event in a format suitable for sending via
  182. * sendAnalytics.
  183. */
  184. export function createProfilePanelButtonEvent(buttonName, attributes = {}) {
  185. return {
  186. action: 'clicked',
  187. actionSubject: buttonName,
  188. attributes,
  189. source: 'profile.panel',
  190. type: TYPE_UI
  191. };
  192. }
  193. /**
  194. * Creates an event which indicates that a specific button on one of the
  195. * recording-related dialogs was clicked.
  196. *
  197. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  198. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  199. * 'cancel').
  200. * @returns {Object} The event in a format suitable for sending via
  201. * sendAnalytics.
  202. */
  203. export function createRecordingDialogEvent(dialogName, buttonName) {
  204. return {
  205. action: 'clicked',
  206. actionSubject: buttonName,
  207. source: `${dialogName}.recording.dialog`,
  208. type: TYPE_UI
  209. };
  210. }
  211. /**
  212. * Creates an event which specifies that the "confirm" button on the remote
  213. * mute dialog has been clicked.
  214. *
  215. * @param {string} participantId - The ID of the participant that was remotely
  216. * muted.
  217. * @returns {Object} The event in a format suitable for sending via
  218. * sendAnalytics.
  219. */
  220. export function createRemoteMuteConfirmedEvent(participantId) {
  221. return {
  222. action: 'clicked',
  223. actionSubject: 'remote.mute.dialog.confirm.button',
  224. attributes: {
  225. 'participant_id': participantId
  226. },
  227. source: 'remote.mute.dialog',
  228. type: TYPE_UI
  229. };
  230. }
  231. /**
  232. * Creates an event which indicates that one of the buttons in the "remote
  233. * video menu" was clicked.
  234. *
  235. * @param {string} buttonName - The name of the button.
  236. * @param {Object} attributes - Attributes to attach to the event.
  237. * @returns {Object} The event in a format suitable for sending via
  238. * sendAnalytics.
  239. */
  240. export function createRemoteVideoMenuButtonEvent(buttonName, attributes) {
  241. return {
  242. action: 'clicked',
  243. actionSubject: buttonName,
  244. attributes,
  245. source: 'remote.video.menu',
  246. type: TYPE_UI
  247. };
  248. }
  249. /**
  250. * Creates an event indicating that an action related to screen sharing
  251. * occurred (e.g. it was started or stopped).
  252. *
  253. * @param {string} action - The action which occurred.
  254. * @returns {Object} The event in a format suitable for sending via
  255. * sendAnalytics.
  256. */
  257. export function createScreenSharingEvent(action) {
  258. return {
  259. action,
  260. actionSubject: 'screen.sharing'
  261. };
  262. }
  263. /**
  264. * The local participant failed to send a "selected endpoint" message to the
  265. * bridge.
  266. *
  267. * @param {Error} error - The error which caused the failure.
  268. * @returns {Object} The event in a format suitable for sending via
  269. * sendAnalytics.
  270. */
  271. export function createSelectParticipantFailedEvent(error) {
  272. const event = {
  273. action: 'select.participant.failed'
  274. };
  275. if (error) {
  276. event.error = error.toString();
  277. }
  278. return event;
  279. }
  280. /**
  281. * Creates an event associated with the "shared video" feature.
  282. *
  283. * @param {string} action - The action that the event represents.
  284. * @param {Object} attributes - Attributes to attach to the event.
  285. * @returns {Object} The event in a format suitable for sending via
  286. * sendAnalytics.
  287. */
  288. export function createSharedVideoEvent(action, attributes = {}) {
  289. return {
  290. action,
  291. attributes,
  292. actionSubject: 'shared.video'
  293. };
  294. }
  295. /**
  296. * Creates an event associated with a shortcut being pressed, released or
  297. * triggered. By convention, where appropriate an attribute named 'enable'
  298. * should be used to indicate the action which resulted by the shortcut being
  299. * pressed (e.g. whether screen sharing was enabled or disabled).
  300. *
  301. * @param {string} shortcut - The identifier of the shortcut which produced
  302. * an action.
  303. * @param {string} action - The action that the event represents (one
  304. * of ACTION_SHORTCUT_PRESSED, ACTION_SHORTCUT_RELEASED
  305. * or ACTION_SHORTCUT_TRIGGERED).
  306. * @param {Object} attributes - Attributes to attach to the event.
  307. * @returns {Object} The event in a format suitable for sending via
  308. * sendAnalytics.
  309. */
  310. export function createShortcutEvent(
  311. shortcut,
  312. action = ACTION_SHORTCUT_TRIGGERED,
  313. attributes = {}) {
  314. return {
  315. action,
  316. actionSubject: 'keyboard.shortcut',
  317. actionSubjectId: shortcut,
  318. attributes,
  319. source: 'keyboard.shortcut',
  320. type: TYPE_UI
  321. };
  322. }
  323. /**
  324. * Creates an event which indicates the "start audio only" configuration.
  325. *
  326. * @param {boolean} audioOnly - Whether "start audio only" is enabled or not.
  327. * @returns {Object} The event in a format suitable for sending via
  328. * sendAnalytics.
  329. */
  330. export function createStartAudioOnlyEvent(audioOnly) {
  331. return {
  332. action: 'start.audio.only',
  333. attributes: {
  334. enabled: audioOnly
  335. }
  336. };
  337. }
  338. /**
  339. * Creates an event which indicates the "start muted" configuration.
  340. *
  341. * @param {string} source - The source of the configuration, 'local' or
  342. * 'remote' depending on whether it comes from the static configuration (i.e.
  343. * config.js) or comes dynamically from Jicofo.
  344. * @param {boolean} audioMute - Whether the configuration requests that audio
  345. * is muted.
  346. * @param {boolean} videoMute - Whether the configuration requests that video
  347. * is muted.
  348. * @returns {Object} The event in a format suitable for sending via
  349. * sendAnalytics.
  350. */
  351. export function createStartMutedConfigurationEvent(
  352. source,
  353. audioMute,
  354. videoMute) {
  355. return {
  356. action: 'start.muted.configuration',
  357. attributes: {
  358. source,
  359. 'audio_mute': audioMute,
  360. 'video_mute': videoMute
  361. }
  362. };
  363. }
  364. /**
  365. * Creates an event which indicates the delay for switching between simulcast
  366. * streams.
  367. *
  368. * @param {Object} attributes - Attributes to attach to the event.
  369. * @returns {Object} The event in a format suitable for sending via
  370. * sendAnalytics.
  371. */
  372. export function createStreamSwitchDelayEvent(attributes) {
  373. return {
  374. action: 'stream.switch.delay',
  375. attributes
  376. };
  377. }
  378. /**
  379. * Automatically changing the mute state of a media track in order to match
  380. * the current stored state in redux.
  381. *
  382. * @param {string} mediaType - The track's media type ('audio' or 'video').
  383. * @param {boolean} muted - Whether the track is being muted or unmuted as
  384. * as result of the sync operation.
  385. * @returns {Object} The event in a format suitable for sending via
  386. * sendAnalytics.
  387. */
  388. export function createSyncTrackStateEvent(mediaType, muted) {
  389. return {
  390. action: 'sync.track.state',
  391. attributes: {
  392. 'media_type': mediaType,
  393. muted
  394. }
  395. };
  396. }
  397. /**
  398. * Creates an event associated with a toolbar button being clicked/pressed. By
  399. * convention, where appropriate an attribute named 'enable' should be used to
  400. * indicate the action which resulted by the shortcut being pressed (e.g.
  401. * whether screen sharing was enabled or disabled).
  402. *
  403. * @param {string} buttonName - The identifier of the toolbar button which was
  404. * clicked/pressed.
  405. * @param {Object} attributes - Attributes to attach to the event.
  406. * @returns {Object} The event in a format suitable for sending via
  407. * sendAnalytics.
  408. */
  409. export function createToolbarEvent(buttonName, attributes = {}) {
  410. return {
  411. action: 'clicked',
  412. actionSubject: buttonName,
  413. attributes,
  414. source: 'toolbar.button',
  415. type: TYPE_UI
  416. };
  417. }
  418. /**
  419. * Creates an event which indicates that a local track was muted.
  420. *
  421. * @param {string} mediaType - The track's media type ('audio' or 'video').
  422. * @param {string} reason - The reason the track was muted (e.g. it was
  423. * triggered by the "initial mute" option, or a previously muted track was
  424. * replaced (e.g. when a new device was used)).
  425. * @param {boolean} muted - Whether the track was muted or unmuted.
  426. * @returns {Object} The event in a format suitable for sending via
  427. * sendAnalytics.
  428. */
  429. export function createTrackMutedEvent(mediaType, reason, muted = true) {
  430. return {
  431. action: 'track.muted',
  432. attributes: {
  433. 'media_type': mediaType,
  434. muted,
  435. reason
  436. }
  437. };
  438. }
  439. /**
  440. * Creates an event for an action on the welcome page.
  441. *
  442. * @param {string} action - The action that the event represents.
  443. * @param {string} actionSubject - The subject that was acted upon.
  444. * @param {boolean} attributes - Additional attributes to attach to the event.
  445. * @returns {Object} The event in a format suitable for sending via
  446. * sendAnalytics.
  447. */
  448. export function createWelcomePageEvent(action, actionSubject, attributes = {}) {
  449. return {
  450. action,
  451. actionSubject,
  452. attributes,
  453. source: 'welcomePage'
  454. };
  455. }