You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnalyticsEvents.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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 which indicates that the invite dialog was closed. This is
  120. * not a TYPE_UI event, since it is not necessarily the result of a user
  121. * interaction.
  122. *
  123. * @returns {Object} The event in a format suitable for sending via
  124. * sendAnalytics.
  125. */
  126. export function createInviteDialogClosedEvent() {
  127. return {
  128. action: 'invite.dialog.closed'
  129. };
  130. }
  131. /**
  132. * Creates a "page reload" event.
  133. *
  134. * @param {string} reason - The reason for the reload.
  135. * @param {number} timeout - The timeout in seconds after which the page is
  136. * scheduled to reload.
  137. * @param {Object} details - The details for the error.
  138. * @returns {Object} The event in a format suitable for sending via
  139. * sendAnalytics.
  140. */
  141. export function createPageReloadScheduledEvent(reason, timeout, details) {
  142. return {
  143. action: 'page.reload.scheduled',
  144. attributes: {
  145. reason,
  146. timeout,
  147. ...details
  148. }
  149. };
  150. }
  151. /**
  152. * Creates a "pinned" or "unpinned" event.
  153. *
  154. * @param {string} action - The action ("pinned" or "unpinned").
  155. * @param {string} participantId - The ID of the participant which was pinned.
  156. * @param {Object} attributes - Attributes to attach to the event.
  157. * @returns {Object} The event in a format suitable for sending via
  158. * sendAnalytics.
  159. */
  160. export function createPinnedEvent(action, participantId, attributes) {
  161. return {
  162. type: TYPE_TRACK,
  163. action,
  164. actionSubject: 'participant',
  165. objectType: 'participant',
  166. objectId: participantId,
  167. attributes
  168. };
  169. }
  170. /**
  171. * Creates an event which indicates that a button in the profile panel was
  172. * clicked.
  173. *
  174. * @param {string} buttonName - The name of the button.
  175. * @param {Object} attributes - Attributes to attach to the event.
  176. * @returns {Object} The event in a format suitable for sending via
  177. * sendAnalytics.
  178. */
  179. export function createProfilePanelButtonEvent(buttonName, attributes = {}) {
  180. return {
  181. action: 'clicked',
  182. actionSubject: buttonName,
  183. attributes,
  184. source: 'profile.panel',
  185. type: TYPE_UI
  186. };
  187. }
  188. /**
  189. * Creates an event which indicates that a specific button on one of the
  190. * recording-related dialogs was clicked.
  191. *
  192. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  193. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  194. * 'cancel').
  195. * @returns {Object} The event in a format suitable for sending via
  196. * sendAnalytics.
  197. */
  198. export function createRecordingDialogEvent(dialogName, buttonName) {
  199. return {
  200. action: 'clicked',
  201. actionSubject: buttonName,
  202. source: `${dialogName}.recording.dialog`,
  203. type: TYPE_UI
  204. };
  205. }
  206. /**
  207. * Creates an event which specifies that the "confirm" button on the remote
  208. * mute dialog has been clicked.
  209. *
  210. * @param {string} participantId - The ID of the participant that was remotely
  211. * muted.
  212. * @returns {Object} The event in a format suitable for sending via
  213. * sendAnalytics.
  214. */
  215. export function createRemoteMuteConfirmedEvent(participantId) {
  216. return {
  217. action: 'clicked',
  218. actionSubject: 'remote.mute.dialog.confirm.button',
  219. attributes: {
  220. 'participant_id': participantId
  221. },
  222. source: 'remote.mute.dialog',
  223. type: TYPE_UI
  224. };
  225. }
  226. /**
  227. * Creates an event which indicates that one of the buttons in the "remote
  228. * video menu" was clicked.
  229. *
  230. * @param {string} buttonName - The name of the button.
  231. * @param {Object} attributes - Attributes to attach to the event.
  232. * @returns {Object} The event in a format suitable for sending via
  233. * sendAnalytics.
  234. */
  235. export function createRemoteVideoMenuButtonEvent(buttonName, attributes) {
  236. return {
  237. action: 'clicked',
  238. actionSubject: buttonName,
  239. attributes,
  240. source: 'remote.video.menu',
  241. type: TYPE_UI
  242. };
  243. }
  244. /**
  245. * Creates an event indicating that an action related to screen sharing
  246. * occurred (e.g. it was started or stopped).
  247. *
  248. * @param {string} action - The action which occurred.
  249. * @returns {Object} The event in a format suitable for sending via
  250. * sendAnalytics.
  251. */
  252. export function createScreenSharingEvent(action) {
  253. return {
  254. action,
  255. actionSubject: 'screen.sharing'
  256. };
  257. }
  258. /**
  259. * The local participant failed to send a "selected endpoint" message to the
  260. * bridge.
  261. *
  262. * @param {Error} error - The error which caused the failure.
  263. * @returns {Object} The event in a format suitable for sending via
  264. * sendAnalytics.
  265. */
  266. export function createSelectParticipantFailedEvent(error) {
  267. const event = {
  268. action: 'select.participant.failed'
  269. };
  270. if (error) {
  271. event.error = error.toString();
  272. }
  273. return event;
  274. }
  275. /**
  276. * Creates an event associated with the "shared video" feature.
  277. *
  278. * @param {string} action - The action that the event represents.
  279. * @param {Object} attributes - Attributes to attach to the event.
  280. * @returns {Object} The event in a format suitable for sending via
  281. * sendAnalytics.
  282. */
  283. export function createSharedVideoEvent(action, attributes = {}) {
  284. return {
  285. action,
  286. attributes,
  287. actionSubject: 'shared.video'
  288. };
  289. }
  290. /**
  291. * Creates an event associated with a shortcut being pressed, released or
  292. * triggered. By convention, where appropriate an attribute named 'enable'
  293. * should be used to indicate the action which resulted by the shortcut being
  294. * pressed (e.g. whether screen sharing was enabled or disabled).
  295. *
  296. * @param {string} shortcut - The identifier of the shortcut which produced
  297. * an action.
  298. * @param {string} action - The action that the event represents (one
  299. * of ACTION_SHORTCUT_PRESSED, ACTION_SHORTCUT_RELEASED
  300. * or ACTION_SHORTCUT_TRIGGERED).
  301. * @param {Object} attributes - Attributes to attach to the event.
  302. * @returns {Object} The event in a format suitable for sending via
  303. * sendAnalytics.
  304. */
  305. export function createShortcutEvent(
  306. shortcut,
  307. action = ACTION_SHORTCUT_TRIGGERED,
  308. attributes = {}) {
  309. return {
  310. action,
  311. actionSubject: 'keyboard.shortcut',
  312. actionSubjectId: shortcut,
  313. attributes,
  314. source: 'keyboard.shortcut',
  315. type: TYPE_UI
  316. };
  317. }
  318. /**
  319. * Creates an event which indicates the "start audio only" configuration.
  320. *
  321. * @param {boolean} audioOnly - Whether "start audio only" is enabled or not.
  322. * @returns {Object} The event in a format suitable for sending via
  323. * sendAnalytics.
  324. */
  325. export function createStartAudioOnlyEvent(audioOnly) {
  326. return {
  327. action: 'start.audio.only',
  328. attributes: {
  329. enabled: audioOnly
  330. }
  331. };
  332. }
  333. /**
  334. * Creates an event which indicates the "start muted" configuration.
  335. *
  336. * @param {string} source - The source of the configuration, 'local' or
  337. * 'remote' depending on whether it comes from the static configuration (i.e.
  338. * config.js) or comes dynamically from Jicofo.
  339. * @param {boolean} audioMute - Whether the configuration requests that audio
  340. * is muted.
  341. * @param {boolean} videoMute - Whether the configuration requests that video
  342. * is muted.
  343. * @returns {Object} The event in a format suitable for sending via
  344. * sendAnalytics.
  345. */
  346. export function createStartMutedConfigurationEvent(
  347. source,
  348. audioMute,
  349. videoMute) {
  350. return {
  351. action: 'start.muted.configuration',
  352. attributes: {
  353. source,
  354. 'audio_mute': audioMute,
  355. 'video_mute': videoMute
  356. }
  357. };
  358. }
  359. /**
  360. * Creates an event which indicates the delay for switching between simulcast
  361. * streams.
  362. *
  363. * @param {Object} attributes - Attributes to attach to the event.
  364. * @returns {Object} The event in a format suitable for sending via
  365. * sendAnalytics.
  366. */
  367. export function createStreamSwitchDelayEvent(attributes) {
  368. return {
  369. action: 'stream.switch.delay',
  370. attributes
  371. };
  372. }
  373. /**
  374. * Automatically changing the mute state of a media track in order to match
  375. * the current stored state in redux.
  376. *
  377. * @param {string} mediaType - The track's media type ('audio' or 'video').
  378. * @param {boolean} muted - Whether the track is being muted or unmuted as
  379. * as result of the sync operation.
  380. * @returns {Object} The event in a format suitable for sending via
  381. * sendAnalytics.
  382. */
  383. export function createSyncTrackStateEvent(mediaType, muted) {
  384. return {
  385. action: 'sync.track.state',
  386. attributes: {
  387. 'media_type': mediaType,
  388. muted
  389. }
  390. };
  391. }
  392. /**
  393. * Creates an event associated with a toolbar button being clicked/pressed. By
  394. * convention, where appropriate an attribute named 'enable' should be used to
  395. * indicate the action which resulted by the shortcut being pressed (e.g.
  396. * whether screen sharing was enabled or disabled).
  397. *
  398. * @param {string} buttonName - The identifier of the toolbar button which was
  399. * clicked/pressed.
  400. * @param {Object} attributes - Attributes to attach to the event.
  401. * @returns {Object} The event in a format suitable for sending via
  402. * sendAnalytics.
  403. */
  404. export function createToolbarEvent(buttonName, attributes = {}) {
  405. return {
  406. action: 'clicked',
  407. actionSubject: buttonName,
  408. attributes,
  409. source: 'toolbar.button',
  410. type: TYPE_UI
  411. };
  412. }
  413. /**
  414. * Creates an event which indicates that a local track was muted.
  415. *
  416. * @param {string} mediaType - The track's media type ('audio' or 'video').
  417. * @param {string} reason - The reason the track was muted (e.g. it was
  418. * triggered by the "initial mute" option, or a previously muted track was
  419. * replaced (e.g. when a new device was used)).
  420. * @param {boolean} muted - Whether the track was muted or unmuted.
  421. * @returns {Object} The event in a format suitable for sending via
  422. * sendAnalytics.
  423. */
  424. export function createTrackMutedEvent(mediaType, reason, muted = true) {
  425. return {
  426. action: 'track.muted',
  427. attributes: {
  428. 'media_type': mediaType,
  429. muted,
  430. reason
  431. }
  432. };
  433. }
  434. /**
  435. * Creates an event for an action on the welcome page.
  436. *
  437. * @param {string} action - The action that the event represents.
  438. * @param {string} actionSubject - The subject that was acted upon.
  439. * @param {boolean} attributes - Additional attributes to attach to the event.
  440. * @returns {Object} The event in a format suitable for sending via
  441. * sendAnalytics.
  442. */
  443. export function createWelcomePageEvent(action, actionSubject, attributes = {}) {
  444. return {
  445. action,
  446. actionSubject,
  447. attributes,
  448. source: 'welcomePage'
  449. };
  450. }