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.ts 28KB

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