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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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();
  16. const { amplitudeAPPKey, host } = 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. }
  26. /**
  27. * Sets the Amplitude user properties.
  28. *
  29. * @param {Object} userProps - The user portperties.
  30. * @returns {void}
  31. */
  32. setUserProperties(userProps) {
  33. if (this._enabled) {
  34. amplitude.getInstance(this._amplitudeOptions)
  35. .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(this._amplitudeOptions).logEvent(
  51. this._extractName(event),
  52. event);
  53. }
  54. }