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

AnalyticsEvents.ts 28KB

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