Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref(config): Create 'analytics' section.

Hristo Terezov5ad98dd05861
diff --git a/config.js b/config.js
index bf5d33f84a..db70da9b96 100644
--- a/config.js
+++ b/config.js
@@ -334,14 +334,19 @@ var config = {
// backToP2PDelay: 5
},
- // A list of scripts to load as lib-jitsi-meet "analytics handlers".
- // analyticsScriptUrls: [
- // "libs/analytics-ga.js", // google-analytics
- // "https://example.com/my-custom-analytics.js"
- // ],
-
- // The Google Analytics Tracking ID
- // googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1',
+ analytics: {
+ // The Google Analytics Tracking ID:
+ // googleAnalyticsTrackingId: 'your-tracking-id-UA-123456-1'
+
+ // The Amplitude APP Key:
+ // amplitudeAPPKey: '<APP_KEY>'
+
+ // Array of script URLs to load as lib-jitsi-meet "analytics handlers".
+ // scriptURLs: [
+ // "libs/analytics-ga.min.js", // google-analytics
+ // "https://example.com/my-custom-analytics.js"
+ // ],
+ },
// Information about the jitsi-meet instance we are connecting to, including
// the user region as seen by the server.
diff --git a/react/features/analytics/functions.js b/react/features/analytics/functions.js
index 040fc0f694..ab986fbb53 100644
--- a/react/features/analytics/functions.js
+++ b/react/features/analytics/functions.js
@@ -43,12 +43,15 @@ export function initAnalytics({ getState }: { getState: Function }) {
const state = getState();
const config = state['features/base/config'];
+ const {
+ analytics: analyticsConfig = {},
+ deploymentInfo
+ } = config;
const {
amplitudeAPPKey,
- analyticsScriptUrls,
- deploymentInfo,
+ scriptURLs,
googleAnalyticsTrackingId
- } = config;
+ } = analyticsConfig;
const { group, server, user } = state['features/base/jwt'];
const handlerConstructorOptions = {
amplitudeAPPKey,
@@ -61,7 +64,7 @@ export function initAnalytics({ getState }: { getState: Function }) {
version: JitsiMeetJS.version
};
- _loadHandlers(analyticsScriptUrls, handlerConstructorOptions)
+ _loadHandlers(scriptURLs, handlerConstructorOptions)
.then(handlers => {
const roomName = state['features/base/conference'].room;
const permanentProperties = {};
diff --git a/react/features/analytics/handlers/AbstractHandler.js b/react/features/analytics/handlers/AbstractHandler.js
index 6dcf5f790b..cc7c720d8a 100644
--- a/react/features/analytics/handlers/AbstractHandler.js
+++ b/react/features/analytics/handlers/AbstractHandler.js
@@ -7,6 +7,9 @@ export default class AbstractHandler {
*/
constructor() {
this._enabled = false;
+ this._ignoredEvents
+ = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
+ 'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
}
/**
@@ -57,11 +60,7 @@ export default class AbstractHandler {
return true;
}
- const ignoredEvents
- = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
- 'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
-
// Temporary removing some of the events that are too noisy.
- return ignoredEvents.indexOf(event.action) !== -1;
+ return this._ignoredEvents.indexOf(event.action) !== -1;
}
}
diff --git a/react/features/analytics/handlers/AmplitudeHandler.js b/react/features/analytics/handlers/AmplitudeHandler.js
index 9391f55a62..cb2b4748e1 100644
--- a/react/features/analytics/handlers/AmplitudeHandler.js
+++ b/react/features/analytics/handlers/AmplitudeHandler.js
@@ -37,12 +37,12 @@ class AmplitudeHandler extends AbstractHandler {
/**
* Sets the Amplitude user properties.
*
- * @param {Object} props - The user portperties.
+ * @param {Object} userProps - The user portperties.
* @returns {void}
*/
- setUserProperties(props) {
+ setUserProperties(userProps) {
if (this._enabled) {
- amplitude.getInstance().setUserProperties(props);
+ amplitude.getInstance().setUserProperties(userProps);
}
}
diff --git a/react/features/analytics/handlers/GoogleAnalyticsHandler.js b/react/features/analytics/handlers/GoogleAnalyticsHandler.js
index 083489eb1e..37e86ffe27 100644
--- a/react/features/analytics/handlers/GoogleAnalyticsHandler.js
+++ b/react/features/analytics/handlers/GoogleAnalyticsHandler.js
@@ -97,10 +97,10 @@ class GoogleAnalyticsHandler extends AbstractHandler {
/**
* Sets the permanent properties for the current session.
*
- * @param {Object} props - The permanent portperties.
+ * @param {Object} userProps - The permanent portperties.
* @returns {void}
*/
- setUserProperties(props = {}) {
+ setUserProperties(userProps = {}) {
if (!this._enabled) {
return;
}
@@ -111,9 +111,9 @@ class GoogleAnalyticsHandler extends AbstractHandler {
const filter = [ 'user_agent', 'callstats_name' ];
this._userPropertiesString
- = Object.keys(props)
+ = Object.keys(userProps)
.filter(key => filter.indexOf(key) === -1)
- .map(key => `permanent_${key}=${props[key]}`)
+ .map(key => `permanent_${key}=${userProps[key]}`)
.join('&');
}
diff --git a/react/features/base/config/reducer.js b/react/features/base/config/reducer.js
index a586927d95..d15ae387b6 100644
--- a/react/features/base/config/reducer.js
+++ b/react/features/base/config/reducer.js
@@ -157,43 +157,45 @@ function _translateLegacyConfig(oldValue: Object) {
let newValue = oldValue;
- // At the time of this writing lib-jitsi-meet will rely on config having a
- // property with the name p2p and with a value of type Object.
- if (typeof oldValue.p2p !== 'object') {
- newValue = set(newValue, 'p2p', {});
- }
-
- /* eslint-disable indent */
+ const oldConfigToNewConfig = {
+ p2p: [
+ [ 'backToP2PDelay', 'backToP2PDelay' ],
+ [ 'enableP2P', 'enabled' ],
+ [ 'p2pStunServers', 'stunServers' ]
+ ],
+ analytics: [
+ [ 'analyticsScriptUrls', 'scriptURLs' ],
+ [ 'googleAnalyticsTrackingId', 'googleAnalyticsTrackingId' ]
+ ]
+ };
// Translate the old config properties into the new config.p2p properties.
- for (const [ oldKey, newKey ]
- of [
- [ 'backToP2PDelay', 'backToP2PDelay' ],
- [ 'enableP2P', 'enabled' ],
- [ 'p2pStunServers', 'stunServers' ]
- ]) {
-
- /* eslint-enable indent */
-
- if (oldKey in newValue && !(newKey in newValue.p2p)) {
- const v = newValue[oldKey];
-
- // Do not modify oldValue.
- if (newValue === oldValue) {
- newValue = {
- ...newValue
+ Object.keys(oldConfigToNewConfig).forEach(section => {
+ if (typeof oldValue[section] !== 'object') {
+ newValue = set(newValue, section, {});
+ }
+
+ for (const [ oldKey, newKey ] of oldConfigToNewConfig[section]) {
+ if (oldKey in newValue && !(newKey in newValue[section])) {
+ const v = newValue[oldKey];
+
+ // Do not modify oldValue.
+ if (newValue === oldValue) {
+ newValue = {
+ ...newValue
+ };
+ }
+ delete newValue[oldKey];
+
+ // Do not modify the section because it may be from oldValue
+ // i.e. do not modify oldValue.
+ newValue[section] = {
+ ...newValue[section],
+ [newKey]: v
};
}
- delete newValue[oldKey];
-
- // Do not modify p2p because it may be from oldValue i.e. do not
- // modify oldValue.
- newValue.p2p = {
- ...newValue.p2p,
- [newKey]: v
- };
}
- }
+ });
return newValue;
}
diff --git a/react/features/base/lib-jitsi-meet/functions.js b/react/features/base/lib-jitsi-meet/functions.js
index d00e76bc27..cd832696e9 100644
--- a/react/features/base/lib-jitsi-meet/functions.js
+++ b/react/features/base/lib-jitsi-meet/functions.js
@@ -44,14 +44,15 @@ export function createLocalTrack(type: string, deviceId: string) {
*/
export function isAnalyticsEnabled(stateful: Function | Object) {
const {
- analyticsScriptUrls,
+ analytics = {},
disableThirdPartyRequests
} = toState(stateful)['features/base/config'];
+ const { scriptURLs } = analytics;
return (
!disableThirdPartyRequests
- && Array.isArray(analyticsScriptUrls)
- && Boolean(analyticsScriptUrls.length));
+ && Array.isArray(scriptURLs)
+ && Boolean(scriptURLs.length));
}
/**