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 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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 an "offer/answer failure" event.
  307. *
  308. * @returns {Object} The event in a format suitable for sending via
  309. * sendAnalytics.
  310. */
  311. export function createOfferAnswerFailedEvent() {
  312. return {
  313. action: 'offer.answer.failure'
  314. };
  315. }
  316. /**
  317. * Creates a "page reload" event.
  318. *
  319. * @param {string} reason - The reason for the reload.
  320. * @param {number} timeout - The timeout in seconds after which the page is
  321. * scheduled to reload.
  322. * @param {Object} details - The details for the error.
  323. * @returns {Object} The event in a format suitable for sending via
  324. * sendAnalytics.
  325. */
  326. export function createPageReloadScheduledEvent(reason: string, timeout: number, details: Object) {
  327. return {
  328. action: 'page.reload.scheduled',
  329. attributes: {
  330. reason,
  331. timeout,
  332. ...details
  333. }
  334. };
  335. }
  336. /**
  337. * Creates a "pinned" or "unpinned" event.
  338. *
  339. * @param {string} action - The action ("pinned" or "unpinned").
  340. * @param {string} participantId - The ID of the participant which was pinned.
  341. * @param {Object} attributes - Attributes to attach to the event.
  342. * @returns {Object} The event in a format suitable for sending via
  343. * sendAnalytics.
  344. */
  345. export function createPinnedEvent(action: string, participantId: string, attributes = {}) {
  346. return {
  347. type: TYPE_TRACK,
  348. action,
  349. actionSubject: 'participant',
  350. objectType: 'participant',
  351. objectId: participantId,
  352. attributes
  353. };
  354. }
  355. /**
  356. * Creates a poll event.
  357. * The following events will be created:
  358. * - poll.created
  359. * - poll.vote.checked
  360. * - poll.vote.sent
  361. * - poll.vote.skipped
  362. * - poll.vote.detailsViewed
  363. * - poll.vote.changed
  364. * - poll.option.added
  365. * - poll.option.moved
  366. * - poll.option.removed.
  367. *
  368. * @param {string} action - The action.
  369. * @returns {Object}
  370. */
  371. export function createPollEvent(action: string) {
  372. return {
  373. action: `poll.${action}`
  374. };
  375. }
  376. /**
  377. * Creates an event which indicates that a button in the profile panel was
  378. * clicked.
  379. *
  380. * @param {string} buttonName - The name of the button.
  381. * @param {Object} attributes - Attributes to attach to the event.
  382. * @returns {Object} The event in a format suitable for sending via
  383. * sendAnalytics.
  384. */
  385. export function createProfilePanelButtonEvent(buttonName: string, attributes = {}) {
  386. return {
  387. action: 'clicked',
  388. actionSubject: buttonName,
  389. attributes,
  390. source: 'profile.panel',
  391. type: TYPE_UI
  392. };
  393. }
  394. /**
  395. * Creates an event which indicates that a specific button on one of the
  396. * recording-related dialogs was clicked.
  397. *
  398. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  399. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  400. * 'cancel').
  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 createRecordingDialogEvent(
  406. dialogName: string, buttonName: string, attributes = {}) {
  407. return {
  408. action: 'clicked',
  409. actionSubject: buttonName,
  410. attributes,
  411. source: `${dialogName}.recording.dialog`,
  412. type: TYPE_UI
  413. };
  414. }
  415. /**
  416. * Creates an event which indicates that a specific button on one of the
  417. * liveStreaming-related dialogs was clicked.
  418. *
  419. * @param {string} dialogName - The name of the dialog (e.g. 'start' or 'stop').
  420. * @param {string} buttonName - The name of the button (e.g. 'confirm' or
  421. * 'cancel').
  422. * @returns {Object} The event in a format suitable for sending via
  423. * sendAnalytics.
  424. */
  425. export function createLiveStreamingDialogEvent(dialogName: string, buttonName: string) {
  426. return {
  427. action: 'clicked',
  428. actionSubject: buttonName,
  429. source: `${dialogName}.liveStreaming.dialog`,
  430. type: TYPE_UI
  431. };
  432. }
  433. /**
  434. * Creates an event with the local tracks duration.
  435. *
  436. * @param {Object} duration - The object with the duration of the local tracks.
  437. * @returns {Object} The event in a format suitable for sending via
  438. * sendAnalytics.
  439. */
  440. export function createLocalTracksDurationEvent(duration: {
  441. audio: { value: number; };
  442. conference: { value: number; };
  443. video: {
  444. camera: { value: number; };
  445. desktop: { value: number; };
  446. };
  447. }) {
  448. const { audio, video, conference } = duration;
  449. const { camera, desktop } = video;
  450. return {
  451. action: 'local.tracks.durations',
  452. attributes: {
  453. audio: audio.value,
  454. camera: camera.value,
  455. conference: conference.value,
  456. desktop: desktop.value
  457. }
  458. };
  459. }
  460. /**
  461. * Creates an event which indicates that an action related to recording has
  462. * occurred.
  463. *
  464. * @param {string} action - The action (e.g. 'start' or 'stop').
  465. * @param {string} type - The recording type (e.g. 'file' or 'live').
  466. * @param {number} value - The duration of the recording in seconds (for stop
  467. * action).
  468. * @returns {Object} The event in a format suitable for sending via
  469. * sendAnalytics.
  470. */
  471. export function createRecordingEvent(action: string, type: string, value?: number) {
  472. return {
  473. action,
  474. actionSubject: `recording.${type}`,
  475. attributes: {
  476. value
  477. }
  478. };
  479. }
  480. /**
  481. * Creates an event which indicates that the same conference has been rejoined.
  482. *
  483. * @param {string} url - The full conference URL.
  484. * @param {number} lastConferenceDuration - How many seconds user stayed in the previous conference.
  485. * @param {number} timeSinceLeft - How many seconds since the last conference was left.
  486. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  487. */
  488. export function createRejoinedEvent({ url, lastConferenceDuration, timeSinceLeft }: {
  489. lastConferenceDuration: number;
  490. timeSinceLeft: number;
  491. url: string;
  492. }) {
  493. return {
  494. action: 'rejoined',
  495. attributes: {
  496. lastConferenceDuration,
  497. timeSinceLeft,
  498. url
  499. }
  500. };
  501. }
  502. /**
  503. * Creates an event which specifies that the "confirm" button on the remote
  504. * mute dialog has been clicked.
  505. *
  506. * @param {string} participantId - The ID of the participant that was remotely
  507. * muted.
  508. * @param {string} mediaType - The media type of the channel to mute.
  509. * @returns {Object} The event in a format suitable for sending via
  510. * sendAnalytics.
  511. */
  512. export function createRemoteMuteConfirmedEvent(participantId: string, mediaType: string) {
  513. return {
  514. action: 'clicked',
  515. attributes: {
  516. 'participant_id': participantId,
  517. 'media_type': mediaType
  518. },
  519. source: 'remote.mute.button',
  520. type: TYPE_UI
  521. };
  522. }
  523. /**
  524. * Creates an event which indicates that one of the buttons in the "remote
  525. * video menu" was clicked.
  526. *
  527. * @param {string} buttonName - The name of the button.
  528. * @param {Object} attributes - Attributes to attach to the event.
  529. * @returns {Object} The event in a format suitable for sending via
  530. * sendAnalytics.
  531. */
  532. export function createRemoteVideoMenuButtonEvent(buttonName: string, attributes = {}) {
  533. return {
  534. action: 'clicked',
  535. actionSubject: buttonName,
  536. attributes,
  537. source: 'remote.video.menu',
  538. type: TYPE_UI
  539. };
  540. }
  541. /**
  542. * The rtcstats websocket onclose event. We send this to amplitude in order
  543. * to detect trace ws prematurely closing.
  544. *
  545. * @param {Object} closeEvent - The event with which the websocket closed.
  546. * @returns {Object} The event in a format suitable for sending via
  547. * sendAnalytics.
  548. */
  549. export function createRTCStatsTraceCloseEvent(closeEvent: { code: string; reason: string; }) {
  550. const event: {
  551. action: string;
  552. code?: string;
  553. reason?: string;
  554. source: string;
  555. } = {
  556. action: 'trace.onclose',
  557. source: 'rtcstats'
  558. };
  559. event.code = closeEvent.code;
  560. event.reason = closeEvent.reason;
  561. return event;
  562. }
  563. /**
  564. * Creates an event indicating that an action related to screen sharing
  565. * occurred (e.g. It was started or stopped).
  566. *
  567. * @param {string} action - The action which occurred.
  568. * @param {number?} value - The screenshare duration in seconds.
  569. * @returns {Object} The event in a format suitable for sending via
  570. * sendAnalytics.
  571. */
  572. export function createScreenSharingEvent(action: string, value = null) {
  573. return {
  574. action,
  575. actionSubject: 'screen.sharing',
  576. attributes: {
  577. value
  578. }
  579. };
  580. }
  581. /**
  582. * Creates an event which indicates the screen sharing video is not displayed when it needs to be displayed.
  583. *
  584. * @param {Object} attributes - Additional information that describes the issue.
  585. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  586. */
  587. export function createScreenSharingIssueEvent(attributes = {}) {
  588. return {
  589. action: 'screen.sharing.issue',
  590. attributes
  591. };
  592. }
  593. /**
  594. * Creates an event associated with the "shared video" feature.
  595. *
  596. * @param {string} action - The action that the event represents.
  597. * @param {Object} attributes - Attributes to attach to the event.
  598. * @returns {Object} The event in a format suitable for sending via
  599. * sendAnalytics.
  600. */
  601. export function createSharedVideoEvent(action: string, attributes = {}) {
  602. return {
  603. action,
  604. attributes,
  605. actionSubject: 'shared.video'
  606. };
  607. }
  608. /**
  609. * Creates an event associated with a shortcut being pressed, released or
  610. * triggered. By convention, where appropriate an attribute named 'enable'
  611. * should be used to indicate the action which resulted by the shortcut being
  612. * pressed (e.g. Whether screen sharing was enabled or disabled).
  613. *
  614. * @param {string} shortcut - The identifier of the shortcut which produced
  615. * an action.
  616. * @param {string} action - The action that the event represents (one
  617. * of ACTION_SHORTCUT_PRESSED, ACTION_SHORTCUT_RELEASED
  618. * or ACTION_SHORTCUT_TRIGGERED).
  619. * @param {Object} attributes - Attributes to attach to the event.
  620. * @param {string} source - The event's source.
  621. * @returns {Object} The event in a format suitable for sending via
  622. * sendAnalytics.
  623. */
  624. export function createShortcutEvent(
  625. shortcut: string,
  626. action = ACTION_SHORTCUT_TRIGGERED,
  627. attributes = {},
  628. source = 'keyboard.shortcut') {
  629. return {
  630. action,
  631. actionSubjectId: shortcut,
  632. attributes,
  633. source,
  634. type: TYPE_UI
  635. };
  636. }
  637. /**
  638. * Creates an event which indicates the "start audio only" configuration.
  639. *
  640. * @param {boolean} audioOnly - Whether "start audio only" is enabled or not.
  641. * @returns {Object} The event in a format suitable for sending via
  642. * sendAnalytics.
  643. */
  644. export function createStartAudioOnlyEvent(audioOnly: boolean) {
  645. return {
  646. action: 'start.audio.only',
  647. attributes: {
  648. enabled: audioOnly
  649. }
  650. };
  651. }
  652. /**
  653. * Creates an event which indicates the "start silent" configuration.
  654. *
  655. * @returns {Object} The event in a format suitable for sending via
  656. * sendAnalytics.
  657. */
  658. export function createStartSilentEvent() {
  659. return {
  660. action: 'start.silent'
  661. };
  662. }
  663. /**
  664. * Creates an event which indicates that HTMLAudioElement.play has failed.
  665. *
  666. * @param {string} elementID - The ID of the HTMLAudioElement.
  667. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  668. */
  669. export function createAudioPlayErrorEvent(elementID: string) {
  670. return {
  671. action: 'audio.play.error',
  672. attributes: {
  673. elementID
  674. }
  675. };
  676. }
  677. /**
  678. * Creates an event which indicates that HTMLAudioElement.play has succeeded after a prior failure.
  679. *
  680. * @param {string} elementID - The ID of the HTMLAudioElement.
  681. * @returns {Object} The event in a format suitable for sending via sendAnalytics.
  682. */
  683. export function createAudioPlaySuccessEvent(elementID: string) {
  684. return {
  685. action: 'audio.play.success',
  686. attributes: {
  687. elementID
  688. }
  689. };
  690. }
  691. /**
  692. * Creates an event which indicates the "start muted" configuration.
  693. *
  694. * @param {string} source - The source of the configuration, 'local' or
  695. * 'remote' depending on whether it comes from the static configuration (i.e.
  696. * {@code config.js}) or comes dynamically from Jicofo.
  697. * @param {boolean} audioMute - Whether the configuration requests that audio
  698. * is muted.
  699. * @param {boolean} videoMute - Whether the configuration requests that video
  700. * is muted.
  701. * @returns {Object} The event in a format suitable for sending via
  702. * sendAnalytics.
  703. */
  704. export function createStartMutedConfigurationEvent(
  705. source: string,
  706. audioMute: boolean,
  707. videoMute: boolean) {
  708. return {
  709. action: 'start.muted.configuration',
  710. attributes: {
  711. source,
  712. 'audio_mute': audioMute,
  713. 'video_mute': videoMute
  714. }
  715. };
  716. }
  717. /**
  718. * Automatically changing the mute state of a media track in order to match
  719. * the current stored state in redux.
  720. *
  721. * @param {string} mediaType - The track's media type ('audio' or 'video').
  722. * @param {boolean} muted - Whether the track is being muted or unmuted as
  723. * as result of the sync operation.
  724. * @returns {Object} The event in a format suitable for sending via
  725. * sendAnalytics.
  726. */
  727. export function createSyncTrackStateEvent(mediaType: string, muted: boolean) {
  728. return {
  729. action: 'sync.track.state',
  730. attributes: {
  731. 'media_type': mediaType,
  732. muted
  733. }
  734. };
  735. }
  736. /**
  737. * Creates an event associated with a toolbar button being clicked/pressed. By
  738. * convention, where appropriate an attribute named 'enable' should be used to
  739. * indicate the action which resulted by the shortcut being pressed (e.g.
  740. * Whether screen sharing was enabled or disabled).
  741. *
  742. * @param {string} buttonName - The identifier of the toolbar button which was
  743. * clicked/pressed.
  744. * @param {Object} attributes - Attributes to attach to the event.
  745. * @returns {Object} The event in a format suitable for sending via
  746. * sendAnalytics.
  747. */
  748. export function createToolbarEvent(buttonName: string, attributes = {}) {
  749. return {
  750. action: 'clicked',
  751. actionSubject: buttonName,
  752. attributes,
  753. source: 'toolbar.button',
  754. type: TYPE_UI
  755. };
  756. }
  757. /**
  758. * Creates an event associated with a reaction button being clicked/pressed.
  759. *
  760. * @param {string} buttonName - The identifier of the reaction button which was
  761. * clicked/pressed.
  762. * @returns {Object} The event in a format suitable for sending via
  763. * sendAnalytics.
  764. */
  765. export function createReactionMenuEvent(buttonName: string) {
  766. return {
  767. action: 'clicked',
  768. actionSubject: 'button',
  769. source: 'reaction',
  770. buttonName,
  771. type: TYPE_UI
  772. };
  773. }
  774. /**
  775. * Creates an event associated with disabling of reaction sounds.
  776. *
  777. * @returns {Object} The event in a format suitable for sending via
  778. * sendAnalytics.
  779. */
  780. export function createReactionSoundsDisabledEvent() {
  781. return {
  782. action: 'disabled',
  783. actionSubject: 'sounds',
  784. source: 'reaction.settings',
  785. type: TYPE_UI
  786. };
  787. }
  788. /**
  789. * Creates an event which indicates that a local track was muted.
  790. *
  791. * @param {string} mediaType - The track's media type ('audio' or 'video').
  792. * @param {string} reason - The reason the track was muted (e.g. It was
  793. * triggered by the "initial mute" option, or a previously muted track was
  794. * replaced (e.g. When a new device was used)).
  795. * @param {boolean} muted - Whether the track was muted or unmuted.
  796. * @returns {Object} The event in a format suitable for sending via
  797. * sendAnalytics.
  798. */
  799. export function createTrackMutedEvent(mediaType: string, reason: string, muted = true) {
  800. return {
  801. action: 'track.muted',
  802. attributes: {
  803. 'media_type': mediaType,
  804. muted,
  805. reason
  806. }
  807. };
  808. }
  809. /**
  810. * Creates an event for joining a vpaas conference.
  811. *
  812. * @param {string} tenant - The conference tenant.
  813. * @returns {Object} The event in a format suitable for sending via
  814. * sendAnalytics.
  815. */
  816. export function createVpaasConferenceJoinedEvent(tenant: string) {
  817. return {
  818. action: 'vpaas.conference.joined',
  819. attributes: {
  820. tenant
  821. }
  822. };
  823. }
  824. /**
  825. * Creates an event for an action on the welcome page.
  826. *
  827. * @param {string} action - The action that the event represents.
  828. * @param {string} actionSubject - The subject that was acted upon.
  829. * @param {boolean} attributes - Additional attributes to attach to the event.
  830. * @returns {Object} The event in a format suitable for sending via
  831. * sendAnalytics.
  832. */
  833. export function createWelcomePageEvent(action: string, actionSubject?: string, attributes = {}) {
  834. return {
  835. action,
  836. actionSubject,
  837. attributes,
  838. source: 'welcomePage'
  839. };
  840. }
  841. /**
  842. * Creates an event which indicates a screenshot of the screensharing has been taken.
  843. *
  844. * @returns {Object} The event in a format suitable for sending via
  845. * sendAnalytics.
  846. */
  847. export function createScreensharingCaptureTakenEvent() {
  848. return {
  849. action: 'screen.sharing.capture.taken'
  850. };
  851. }
  852. /**
  853. * Creates an event for an action on breakout rooms.
  854. *
  855. * @param {string} actionSubject - The subject that was acted upon.
  856. * @returns {Object} The event in a format suitable for sending via
  857. * sendAnalytics.
  858. */
  859. export function createBreakoutRoomsEvent(actionSubject: string) {
  860. return {
  861. action: 'clicked',
  862. actionSubject: `${actionSubject}.button`,
  863. source: 'breakout.rooms'
  864. };
  865. }
  866. /**
  867. * Creates an event which indicates a GIF was sent.
  868. *
  869. * @returns {Object} The event in a format suitable for sending via
  870. * sendAnalytics.
  871. */
  872. export function createGifSentEvent() {
  873. return {
  874. action: 'gif.sent'
  875. };
  876. }