ref(config): Create 'analytics' section.

This commit is contained in:
Hristo Terezov 2019-01-03 14:48:41 +00:00
parent e5a8d95f1f
commit 5ad98dd058
7 changed files with 66 additions and 56 deletions

View File

@ -334,14 +334,19 @@ var config = {
// backToP2PDelay: 5 // backToP2PDelay: 5
}, },
// A list of scripts to load as lib-jitsi-meet "analytics handlers". analytics: {
// analyticsScriptUrls: [ // The Google Analytics Tracking ID:
// "libs/analytics-ga.js", // google-analytics // googleAnalyticsTrackingId: 'your-tracking-id-UA-123456-1'
// "https://example.com/my-custom-analytics.js"
// ],
// The Google Analytics Tracking ID // The Amplitude APP Key:
// googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1', // 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 // Information about the jitsi-meet instance we are connecting to, including
// the user region as seen by the server. // the user region as seen by the server.

View File

@ -44,11 +44,14 @@ export function initAnalytics({ getState }: { getState: Function }) {
const state = getState(); const state = getState();
const config = state['features/base/config']; const config = state['features/base/config'];
const { const {
amplitudeAPPKey, analytics: analyticsConfig = {},
analyticsScriptUrls, deploymentInfo
deploymentInfo,
googleAnalyticsTrackingId
} = config; } = config;
const {
amplitudeAPPKey,
scriptURLs,
googleAnalyticsTrackingId
} = analyticsConfig;
const { group, server, user } = state['features/base/jwt']; const { group, server, user } = state['features/base/jwt'];
const handlerConstructorOptions = { const handlerConstructorOptions = {
amplitudeAPPKey, amplitudeAPPKey,
@ -61,7 +64,7 @@ export function initAnalytics({ getState }: { getState: Function }) {
version: JitsiMeetJS.version version: JitsiMeetJS.version
}; };
_loadHandlers(analyticsScriptUrls, handlerConstructorOptions) _loadHandlers(scriptURLs, handlerConstructorOptions)
.then(handlers => { .then(handlers => {
const roomName = state['features/base/conference'].room; const roomName = state['features/base/conference'].room;
const permanentProperties = {}; const permanentProperties = {};

View File

@ -7,6 +7,9 @@ export default class AbstractHandler {
*/ */
constructor() { constructor() {
this._enabled = false; 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; 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. // Temporary removing some of the events that are too noisy.
return ignoredEvents.indexOf(event.action) !== -1; return this._ignoredEvents.indexOf(event.action) !== -1;
} }
} }

View File

@ -37,12 +37,12 @@ class AmplitudeHandler extends AbstractHandler {
/** /**
* Sets the Amplitude user properties. * Sets the Amplitude user properties.
* *
* @param {Object} props - The user portperties. * @param {Object} userProps - The user portperties.
* @returns {void} * @returns {void}
*/ */
setUserProperties(props) { setUserProperties(userProps) {
if (this._enabled) { if (this._enabled) {
amplitude.getInstance().setUserProperties(props); amplitude.getInstance().setUserProperties(userProps);
} }
} }

View File

@ -97,10 +97,10 @@ class GoogleAnalyticsHandler extends AbstractHandler {
/** /**
* Sets the permanent properties for the current session. * Sets the permanent properties for the current session.
* *
* @param {Object} props - The permanent portperties. * @param {Object} userProps - The permanent portperties.
* @returns {void} * @returns {void}
*/ */
setUserProperties(props = {}) { setUserProperties(userProps = {}) {
if (!this._enabled) { if (!this._enabled) {
return; return;
} }
@ -111,9 +111,9 @@ class GoogleAnalyticsHandler extends AbstractHandler {
const filter = [ 'user_agent', 'callstats_name' ]; const filter = [ 'user_agent', 'callstats_name' ];
this._userPropertiesString this._userPropertiesString
= Object.keys(props) = Object.keys(userProps)
.filter(key => filter.indexOf(key) === -1) .filter(key => filter.indexOf(key) === -1)
.map(key => `permanent_${key}=${props[key]}`) .map(key => `permanent_${key}=${userProps[key]}`)
.join('&'); .join('&');
} }

View File

@ -157,43 +157,45 @@ function _translateLegacyConfig(oldValue: Object) {
let newValue = oldValue; let newValue = oldValue;
// At the time of this writing lib-jitsi-meet will rely on config having a const oldConfigToNewConfig = {
// property with the name p2p and with a value of type Object. p2p: [
if (typeof oldValue.p2p !== 'object') { [ 'backToP2PDelay', 'backToP2PDelay' ],
newValue = set(newValue, 'p2p', {}); [ 'enableP2P', 'enabled' ],
} [ 'p2pStunServers', 'stunServers' ]
],
/* eslint-disable indent */ analytics: [
[ 'analyticsScriptUrls', 'scriptURLs' ],
[ 'googleAnalyticsTrackingId', 'googleAnalyticsTrackingId' ]
]
};
// Translate the old config properties into the new config.p2p properties. // Translate the old config properties into the new config.p2p properties.
for (const [ oldKey, newKey ] Object.keys(oldConfigToNewConfig).forEach(section => {
of [ if (typeof oldValue[section] !== 'object') {
[ 'backToP2PDelay', 'backToP2PDelay' ], newValue = set(newValue, section, {});
[ 'enableP2P', 'enabled' ], }
[ 'p2pStunServers', 'stunServers' ]
]) {
/* eslint-enable indent */ for (const [ oldKey, newKey ] of oldConfigToNewConfig[section]) {
if (oldKey in newValue && !(newKey in newValue[section])) {
const v = newValue[oldKey];
if (oldKey in newValue && !(newKey in newValue.p2p)) { // Do not modify oldValue.
const v = newValue[oldKey]; if (newValue === oldValue) {
newValue = {
...newValue
};
}
delete newValue[oldKey];
// Do not modify oldValue. // Do not modify the section because it may be from oldValue
if (newValue === oldValue) { // i.e. do not modify oldValue.
newValue = { newValue[section] = {
...newValue ...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; return newValue;
} }

View File

@ -44,14 +44,15 @@ export function createLocalTrack(type: string, deviceId: string) {
*/ */
export function isAnalyticsEnabled(stateful: Function | Object) { export function isAnalyticsEnabled(stateful: Function | Object) {
const { const {
analyticsScriptUrls, analytics = {},
disableThirdPartyRequests disableThirdPartyRequests
} = toState(stateful)['features/base/config']; } = toState(stateful)['features/base/config'];
const { scriptURLs } = analytics;
return ( return (
!disableThirdPartyRequests !disableThirdPartyRequests
&& Array.isArray(analyticsScriptUrls) && Array.isArray(scriptURLs)
&& Boolean(analyticsScriptUrls.length)); && Boolean(scriptURLs.length));
} }
/** /**