Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AnalyticsEvents.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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. *
  6. * @type {string}
  7. */
  8. const TYPE_TRACK = 'track';
  9. /**
  10. * The constant for the event type 'UI' (User Interaction).
  11. * TODO: keep these constants in a single place. Can we import them from
  12. * lib-jitsi-meet's AnalyticsEvents somehow?
  13. *
  14. * @type {string}
  15. */
  16. const TYPE_UI = 'ui';
  17. /**
  18. * The identifier for the "pinned" action. The local participant has pinned a
  19. * participant to remain on large video.
  20. *
  21. * @type {String}
  22. */
  23. export const ACTION_PINNED = 'pinned';
  24. /**
  25. * The identifier for the "unpinned" action. The local participant has unpinned
  26. * a participant so the participant doesn't remain permanently on local large
  27. * video.
  28. *
  29. * @type {String}
  30. */
  31. export const ACTION_UNPINNED = 'unpinned';
  32. /**
  33. * The identifier for the "pressed" action for shortcut events. This action
  34. * means that a button was pressed (and not yet released).
  35. *
  36. * @type {String}
  37. */
  38. export const ACTION_SHORTCUT_PRESSED = 'pressed';
  39. /**
  40. * The identifier for the "released" action for shortcut events. This action
  41. * means that a button which was previously pressed was released.
  42. *
  43. * @type {String}
  44. */
  45. export const ACTION_SHORTCUT_RELEASED = 'released';
  46. /**
  47. * The identifier for the "triggered" action for shortcut events. This action
  48. * means that a button was pressed, and we don't care about whether it was
  49. * released or will be released in the future.
  50. *
  51. * @type {String}
  52. */
  53. export const ACTION_SHORTCUT_TRIGGERED = 'triggered';
  54. /**
  55. * The name of the keyboard shortcut or toolbar button for muting audio.
  56. */
  57. export const AUDIO_MUTE = 'audio.mute';
  58. /**
  59. * The name of the keyboard shortcut or toolbar button for muting video.
  60. */
  61. export const VIDEO_MUTE = 'video.mute';
  62. /**
  63. * Creates an event which indicates that a certain action was requested through
  64. * the jitsi-meet API.
  65. *
  66. * @param {Object} action - The action which was requested through the
  67. * jitsi-meet API.
  68. * @param {Object} attributes - Attributes to attach to the event.
  69. * @returns {Object} The event in a format suitable for sending via
  70. * sendAnalytics.
  71. */
  72. export function createApiEvent(action, attributes = {}) {
  73. return {
  74. action,
  75. attributes,
  76. source: 'jitsi-meet-api'
  77. };
  78. }
  79. /**
  80. * Creates an event which indicates that the audio-only mode has been changed.
  81. *
  82. * @param {boolean} enabled - True if audio-only is enabled, false otherwise.
  83. * @returns {Object} The event in a format suitable for sending via
  84. * sendAnalytics.
  85. */
  86. export function createAudioOnlyChangedEvent(enabled) {
  87. return {
  88. action: `audio.only.${enabled ? 'enabled' : 'disabled'}`
  89. };
  90. }
  91. /**
  92. * Creates an event for about the JitsiConnection.
  93. *
  94. * @param {string} action - The action that the event represents.
  95. * @param {boolean} attributes - Additional attributes to attach to the event.
  96. * @returns {Object} The event in a format suitable for sending via
  97. * sendAnalytics.
  98. */
  99. export function createConnectionEvent(action, attributes = {}) {
  100. return {
  101. action,
  102. actionSubject: 'connection',
  103. attributes
  104. };
  105. }
  106. /**
  107. * Creates an event which indicates an action occurred in the calendar
  108. * integration UI.
  109. *
  110. * @param {string} eventName - The name of the calendar UI event.
  111. * @param {Object} attributes - Attributes to attach to the event.
  112. * @returns {Object} The event in a format suitable for sending via
  113. * sendAnalytics.
  114. */
  115. export function createCalendarClickedEvent(eventName, attributes = {}) {
  116. return {
  117. action: 'clicked',
  118. actionSubject: eventName,
  119. attributes,
  120. source: 'calendar',
  121. type: TYPE_UI
  122. };
  123. }
  124. /**
  125. * Creates an event which indicates that the calendar container is shown and
  126. * selected.
  127. *
  128. * @param {Object} attributes - Attributes to attach to the event.
  129. * @returns {Object} The event in a format suitable for sending via
  130. * sendAnalytics.
  131. */
  132. export function createCalendarSelectedEvent(attributes = {}) {
  133. return {
  134. action: 'selected',
  135. actionSubject: 'calendar.selected',
  136. attributes,
  137. source: 'calendar',
  138. type: TYPE_UI
  139. };
  140. }
  141. /**
  142. * Creates an event indicating that a calendar has been connected.
  143. *
  144. * @param {boolean} attributes - Additional attributes to attach to the event.
  145. * @returns {Object} The event in a format suitable for sending via
  146. * sendAnalytics.
  147. */
  148. export function createCalendarConnectedEvent(attributes = {}) {
  149. return {
  150. action: 'calendar.connected',
  151. actionSubject: 'calendar.connected',
  152. attributes
  153. };
  154. }
  155. /**
  156. * Creates an event which indicates an action occurred in the recent list
  157. * integration UI.
  158. *
  159. * @param {string} eventName - The name of the recent list UI event.
  160. * @param {Object} attributes - Attributes to attach to the event.
  161. * @returns {Object} The event in a format suitable for sending via
  162. * sendAnalytics.
  163. */
  164. export function createRecentClickedEvent(eventName, attributes = {}) {
  165. return {
  166. action: 'clicked',
  167. actionSubject: eventName,
  168. attributes,
  169. source: 'recent.list',
  170. type: TYPE_UI
  171. };
  172. }
  173. /**
  174. * Creates an event which indicate an action occurred in the chrome extension banner.
  175. *
  176. * @param {boolean} installPressed - Whether the user pressed install or `x` - cancel.
  177. * @param {Object} attributes - Attributes to attach to the event.
  178. * @returns {Object} The event in a format suitable for sending via
  179. * sendAnalytics.
  180. */
  181. export function createChromeExtensionBannerEvent(installPressed, attributes = {}) {
  182. return {
  183. action: installPressed ? 'install' : 'cancel',
  184. attributes,
  185. source: 'chrome.extension.banner',
  186. type: TYPE_UI
  187. };
  188. }
  189. /**
  190. * Creates an event which indicates that the recent list container is shown and
  191. * selected.
  192. *
  193. * @param {Object} attributes - Attributes to attach to the event.
  194. * @returns {Object} The event in a format suitable for sending via
  195. * sendAnalytics.
  196. */
  197. export function createRecentSelectedEvent(attributes = {}) {
  198. return {
  199. action: 'selected',
  200. actionSubject: 'recent.list.selected',
  201. attributes,
  202. source: 'recent.list',
  203. type: TYPE_UI
  204. };
  205. }
  206. /**
  207. * Creates an event for an action on the deep linking page.
  208. *
  209. * @param {string} action - The action that the event represents.
  210. * @param {string} actionSubject - The subject that was acted upon.
  211. * @param {boolean} attributes - Additional attributes to attach to the event.
  212. * @returns {Object} The event in a format suitable for sending via
  213. * sendAnalytics.
  214. */
  215. export function createDeepLinkingPageEvent(
  216. action, actionSubject, attributes = {}) {
  217. return {
  218. action,
  219. actionSubject,
  220. source: 'deepLinkingPage',
  221. attributes
  222. };
  223. }
  224. /**
  225. * Creates an event which indicates that a device was changed.
  226. *
  227. * @param {string} mediaType - The media type of the device ('audio' or
  228. * 'video').
  229. * @param {string} deviceType - The type of the device ('input' or 'output').
  230. * @returns {Object} The event in a format suitable for sending via
  231. * sendAnalytics.
  232. */
  233. export function createDeviceChangedEvent(mediaType, deviceType) {
  234. return {
  235. action: 'device.changed',
  236. attributes: {
  237. 'device_type': deviceType,
  238. 'media_type': mediaType
  239. }
  240. };
  241. }
  242. /**
  243. * Creates an event indicating that an action related to E2EE occurred.
  244. *
  245. * @param {string} action - The action which occurred.
  246. * @returns {Object} The event in a format suitable for sending via
  247. * sendAnalytics.
  248. */
  249. export function createE2EEEvent(action) {
  250. return {
  251. action,
  252. actionSubject: 'e2ee'
  253. };
  254. }
  255. /**
  256. * Creates an event which specifies that the feedback dialog has been opened.
  257. *
  258. * @returns {Object} The event in a format suitable for sending via
  259. * sendAnalytics.
  260. */
  261. export function createFeedbackOpenEvent() {
  262. return {
  263. action: 'feedback.opened'
  264. };
  265. }
  266. /**
  267. * Creates an event for an action regarding the AddPeopleDialog (invites).
  268. *
  269. * @param {string} action - The action that the event represents.
  270. * @param {string} actionSubject - The subject that was acted upon.
  271. * @param {boolean} attributes - Additional attributes to attach to the event.
  272. * @returns {Object} The event in a format suitable for sending via
  273. * sendAnalytics.
  274. */
  275. export function createInviteDialogEvent(
  276. action, actionSubject, attributes = {}) {
  277. return {
  278. action,
  279. actionSubject,
  280. attributes,
  281. source: 'inviteDialog'
  282. };
  283. }
  284. /**
  285. * Creates an event which reports about the current network information reported by the operating system.
  286. *
  287. * @param {boolean} isOnline - Tells whether or not the internet is reachable.
  288. * @param {string} [networkType] - Network type, see {@code NetworkInfo} type defined by the 'base/net-info' feature.
  289. * @param {Object} [details] - Extra info, see {@code NetworkInfo} type defined by the 'base/net-info' feature.
  290. * @returns {Object}
  291. */
  292. export function createNetworkInfoEvent({ isOnline, networkType, details }) {
  293. const attributes = { isOnline };
  294. // Do no include optional stuff or Amplitude handler will log warnings.
  295. networkType && (attributes.networkType = networkType);
  296. details && (attributes.details = details);
  297. return {
  298. action: 'network.info',
  299. attributes
  300. };
  301. }
  302. /**
  303. * Creates an "offer/answer failure" event.
  304. *
  305. * @returns {Object} The event in a format suitable for sending via
  306. * sendAnalytics.
  307. */
  308. export function createOfferAnswerFailedEvent() {
  309. return {
  310. action: 'offer.answer.failure'
  311. };
  312. }
  313. /**
  314. * Creates a "page reload" event.
  315. *
  316. * @param {string} reason - The reason for the reload.
  317. * @param {number} timeout - The timeout in seconds after which the page is
  318. * scheduled to reload.
  319. * @param {Object} details - The details for the error.
  320. * @returns {Object} The event in a format suitable for sending via
  321. * sendAnalytics.
  322. */
  323. export function createPageReloadScheduledEvent(reason, timeout, details) {
  324. return {
  325. action: 'page.reload.scheduled',
  326. attributes: {
  327. reason,
  328. timeout,
  329. ...details
  330. }
  331. };
  332. }
  333. /**
  334. * Creates a "pinned" or "unpinned" event.
  335. *
  336. * @param {string} action - The action ("pinned" or "unpinned").
  337. * @param {string} participantId - The ID of the participant which was pinned.
  338. * @param {Object} attributes - Attributes to attach to the event.
  339. * @returns {Object} The event in a format suitable for sending via
  340. * sendAnalytics.
  341. */
  342. export function createPinnedEvent(action, participantId, attributes) {
  343. return {
  344. type: TYPE_TRACK,
  345. action,
  346. actionSubject: 'participant',
  347. objectType: 'participant',
  348. objectId: participantId,
  349. attributes
  350. };
  351. }
  352. /**
  353. * Creates a poll event.
  354. * The following events will be created:
  355. * - poll.created
  356. * - poll.vote.checked
  357. * - poll.vote.sent
  358. * - poll.vote.skipped
  359. * - poll.vote.detailsViewed
  360. * - poll.vote.changed
  361. * - poll.option.added
  362. * - poll.option.moved
  363. * - poll.option.removed.
  364. *
  365. * @param {string} action - The action.
  366. * @returns {Object}
  367. */
  368. export function createPollEvent(action) {
  369. return {
  370. action: `poll.${action}`
  371. };
  372. }
  373. /**
  374. * Creates an event which indicates that a button in the profile panel was
  375. * clicked.
  376. *
  377. * @param {string} buttonName - The name of the button.
  378. * @param {Object} attributes - Attributes to attach to the event.
  379. * @returns {Object} The event in a format suitable for sending via
  380. * sendAnalytics.
  381. */
  382. export function createProfilePanelButtonEvent(buttonName, attributes = {}) {
  383. return {
  384. action: 'clicked',
  385. actionSubject: buttonName,
  386. attributes,
  387. source: 'profile.panel',
  388. type: TYPE_UI
  389. };
  390. }
  391. /**
  392. * Creates an event which indicates that a specific button on one of the
  393. * recording-related dialogs was clicked.
  394. *
  395. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  396. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  397. * 'cancel').
  398. * @param {Object} attributes - Attributes to attach to the event.
  399. * @returns {Object} The event in a format suitable for sending via
  400. * sendAnalytics.
  401. */
  402. export function createRecordingDialogEvent(
  403. dialogName, buttonName, attributes = {}) {
  404. return {
  405. action: 'clicked',
  406. actionSubject: buttonName,
  407. attributes,
  408. source: `${dialogName}.recording.dialog`,
  409. type: TYPE_UI
  410. };
  411. }
  412. /**
  413. * Creates an event which indicates that a specific button on one of the
  414. * liveStreaming-related dialogs was clicked.
  415. *
  416. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  417. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  418. * 'cancel').
  419. * @returns {Object} The event in a format suitable for sending via
  420. * sendAnalytics.
  421. */
  422. export function createLiveStreamingDialogEvent(dialogName, buttonName) {
  423. return {
  424. action: 'clicked',
  425. actionSubject: buttonName,
  426. source: `${dialogName}.liveStreaming.dialog`,
  427. type: TYPE_UI
  428. };
  429. }
  430. /**
  431. * Creates an event with the local tracks duration.
  432. *
  433. * @param {Object} duration - The object with the duration of the local tracks.
  434. * @returns {Object} The event in a format suitable for sending via
  435. * sendAnalytics.
  436. */
  437. export function createLocalTracksDurationEvent(duration) {
  438. const { audio, video, conference } = duration;
  439. const { camera, desktop } = video;
  440. return {
  441. action: 'local.tracks.durations',
  442. attributes: {
  443. audio: audio.value,
  444. camera: camera.value,
  445. conference: conference.value,
  446. desktop: desktop.value
  447. }
  448. };
  449. }
  450. /**
  451. * Creates an event which indicates that an action related to recording has
  452. * occurred.
  453. *
  454. * @param {string} action - The action (e.g. 'start' or 'stop').
  455. * @param {string} type - The recording type (e.g. 'file' or 'live').
  456. * @param {number} value - The duration of the recording in seconds (for stop
  457. * action).
  458. * @returns {Object} The event in a format suitable for sending via
  459. * sendAnalytics.
  460. */
  461. export function createRecordingEvent(action, type, value) {
  462. return {
  463. action,
  464. actionSubject: `recording.${type}`,
  465. attributes: {
  466. value
  467. }
  468. };
  469. }
  470. /**
  471. * Creates an event which indicates that the same conference has been rejoined.
  472. *
  473. * @param {string} url - The full conference URL.
  474. * @param {number} lastConferenceDuration - How many seconds user stayed in the previous conference.
  475. * @param {number} timeSinceLeft - How many seconds since the last conference was left.
  476. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  477. */
  478. export function createRejoinedEvent({ url, lastConferenceDuration, timeSinceLeft }) {
  479. return {
  480. action: 'rejoined',
  481. attributes: {
  482. lastConferenceDuration,
  483. timeSinceLeft,
  484. url
  485. }
  486. };
  487. }
  488. /**
  489. * Creates an event which specifies that the "confirm" button on the remote
  490. * mute dialog has been clicked.
  491. *
  492. * @param {string} participantId - The ID of the participant that was remotely
  493. * muted.
  494. * @param {string} mediaType - The media type of the channel to mute.
  495. * @returns {Object} The event in a format suitable for sending via
  496. * sendAnalytics.
  497. */
  498. export function createRemoteMuteConfirmedEvent(participantId, mediaType) {
  499. return {
  500. action: 'clicked',
  501. actionSubject: 'remote.mute.dialog.confirm.button',
  502. attributes: {
  503. 'participant_id': participantId,
  504. 'media_type': mediaType
  505. },
  506. source: 'remote.mute.dialog',
  507. type: TYPE_UI
  508. };
  509. }
  510. /**
  511. * Creates an event which indicates that one of the buttons in the "remote
  512. * video menu" was clicked.
  513. *
  514. * @param {string} buttonName - The name of the button.
  515. * @param {Object} attributes - Attributes to attach to the event.
  516. * @returns {Object} The event in a format suitable for sending via
  517. * sendAnalytics.
  518. */
  519. export function createRemoteVideoMenuButtonEvent(buttonName, attributes) {
  520. return {
  521. action: 'clicked',
  522. actionSubject: buttonName,
  523. attributes,
  524. source: 'remote.video.menu',
  525. type: TYPE_UI
  526. };
  527. }
  528. /**
  529. * The rtcstats websocket onclose event. We send this to amplitude in order
  530. * to detect trace ws prematurely closing.
  531. *
  532. * @param {Object} closeEvent - The event with which the websocket closed.
  533. * @returns {Object} The event in a format suitable for sending via
  534. * sendAnalytics.
  535. */
  536. export function createRTCStatsTraceCloseEvent(closeEvent) {
  537. const event = {
  538. action: 'trace.onclose',
  539. source: 'rtcstats'
  540. };
  541. event.code = closeEvent.code;
  542. event.reason = closeEvent.reason;
  543. return event;
  544. }
  545. /**
  546. * Creates an event indicating that an action related to video blur
  547. * occurred (e.g. It was started or stopped).
  548. *
  549. * @param {string} action - The action which occurred.
  550. * @returns {Object} The event in a format suitable for sending via
  551. * sendAnalytics.
  552. */
  553. export function createVideoBlurEvent(action) {
  554. return {
  555. action,
  556. actionSubject: 'video.blur'
  557. };
  558. }
  559. /**
  560. * Creates an event indicating that an action related to screen sharing
  561. * occurred (e.g. It was started or stopped).
  562. *
  563. * @param {string} action - The action which occurred.
  564. * @param {number?} value - The screenshare duration in seconds.
  565. * @returns {Object} The event in a format suitable for sending via
  566. * sendAnalytics.
  567. */
  568. export function createScreenSharingEvent(action, value = null) {
  569. return {
  570. action,
  571. actionSubject: 'screen.sharing',
  572. attributes: {
  573. value
  574. }
  575. };
  576. }
  577. /**
  578. * Creates an event which indicates the screen sharing video is not displayed when it needs to be displayed.
  579. *
  580. * @param {Object} attributes - Additional information that describes the issue.
  581. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  582. */
  583. export function createScreenSharingIssueEvent(attributes) {
  584. return {
  585. action: 'screen.sharing.issue',
  586. attributes
  587. };
  588. }
  589. /**
  590. * The local participant failed to send a "selected endpoint" message to the
  591. * bridge.
  592. *
  593. * @param {Error} error - The error which caused the failure.
  594. * @returns {Object} The event in a format suitable for sending via
  595. * sendAnalytics.
  596. */
  597. export function createSelectParticipantFailedEvent(error) {
  598. const event = {
  599. action: 'select.participant.failed'
  600. };
  601. if (error) {
  602. event.error = error.toString();
  603. }
  604. return event;
  605. }
  606. /**
  607. * Creates an event associated with the "shared video" feature.
  608. *
  609. * @param {string} action - The action that the event represents.
  610. * @param {Object} attributes - Attributes to attach to the event.
  611. * @returns {Object} The event in a format suitable for sending via
  612. * sendAnalytics.
  613. */
  614. export function createSharedVideoEvent(action, attributes = {}) {
  615. return {
  616. action,
  617. attributes,
  618. actionSubject: 'shared.video'
  619. };
  620. }
  621. /**
  622. * Creates an event associated with a shortcut being pressed, released or
  623. * triggered. By convention, where appropriate an attribute named 'enable'
  624. * should be used to indicate the action which resulted by the shortcut being
  625. * pressed (e.g. Whether screen sharing was enabled or disabled).
  626. *
  627. * @param {string} shortcut - The identifier of the shortcut which produced
  628. * an action.
  629. * @param {string} action - The action that the event represents (one
  630. * of ACTION_SHORTCUT_PRESSED, ACTION_SHORTCUT_RELEASED
  631. * or ACTION_SHORTCUT_TRIGGERED).
  632. * @param {Object} attributes - Attributes to attach to the event.
  633. * @returns {Object} The event in a format suitable for sending via
  634. * sendAnalytics.
  635. */
  636. export function createShortcutEvent(
  637. shortcut,
  638. action = ACTION_SHORTCUT_TRIGGERED,
  639. attributes = {}) {
  640. return {
  641. action,
  642. actionSubject: 'keyboard.shortcut',
  643. actionSubjectId: shortcut,
  644. attributes,
  645. source: 'keyboard.shortcut',
  646. type: TYPE_UI
  647. };
  648. }
  649. /**
  650. * Creates an event which indicates the "start audio only" configuration.
  651. *
  652. * @param {boolean} audioOnly - Whether "start audio only" is enabled or not.
  653. * @returns {Object} The event in a format suitable for sending via
  654. * sendAnalytics.
  655. */
  656. export function createStartAudioOnlyEvent(audioOnly) {
  657. return {
  658. action: 'start.audio.only',
  659. attributes: {
  660. enabled: audioOnly
  661. }
  662. };
  663. }
  664. /**
  665. * Creates an event which indicates the "start silent" configuration.
  666. *
  667. * @returns {Object} The event in a format suitable for sending via
  668. * sendAnalytics.
  669. */
  670. export function createStartSilentEvent() {
  671. return {
  672. action: 'start.silent'
  673. };
  674. }
  675. /**
  676. * Creates an event which indicates that HTMLAudioElement.play has failed.
  677. *
  678. * @param {sting} elementID - The ID of the HTMLAudioElement.
  679. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  680. */
  681. export function createAudioPlayErrorEvent(elementID) {
  682. return {
  683. action: 'audio.play.error',
  684. attributes: {
  685. elementID
  686. }
  687. };
  688. }
  689. /**
  690. * Creates an event which indicates that HTMLAudioElement.play has succeded after a prior failure.
  691. *
  692. * @param {sting} elementID - The ID of the HTMLAudioElement.
  693. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  694. */
  695. export function createAudioPlaySuccessEvent(elementID) {
  696. return {
  697. action: 'audio.play.success',
  698. attributes: {
  699. elementID
  700. }
  701. };
  702. }
  703. /**
  704. * Creates an event which indicates the "start muted" configuration.
  705. *
  706. * @param {string} source - The source of the configuration, 'local' or
  707. * 'remote' depending on whether it comes from the static configuration (i.e.
  708. * {@code config.js}) or comes dynamically from Jicofo.
  709. * @param {boolean} audioMute - Whether the configuration requests that audio
  710. * is muted.
  711. * @param {boolean} videoMute - Whether the configuration requests that video
  712. * is muted.
  713. * @returns {Object} The event in a format suitable for sending via
  714. * sendAnalytics.
  715. */
  716. export function createStartMutedConfigurationEvent(
  717. source,
  718. audioMute,
  719. videoMute) {
  720. return {
  721. action: 'start.muted.configuration',
  722. attributes: {
  723. source,
  724. 'audio_mute': audioMute,
  725. 'video_mute': videoMute
  726. }
  727. };
  728. }
  729. /**
  730. * Automatically changing the mute state of a media track in order to match
  731. * the current stored state in redux.
  732. *
  733. * @param {string} mediaType - The track's media type ('audio' or 'video').
  734. * @param {boolean} muted - Whether the track is being muted or unmuted as
  735. * as result of the sync operation.
  736. * @returns {Object} The event in a format suitable for sending via
  737. * sendAnalytics.
  738. */
  739. export function createSyncTrackStateEvent(mediaType, muted) {
  740. return {
  741. action: 'sync.track.state',
  742. attributes: {
  743. 'media_type': mediaType,
  744. muted
  745. }
  746. };
  747. }
  748. /**
  749. * Creates an event associated with a toolbar button being clicked/pressed. By
  750. * convention, where appropriate an attribute named 'enable' should be used to
  751. * indicate the action which resulted by the shortcut being pressed (e.g.
  752. * Whether screen sharing was enabled or disabled).
  753. *
  754. * @param {string} buttonName - The identifier of the toolbar button which was
  755. * clicked/pressed.
  756. * @param {Object} attributes - Attributes to attach to the event.
  757. * @returns {Object} The event in a format suitable for sending via
  758. * sendAnalytics.
  759. */
  760. export function createToolbarEvent(buttonName, attributes = {}) {
  761. return {
  762. action: 'clicked',
  763. actionSubject: buttonName,
  764. attributes,
  765. source: 'toolbar.button',
  766. type: TYPE_UI
  767. };
  768. }
  769. /**
  770. * Creates an event associated with reactions.
  771. *
  772. * @param {string} action - Event action.
  773. * @param {string} name - Event name.
  774. * @param {string} source - Event source.
  775. * @returns {Object} The event in a format suitable for sending via
  776. * sendAnalytics.
  777. */
  778. function createReactionEvent(action, name, source) {
  779. return {
  780. action,
  781. actionSubject: name,
  782. source: `reaction.${source}`,
  783. type: TYPE_UI
  784. };
  785. }
  786. /**
  787. * Creates an event associated with a reaction button being clicked/pressed.
  788. *
  789. * @param {string} buttonName - The identifier of the reaction button which was
  790. * clicked/pressed.
  791. * @returns {Object} The event in a format suitable for sending via
  792. * sendAnalytics.
  793. */
  794. export function createReactionMenuEvent(buttonName) {
  795. return createReactionEvent('clicked', buttonName, 'button');
  796. }
  797. /**
  798. * Creates an event associated with disabling of reaction sounds.
  799. *
  800. * @returns {Object} The event in a format suitable for sending via
  801. * sendAnalytics.
  802. */
  803. export function createReactionSoundsDisabledEvent() {
  804. return createReactionEvent('disabled', 'sounds', 'settings');
  805. }
  806. /**
  807. * Creates an event which indicates that a local track was muted.
  808. *
  809. * @param {string} mediaType - The track's media type ('audio' or 'video').
  810. * @param {string} reason - The reason the track was muted (e.g. It was
  811. * triggered by the "initial mute" option, or a previously muted track was
  812. * replaced (e.g. When a new device was used)).
  813. * @param {boolean} muted - Whether the track was muted or unmuted.
  814. * @returns {Object} The event in a format suitable for sending via
  815. * sendAnalytics.
  816. */
  817. export function createTrackMutedEvent(mediaType, reason, muted = true) {
  818. return {
  819. action: 'track.muted',
  820. attributes: {
  821. 'media_type': mediaType,
  822. muted,
  823. reason
  824. }
  825. };
  826. }
  827. /**
  828. * Creates an event for joining a vpaas conference.
  829. *
  830. * @param {string} tenant - The conference tenant.
  831. * @returns {Object} The event in a format suitable for sending via
  832. * sendAnalytics.
  833. */
  834. export function createVpaasConferenceJoinedEvent(tenant) {
  835. return {
  836. action: 'vpaas.conference.joined',
  837. attributes: {
  838. tenant
  839. }
  840. };
  841. }
  842. /**
  843. * Creates an event for an action on the welcome page.
  844. *
  845. * @param {string} action - The action that the event represents.
  846. * @param {string} actionSubject - The subject that was acted upon.
  847. * @param {boolean} attributes - Additional attributes to attach to the event.
  848. * @returns {Object} The event in a format suitable for sending via
  849. * sendAnalytics.
  850. */
  851. export function createWelcomePageEvent(action, actionSubject, attributes = {}) {
  852. return {
  853. action,
  854. actionSubject,
  855. attributes,
  856. source: 'welcomePage'
  857. };
  858. }
  859. /**
  860. * Creates an event which indicates a screenshot of the screensharing has been taken.
  861. *
  862. * @returns {Object} The event in a format suitable for sending via
  863. * sendAnalytics.
  864. */
  865. export function createScreensharingCaptureTakenEvent() {
  866. return {
  867. action: 'screen.sharing.capture'
  868. };
  869. }