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.

AmplitudeHandler.js 1.8KB

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