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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /**
  2. * This class exports constants and factory methods related to the analytics
  3. * API provided by AnalyticsAdapter. In order for entries in a database to be
  4. * somewhat easily traceable back to the code which produced them, events sent
  5. * through analytics should be defined here.
  6. *
  7. * Since the AnalyticsAdapter API can be used in different ways, for some events
  8. * it is more convenient to just define the event name as a constant. For other
  9. * events a factory function is easier.
  10. *
  11. * A general approach for adding a new event:
  12. * 1. Determine the event type: track, UI, page, or operational. If in doubt use
  13. * operational.
  14. * 2. Determine whether the event is related to other existing events, and
  15. * which fields are desired to be set: name, action, actionSubject, source.
  16. * 3. If the name is sufficient (the other fields are not important), use a
  17. * constant. Otherwise use a factory function.
  18. *
  19. * Note that the AnalyticsAdapter uses the events passed to its functions for
  20. * its own purposes, and might modify them. Because of this, factory functions
  21. * should create new objects.
  22. *
  23. */
  24. export enum AnalyticsEvents {
  25. /**
  26. * The constant which identifies an event of type "operational".
  27. */
  28. TYPE_OPERATIONAL = 'operational',
  29. /**
  30. * The constant which identifies an event of type "page".
  31. */
  32. TYPE_PAGE = 'page',
  33. /**
  34. * The constant which identifies an event of type "track".
  35. */
  36. TYPE_TRACK = 'track',
  37. /**
  38. * The constant which identifies an event of type "ui".
  39. */
  40. TYPE_UI = 'ui',
  41. /**
  42. * The "action" value for Jingle events which indicates that the Jingle session
  43. * was restarted (TODO: verify/fix the documentation)
  44. */
  45. ACTION_JINGLE_RESTART = 'restart',
  46. /**
  47. * The "action" value for Jingle events which indicates that a session-accept
  48. * timed out (TODO: verify/fix the documentation)
  49. */
  50. ACTION_JINGLE_SA_TIMEOUT = 'session-accept.timeout',
  51. /**
  52. * The "action" value for Jingle events which indicates that a session-initiate
  53. * was received.
  54. */
  55. ACTION_JINGLE_SI_RECEIVED = 'session-initiate.received',
  56. /**
  57. * The "action" value for Jingle events which indicates that a session-initiate
  58. * not arrived within a timeout (the value is specified in
  59. * the {@link JingleSessionPC}.
  60. */
  61. ACTION_JINGLE_SI_TIMEOUT = 'session-initiate.timeout',
  62. /**
  63. * A constant for the "terminate" action for Jingle events. TODO: verify/fix
  64. * the documentation)
  65. */
  66. ACTION_JINGLE_TERMINATE = 'terminate',
  67. /**
  68. * The "action" value for Jingle events which indicates that a transport-replace
  69. * was received.
  70. */
  71. ACTION_JINGLE_TR_RECEIVED = 'transport-replace.received',
  72. /**
  73. * The "action" value for Jingle events which indicates that a transport-replace
  74. * succeeded (TODO: verify/fix the documentation)
  75. */
  76. ACTION_JINGLE_TR_SUCCESS = 'transport-replace.success',
  77. /**
  78. * The "action" value for P2P events which indicates that P2P session initiate message has been rejected by the client
  79. * because the mandatory requirements were not met.
  80. */
  81. ACTION_P2P_DECLINED = 'decline',
  82. /**
  83. * The "action" value for P2P events which indicates that a connection was
  84. * established (TODO: verify/fix the documentation)
  85. */
  86. ACTION_P2P_ESTABLISHED = 'established',
  87. /**
  88. * The "action" value for P2P events which indicates that something failed.
  89. */
  90. ACTION_P2P_FAILED = 'failed',
  91. /**
  92. * The "action" value for P2P events which indicates that a switch to
  93. * jitsi-videobridge happened.
  94. */
  95. ACTION_P2P_SWITCH_TO_JVB = 'switch.to.jvb',
  96. /**
  97. * The name of an event which indicates an available device. We send one such
  98. * event per available device once when the available devices are first known,
  99. * and every time that they change
  100. *
  101. * Properties:
  102. * audio_input_device_count: the number of audio input devices available at
  103. * the time the event was sent.
  104. * audio_output_device_count: the number of audio output devices available
  105. * at the time the event was sent.
  106. * video_input_device_count: the number of video input devices available at
  107. * the time the event was sent.
  108. * video_output_device_count: the number of video output devices available
  109. * at the time the event was sent.
  110. * device_id: an identifier of the device described in this event.
  111. * device_group_id:
  112. * device_kind: one of 'audioinput', 'audiooutput', 'videoinput' or
  113. * 'videooutput'.
  114. * device_label: a string which describes the device.
  115. */
  116. AVAILABLE_DEVICE = 'available.device',
  117. /**
  118. * This appears to be fired only in certain cases when the XMPP connection
  119. * disconnects (and it was intentional?). It is currently never observed to
  120. * fire in production.
  121. *
  122. * TODO: document
  123. *
  124. * Properties:
  125. * message: an error message
  126. */
  127. CONNECTION_DISCONNECTED = 'connection.disconnected',
  128. /**
  129. * Indicates that the user of the application provided feedback in terms of a
  130. * rating (an integer from 1 to 5) and an optional comment.
  131. * Properties:
  132. * value: the user's rating (an integer from 1 to 5)
  133. * comment: the user's comment
  134. */
  135. FEEDBACK = 'feedback',
  136. /**
  137. * Indicates the duration of a particular phase of the ICE connectivity
  138. * establishment.
  139. *
  140. * Properties:
  141. * phase: the ICE phase (e.g. 'gathering', 'checking', 'establishment')
  142. * value: the duration in milliseconds.
  143. * p2p: whether the associated ICE connection is p2p or towards a
  144. * jitsi-videobridge
  145. * initiator: whether the local Jingle peer is the initiator or responder
  146. * in the Jingle session. XXX we probably actually care about the ICE
  147. * role (controlling vs controlled), and we assume that this correlates
  148. * with the Jingle initiator.
  149. */
  150. ICE_DURATION = 'ice.duration',
  151. /**
  152. * Indicates the difference in milliseconds between the ICE establishment time
  153. * for the P2P and JVB connections (e.g. a value of 10 would indicate that the
  154. * P2P connection took 10ms more than JVB connection to establish).
  155. *
  156. * Properties:
  157. * value: the difference in establishment durations in milliseconds.
  158. *
  159. */
  160. ICE_ESTABLISHMENT_DURATION_DIFF = 'ice.establishment.duration.diff',
  161. /**
  162. * Indicates that the ICE state has changed.
  163. *
  164. * Properties:
  165. * state: the ICE state which was entered (e.g. 'checking', 'connected',
  166. * 'completed', etc).
  167. * value: the time in milliseconds (as reported by
  168. * window.performance.now()) that the state change occurred.
  169. * p2p: whether the associated ICE connection is p2p or towards a
  170. * jitsi-videobridge
  171. * signalingState: The signaling state of the associated PeerConnection
  172. * reconnect: whether the associated Jingle session is in the process of
  173. * reconnecting (or is it ICE? TODO: verify/fix the documentation)
  174. */
  175. ICE_STATE_CHANGED = 'ice.state.changed',
  176. /**
  177. * Indicates that no bytes have been sent for the track.
  178. *
  179. * Properties:
  180. * mediaType: the media type of the local track ('audio' or 'video').
  181. */
  182. NO_BYTES_SENT = 'track.no-bytes-sent',
  183. /**
  184. * Indicates that a track was unmuted (?).
  185. *
  186. * Properties:
  187. * mediaType: the media type of the local track ('audio' or 'video').
  188. * trackType: the type of the track ('local' or 'remote').
  189. * value: TODO: document
  190. */
  191. TRACK_UNMUTED = 'track.unmuted',
  192. /**
  193. * Indicates that the video codec changed for a local track.
  194. *
  195. * Properties:
  196. * value: the video codec mimeType.
  197. * videoType: the videoType of local track, whether its 'camera' or 'desktop'.
  198. */
  199. VIDEO_CODEC_CHANGED = 'quality.video-codec-changed',
  200. }
  201. // exported for backward compatibility
  202. export const TYPE_OPERATIONAL = AnalyticsEvents.TYPE_OPERATIONAL;
  203. export const TYPE_PAGE = AnalyticsEvents.TYPE_PAGE;
  204. export const TYPE_TRACK = AnalyticsEvents.TYPE_TRACK;
  205. export const TYPE_UI = AnalyticsEvents.TYPE_UI;
  206. export const ACTION_JINGLE_RESTART = AnalyticsEvents.ACTION_JINGLE_RESTART;
  207. export const ACTION_JINGLE_SA_TIMEOUT = AnalyticsEvents.ACTION_JINGLE_SA_TIMEOUT;
  208. export const ACTION_JINGLE_SI_RECEIVED = AnalyticsEvents.ACTION_JINGLE_SI_RECEIVED;
  209. export const ACTION_JINGLE_SI_TIMEOUT = AnalyticsEvents.ACTION_JINGLE_SI_TIMEOUT;
  210. export const ACTION_JINGLE_TERMINATE = AnalyticsEvents.ACTION_JINGLE_TERMINATE;
  211. export const ACTION_JINGLE_TR_RECEIVED = AnalyticsEvents.ACTION_JINGLE_TR_RECEIVED;
  212. export const ACTION_JINGLE_TR_SUCCESS = AnalyticsEvents.ACTION_JINGLE_TR_SUCCESS;
  213. export const ACTION_P2P_DECLINED = AnalyticsEvents.ACTION_P2P_DECLINED;
  214. export const ACTION_P2P_ESTABLISHED = AnalyticsEvents.ACTION_P2P_ESTABLISHED;
  215. export const ACTION_P2P_FAILED = AnalyticsEvents.ACTION_P2P_FAILED;
  216. export const ACTION_P2P_SWITCH_TO_JVB = AnalyticsEvents.ACTION_P2P_SWITCH_TO_JVB;
  217. export const AVAILABLE_DEVICE = AnalyticsEvents.AVAILABLE_DEVICE;
  218. export const CONNECTION_DISCONNECTED = AnalyticsEvents.CONNECTION_DISCONNECTED;
  219. export const FEEDBACK = AnalyticsEvents.FEEDBACK;
  220. export const ICE_DURATION = AnalyticsEvents.ICE_DURATION;
  221. export const ICE_ESTABLISHMENT_DURATION_DIFF = AnalyticsEvents.ICE_ESTABLISHMENT_DURATION_DIFF;
  222. export const ICE_STATE_CHANGED = AnalyticsEvents.ICE_STATE_CHANGED;
  223. export const NO_BYTES_SENT = AnalyticsEvents.NO_BYTES_SENT;
  224. export const TRACK_UNMUTED = AnalyticsEvents.TRACK_UNMUTED;
  225. export const VIDEO_CODEC_CHANGED = AnalyticsEvents.VIDEO_CODEC_CHANGED;
  226. /**
  227. * Creates an operational event which indicates that we have received a
  228. * "bridge down" event from jicofo.
  229. */
  230. export const createBridgeDownEvent = () => ( {
  231. action: 'bridge.down',
  232. actionSubject: 'bridge.down',
  233. type: TYPE_OPERATIONAL
  234. } );
  235. /**
  236. * Creates an event which indicates that the XMPP connection failed
  237. * @param errorType TODO
  238. * @param errorMessage TODO
  239. * @param detail connection failed details.
  240. */
  241. export const createConnectionFailedEvent = ( errorType: unknown, errorMessage: unknown, details: object ) => ( {
  242. type: AnalyticsEvents.TYPE_OPERATIONAL,
  243. action: 'connection.failed',
  244. attributes: {
  245. 'error_type': errorType,
  246. 'error_message': errorMessage,
  247. ...details
  248. }
  249. } );
  250. /**
  251. * Creates a conference event.
  252. *
  253. * @param action - The action of the event.
  254. * @param attributes - The attributes to be added to the event.
  255. */
  256. export const createConferenceEvent = ( action: string, attributes: object ) => ( {
  257. action,
  258. attributes,
  259. source: 'conference',
  260. type: AnalyticsEvents.TYPE_OPERATIONAL
  261. } );
  262. /**
  263. * Creates an operational event which indicates that a particular connection
  264. * stage was reached (i.e. the XMPP connection transitioned to the "connected"
  265. * state).
  266. *
  267. * @param stage the stage which was reached
  268. * @param attributes additional attributes for the event. This should be an
  269. * object with a "value" property indicating a timestamp in milliseconds
  270. * relative to the beginning of the document's lifetime.
  271. *
  272. */
  273. export const createConnectionStageReachedEvent = ( stage: unknown, attributes: object ) => ( {
  274. action: 'connection.stage.reached',
  275. actionSubject: stage,
  276. attributes,
  277. source: 'connection.stage.reached',
  278. type: AnalyticsEvents.TYPE_OPERATIONAL
  279. } );
  280. /**
  281. * Creates an operational event for the end-to-end round trip time to a
  282. * specific remote participant.
  283. * @param participantId the ID of the remote participant.
  284. * @param region the region of the remote participant
  285. * @param rtt the rtt
  286. */
  287. export const createE2eRttEvent = ( participantId: unknown, region: unknown, rtt: unknown ) => ( {
  288. attributes: {
  289. 'participant_id': participantId,
  290. region,
  291. rtt
  292. },
  293. name: 'e2e_rtt',
  294. type: AnalyticsEvents.TYPE_OPERATIONAL
  295. } );
  296. /**
  297. * Creates an event which indicates that the focus has left the MUC.
  298. */
  299. export const createFocusLeftEvent = () => ( {
  300. action: 'focus.left',
  301. actionSubject: 'focus.left',
  302. type: AnalyticsEvents.TYPE_OPERATIONAL
  303. } );
  304. /**
  305. * Creates an event related to a getUserMedia call.
  306. *
  307. * @param action the type of the result that the event represents: 'error',
  308. * 'success', 'warning', etc.
  309. * @param attributes the attributes to attach to the event.
  310. */
  311. export const createGetUserMediaEvent = ( action: 'error' | 'success' | 'warning' | string, attributes: object = {} ) => ( {
  312. type: AnalyticsEvents.TYPE_OPERATIONAL,
  313. source: 'get.user.media',
  314. action,
  315. attributes
  316. } );
  317. /**
  318. * Creates an event related to remote participant connection status changes.
  319. *
  320. * @param attributes the attributes to attach to the event.
  321. */
  322. export const createParticipantConnectionStatusEvent = ( attributes: object = {} ) => ( {
  323. type: AnalyticsEvents.TYPE_OPERATIONAL,
  324. source: 'peer.conn.status',
  325. action: 'duration',
  326. attributes
  327. } );
  328. /**
  329. * Creates an event related to remote track streaming status changes.
  330. *
  331. * @param attributes the attributes to attach to the event.
  332. */
  333. export const createTrackStreamingStatusEvent = ( attributes: object = {} ) => ( {
  334. type: AnalyticsEvents.TYPE_OPERATIONAL,
  335. source: 'track.streaming.status',
  336. action: 'duration',
  337. attributes
  338. } );
  339. /**
  340. * Creates an event for a Jingle-related event.
  341. * @param action the action of the event
  342. * @param attributes attributes to add to the event.
  343. */
  344. export const createJingleEvent = ( action: unknown, attributes: object = {} ) => ( {
  345. type: AnalyticsEvents.TYPE_OPERATIONAL,
  346. action,
  347. source: 'jingle',
  348. attributes
  349. } );
  350. /**
  351. * Creates an event which indicates that a local track was not able to read
  352. * data from its source (a camera or a microphone).
  353. *
  354. * @param mediaType the media type of the local track ('audio' or
  355. * 'video').
  356. */
  357. export const createNoDataFromSourceEvent = ( mediaType: 'audio' | 'video' | string, value: unknown ) => ( {
  358. attributes: {
  359. 'media_type': mediaType,
  360. value
  361. },
  362. action: 'track.no.data.from.source',
  363. type: AnalyticsEvents.TYPE_OPERATIONAL
  364. } );
  365. /**
  366. * Creates an event for a p2p-related event.
  367. * @param action the action of the event
  368. * @param attributes attributes to add to the event.
  369. */
  370. export const createP2PEvent = ( action: unknown, attributes: object = {} ) => ( {
  371. type: AnalyticsEvents.TYPE_OPERATIONAL,
  372. action,
  373. source: 'p2p',
  374. attributes
  375. } )
  376. /**
  377. * Indicates that we received a remote command to mute.
  378. */
  379. export const createRemotelyMutedEvent = ( mediaType: unknown ) => ( {
  380. type: AnalyticsEvents.TYPE_OPERATIONAL,
  381. action: 'remotely.muted',
  382. mediaType
  383. } );
  384. /**
  385. * Creates an event which contains RTP statistics such as RTT and packet loss.
  386. *
  387. * All average RTP stats are currently reported under 1 event name, but with
  388. * different properties that allows to distinguish between a P2P call, a
  389. * call relayed through TURN or the JVB, and multiparty vs 1:1.
  390. *
  391. * The structure of the event is:
  392. *
  393. * {
  394. * p2p: true,
  395. * conferenceSize: 2,
  396. * localCandidateType: "relay",
  397. * remoteCandidateType: "relay",
  398. * transportType: "udp",
  399. *
  400. * // Average RTT of 200ms
  401. * "rtt.avg": 200,
  402. * "rtt.samples": "[100, 200, 300]",
  403. *
  404. * // Average packet loss of 10%
  405. * "packet.loss.avg": 10,
  406. * "packet.loss.samples": '[5, 10, 15]'
  407. *
  408. * // Difference in milliseconds in the end-to-end RTT between p2p and jvb.
  409. * // The e2e RTT through jvb is 15ms shorter:
  410. * "rtt.diff": 15,
  411. *
  412. * // End-to-end RTT through JVB is ms.
  413. * "end2end.rtt.avg" = 100
  414. * }
  415. *
  416. * Note that the value of the "samples" properties are (JSON encoded) strings,
  417. * and not JSON arrays, as events' attributes can not be nested. The samples are
  418. * currently included for debug purposes only and can be removed anytime soon
  419. * from the structure.
  420. *
  421. * Also note that not all of values are present in each event, as values are
  422. * obtained and calculated as part of different process/event pipe. For example
  423. * {@link ConnectionAvgStats} instances are doing the reports for each
  424. * {@link TraceablePeerConnection} and work independently from the main stats
  425. * pipe.
  426. */
  427. export const createRtpStatsEvent = ( attributes: object ) => ( {
  428. type: AnalyticsEvents.TYPE_OPERATIONAL,
  429. action: 'rtp.stats',
  430. attributes
  431. } );
  432. /**
  433. * Creates an event which contains the round trip time (RTT) to a set of
  434. * regions.
  435. *
  436. * @param attributes
  437. */
  438. export const createRttByRegionEvent = ( attributes: object ) => ( {
  439. type: AnalyticsEvents.TYPE_OPERATIONAL,
  440. action: 'rtt.by.region',
  441. attributes
  442. } );
  443. /**
  444. * Creates an event which contains the local and remote ICE candidate types
  445. * for the transport that is currently selected.
  446. *
  447. * @param attributes
  448. */
  449. export const createTransportStatsEvent = ( attributes: object ) => ( {
  450. type: AnalyticsEvents.TYPE_OPERATIONAL,
  451. action: 'transport.stats',
  452. attributes
  453. } );
  454. /**
  455. * Creates an event which contains information about the audio output problem (the user id of the affected participant,
  456. * the local audio levels and the remote audio levels that triggered the event).
  457. *
  458. * @param userID - The user id of the affected participant.
  459. * @param localAudioLevels - The local audio levels.
  460. * @param remoteAudioLevels - The audio levels received from the participant.
  461. */
  462. export const createAudioOutputProblemEvent = ( userID: string, localAudioLevels: unknown, remoteAudioLevels: unknown ) => ( {
  463. type: AnalyticsEvents.TYPE_OPERATIONAL,
  464. action: 'audio.output.problem',
  465. attributes: {
  466. userID,
  467. localAudioLevels,
  468. remoteAudioLevels
  469. }
  470. } );
  471. /**
  472. * Creates an event which contains an information related to the bridge channel close event.
  473. *
  474. * @param code - A code from {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
  475. * @param reason - A string which describes the reason for closing the bridge channel.
  476. */
  477. export const createBridgeChannelClosedEvent = ( code: string, reason: string ) => ( {
  478. type: AnalyticsEvents.TYPE_OPERATIONAL,
  479. action: 'bridge-channel.error',
  480. attributes: {
  481. code,
  482. reason
  483. }
  484. } );
  485. /**
  486. * Creates an event which indicates the Time To First Media (TTFM).
  487. * It is measured in milliseconds relative to the beginning of the document's
  488. * lifetime (i.e. the origin used by window.performance.now()), and it excludes
  489. * the following:
  490. * 1. The delay due to getUserMedia()
  491. * 2. The period between the MUC being joined and the reception of the Jingle
  492. * session-initiate from jicofo. This is because jicofo will not start a Jingle
  493. * session until there are at least 2 participants in the room.
  494. *
  495. * @param attributes the attributes to add to the event. Currently used fields:
  496. * mediaType: the media type of the local track ('audio' or 'video').
  497. * muted: whether the track has ever been muted (?)
  498. * value: the TTMF in milliseconds.
  499. */
  500. export const createTtfmEvent = ( attributes: object ) => createConnectionStageReachedEvent( 'ttfm', attributes );