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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import AbstractHandler from './AbstractHandler';
  2. import { amplitude } from './amplitude';
  3. /**
  4. * Analytics handler for Amplitude.
  5. */
  6. export default class AmplitudeHandler extends AbstractHandler {
  7. /**
  8. * Creates new instance of the Amplitude analytics handler.
  9. *
  10. * @param {Object} options -
  11. * @param {string} options.amplitudeAPPKey - The Amplitude app key required
  12. * by the Amplitude API.
  13. */
  14. constructor(options) {
  15. super(options);
  16. const { amplitudeAPPKey, host, user } = options;
  17. if (!amplitudeAPPKey) {
  18. throw new Error('Failed to initialize Amplitude handler, no APP key');
  19. }
  20. this._enabled = true;
  21. this._amplitudeOptions = {
  22. host
  23. };
  24. amplitude.getInstance(this._amplitudeOptions).init(amplitudeAPPKey);
  25. if (user) {
  26. amplitude.getInstance(this._amplitudeOptions).setUserId(user);
  27. }
  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. }