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

AnalyticsEvents.js 15KB

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