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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import AbstractHandler from './AbstractHandler';
  2. import { amplitude, fixDeviceID } 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, undefined, { includeReferrer: true });
  25. fixDeviceID(amplitude.getInstance(this._amplitudeOptions));
  26. if (user) {
  27. amplitude.getInstance(this._amplitudeOptions).setUserId(user);
  28. }
  29. }
  30. /**
  31. * Sets the Amplitude user properties.
  32. *
  33. * @param {Object} userProps - The user portperties.
  34. * @returns {void}
  35. */
  36. setUserProperties(userProps) {
  37. if (this._enabled) {
  38. amplitude.getInstance(this._amplitudeOptions)
  39. .setUserProperties(userProps);
  40. }
  41. }
  42. /**
  43. * Sends an event to Amplitude. The format of the event is described
  44. * in AnalyticsAdapter in lib-jitsi-meet.
  45. *
  46. * @param {Object} event - The event in the format specified by
  47. * lib-jitsi-meet.
  48. * @returns {void}
  49. */
  50. sendEvent(event) {
  51. if (this._shouldIgnore(event)) {
  52. return;
  53. }
  54. amplitude.getInstance(this._amplitudeOptions).logEvent(
  55. this._extractName(event),
  56. event);
  57. }
  58. }