Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AmplitudeHandler.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import AbstractHandler from './AbstractHandler';
  2. import { amplitude } from './amplitude';
  3. const logger = require('jitsi-meet-logger').getLogger(__filename);
  4. /**
  5. * Analytics handler for Amplitude.
  6. */
  7. export default class AmplitudeHandler extends AbstractHandler {
  8. /**
  9. * Creates new instance of the Amplitude analytics handler.
  10. *
  11. * @param {Object} options -
  12. * @param {string} options.amplitudeAPPKey - The Amplitude app key required
  13. * by the Amplitude API.
  14. */
  15. constructor(options) {
  16. super();
  17. const { amplitudeAPPKey, host } = options;
  18. if (!amplitudeAPPKey) {
  19. logger.warn(
  20. 'Failed to initialize Amplitude handler, no APP key');
  21. return;
  22. }
  23. this._enabled = true;
  24. this._amplitudeOptions = {
  25. host
  26. };
  27. amplitude.getInstance(this._amplitudeOptions).init(amplitudeAPPKey);
  28. }
  29. /**
  30. * Sets the Amplitude user properties.
  31. *
  32. * @param {Object} userProps - The user portperties.
  33. * @returns {void}
  34. */
  35. setUserProperties(userProps) {
  36. if (this._enabled) {
  37. amplitude.getInstance(this._amplitudeOptions)
  38. .setUserProperties(userProps);
  39. }
  40. }
  41. /**
  42. * Sends an event to Amplitude. The format of the event is described
  43. * in AnalyticsAdapter in lib-jitsi-meet.
  44. *
  45. * @param {Object} event - The event in the format specified by
  46. * lib-jitsi-meet.
  47. * @returns {void}
  48. */
  49. sendEvent(event) {
  50. if (this._shouldIgnore(event)) {
  51. return;
  52. }
  53. amplitude.getInstance(this._amplitudeOptions).logEvent(
  54. this._extractName(event),
  55. event);
  56. }
  57. }