Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(amplitude) adjust to new SDK API changes
Saúl Ibarra Corretgéa4367567ab5d
diff --git a/config.js b/config.jsindex 7bbead8f7a..23f7df66a3 100644--- a/config.js+++ b/config.js@@ -1131,10 +1131,6 @@ var config = {// The Amplitude APP Key:// amplitudeAPPKey: '<APP_KEY>',- // Enables Amplitude UTM tracking:- // Default value is false.- // amplitudeIncludeUTM: false,-// Obfuscates room name sent to analytics (amplitude, rtcstats)// Default value is false.// obfuscateRoomName: false,diff --git a/react/features/analytics/functions.ts b/react/features/analytics/functions.tsindex 510e510b9b..6a8ee6df9c 100644--- a/react/features/analytics/functions.ts+++ b/react/features/analytics/functions.ts@@ -84,7 +84,6 @@ export async function createHandlers({ getState }: IStore) {} = config;const {amplitudeAPPKey,- amplitudeIncludeUTM,blackListedEvents,scriptURLs,matomoEndpoint,@@ -94,7 +93,6 @@ export async function createHandlers({ getState }: IStore) {const { group, user } = state['features/base/jwt'];const handlerConstructorOptions = {amplitudeAPPKey,- amplitudeIncludeUTM,blackListedEvents,envType: deploymentInfo?.envType || 'dev',matomoEndpoint,diff --git a/react/features/analytics/handlers/AbstractHandler.ts b/react/features/analytics/handlers/AbstractHandler.tsindex fb1ca7bfb1..4d156cee3f 100644--- a/react/features/analytics/handlers/AbstractHandler.ts+++ b/react/features/analytics/handlers/AbstractHandler.ts@@ -11,7 +11,6 @@ export interface IEvent {interface IOptions {amplitudeAPPKey?: string;- amplitudeIncludeUTM?: boolean;blackListedEvents?: string[];envType?: string;group?: string;diff --git a/react/features/analytics/handlers/AmplitudeHandler.ts b/react/features/analytics/handlers/AmplitudeHandler.tsindex 30bd93538d..04d3c1ef41 100644--- a/react/features/analytics/handlers/AmplitudeHandler.ts+++ b/react/features/analytics/handlers/AmplitudeHandler.ts@@ -4,7 +4,7 @@ import logger from '../logger';import AbstractHandler, { IEvent } from './AbstractHandler';import { fixDeviceID } from './amplitude/fixDeviceID';-import amplitude from './amplitude/lib';+import amplitude, { initAmplitude } from './amplitude/lib';/*** Analytics handler for Amplitude.@@ -15,8 +15,7 @@ export default class AmplitudeHandler extends AbstractHandler {* Creates new instance of the Amplitude analytics handler.** @param {Object} options - The amplitude options.- * @param {string} options.amplitudeAPPKey - The Amplitude app key required by the Amplitude API.- * @param {boolean} options.amplitudeIncludeUTM - Whether to include UTM parameters+ * @param {string} options.amplitudeAPPKey - The Amplitude app key required by the Amplitude API* in the Amplitude events.*/constructor(options: any) {@@ -24,47 +23,26 @@ export default class AmplitudeHandler extends AbstractHandler {const {amplitudeAPPKey,- amplitudeIncludeUTM: includeUtm = true,user} = options;this._enabled = true;- const onError = (e: Error) => {- logger.error('Error initializing Amplitude', e);- this._enabled = false;- };-- // Forces sending all events on exit (flushing) via sendBeacon- const onExitPage = () => {- amplitude.flush();- };-- if (navigator.product === 'ReactNative') {- amplitude.init(amplitudeAPPKey);- fixDeviceID(amplitude);- } else {- const amplitudeOptions: any = {- includeReferrer: true,- includeUtm,- saveParamsReferrerOncePerSession: false,- onError,- onExitPage- };-- amplitude.init(amplitudeAPPKey, undefined, amplitudeOptions);- fixDeviceID(amplitude);- }-- if (user) {- amplitude.setUserId(user);- }+ initAmplitude(amplitudeAPPKey, user)+ .then(() => {+ logger.info('Amplitude initialized');+ fixDeviceID(amplitude);+ })+ .catch(e => {+ logger.error('Error initializing Amplitude', e);+ this._enabled = false;+ });}/*** Sets the Amplitude user properties.*- * @param {Object} userProps - The user portperties.+ * @param {Object} userProps - The user properties.* @returns {void}*/setUserProperties(userProps: any) {@@ -95,7 +73,7 @@ export default class AmplitudeHandler extends AbstractHandler {const eventName = this._extractName(event) ?? '';- amplitude.logEvent(eventName, event);+ amplitude.track(eventName, event);}/**diff --git a/react/features/analytics/handlers/amplitude/lib.native.ts b/react/features/analytics/handlers/amplitude/lib.native.tsindex 7fbc50bbcf..8c4b1167ac 100644--- a/react/features/analytics/handlers/amplitude/lib.native.ts+++ b/react/features/analytics/handlers/amplitude/lib.native.ts@@ -1,3 +1,15 @@-import { createInstance } from '@amplitude/analytics-react-native';+import amplitude from '@amplitude/analytics-react-native';-export default createInstance();+export default amplitude;++/**+ * Initializes the Amplitude instance.+ *+ * @param {string} amplitudeAPPKey - The Amplitude app key.+ * @param {string | undefined} user - The user ID.+ * @returns {Promise} The initialized Amplitude instance.+ */+export function initAmplitude(+ amplitudeAPPKey: string, user: string | undefined): Promise<unknown> {+ return amplitude.init(amplitudeAPPKey, user, {}).promise;+}diff --git a/react/features/analytics/handlers/amplitude/lib.web.ts b/react/features/analytics/handlers/amplitude/lib.web.tsindex 2e1c3e8102..704339d37b 100644--- a/react/features/analytics/handlers/amplitude/lib.web.ts+++ b/react/features/analytics/handlers/amplitude/lib.web.ts@@ -1,3 +1,38 @@import { createInstance } from '@amplitude/analytics-browser';-export default createInstance();+const amplitude = createInstance();++export default amplitude;++/**+ * Initializes the Amplitude instance.+ *+ * @param {string} amplitudeAPPKey - The Amplitude app key.+ * @param {string | undefined} user - The user ID.+ * @returns {Promise} The initialized Amplitude instance.+ */+export function initAmplitude(+ amplitudeAPPKey: string, user: string | undefined): Promise<unknown> {++ // Forces sending all events on exit (flushing) via sendBeacon.+ window.addEventListener('pagehide', () => {+ // Set https transport to use sendBeacon API.+ amplitude.setTransport('beacon');+ // Send all pending events to server.+ amplitude.flush();+ });++ const options = {+ autocapture: {+ attribution: true,+ pageViews: true,+ sessions: false,+ fileDownloads: false,+ formInteractions: false,+ elementInteractions: false+ },+ defaultTracking: false+ };++ return amplitude.init(amplitudeAPPKey, user, options).promise;+}diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex 5bc960cd0c..c1c19692a4 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -172,7 +172,6 @@ export interface IConfig {_screenshotHistoryRegionUrl?: number;analytics?: {amplitudeAPPKey?: string;- amplitudeIncludeUTM?: boolean;blackListedEvents?: string[];disabled?: boolean;matomoEndpoint?: string;