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

AmplitudeHandler.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  59. * Return amplitude identity information.
  60. *
  61. * @returns {Object}
  62. */
  63. getIdentityProps() {
  64. return {
  65. sessionId: amplitude.getInstance(this._amplitudeOptions).getSessionId(),
  66. deviceId: amplitude.getInstance(this._amplitudeOptions).options.deviceId,
  67. userId: amplitude.getInstance(this._amplitudeOptions).options.userId
  68. };
  69. }
  70. }