69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
import AbstractHandler from './AbstractHandler';
|
|
import { amplitude } from './amplitude';
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
/**
|
|
* Analytics handler for Amplitude.
|
|
*/
|
|
export default class AmplitudeHandler extends AbstractHandler {
|
|
/**
|
|
* Creates new instance of the Amplitude analytics handler.
|
|
*
|
|
* @param {Object} options -
|
|
* @param {string} options.amplitudeAPPKey - The Amplitude app key required
|
|
* by the Amplitude API.
|
|
*/
|
|
constructor(options) {
|
|
super();
|
|
|
|
const { amplitudeAPPKey, host } = options;
|
|
|
|
if (!amplitudeAPPKey) {
|
|
logger.warn(
|
|
'Failed to initialize Amplitude handler, no APP key');
|
|
|
|
return;
|
|
}
|
|
|
|
this._enabled = true;
|
|
|
|
this._amplitudeOptions = {
|
|
host
|
|
};
|
|
|
|
amplitude.getInstance(this._amplitudeOptions).init(amplitudeAPPKey);
|
|
}
|
|
|
|
/**
|
|
* Sets the Amplitude user properties.
|
|
*
|
|
* @param {Object} userProps - The user portperties.
|
|
* @returns {void}
|
|
*/
|
|
setUserProperties(userProps) {
|
|
if (this._enabled) {
|
|
amplitude.getInstance(this._amplitudeOptions)
|
|
.setUserProperties(userProps);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sends an event to Amplitude. The format of the event is described
|
|
* in AnalyticsAdapter in lib-jitsi-meet.
|
|
*
|
|
* @param {Object} event - The event in the format specified by
|
|
* lib-jitsi-meet.
|
|
* @returns {void}
|
|
*/
|
|
sendEvent(event) {
|
|
if (this._shouldIgnore(event)) {
|
|
return;
|
|
}
|
|
|
|
amplitude.getInstance(this._amplitudeOptions).logEvent(
|
|
this._extractName(event),
|
|
event);
|
|
}
|
|
}
|