Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AnalyticsEvents.js 15KB

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