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
},
// 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"
// ],
analytics: {
// The Google Analytics Tracking ID:
// googleAnalyticsTrackingId: 'your-tracking-id-UA-123456-1'
// The Google Analytics Tracking ID
// googleAnalyticsTrackingId = 'your-tracking-id-here-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.

View File

@ -44,11 +44,14 @@ export function initAnalytics({ getState }: { getState: Function }) {
const state = getState();
const config = state['features/base/config'];
const {
amplitudeAPPKey,
analyticsScriptUrls,
deploymentInfo,
googleAnalyticsTrackingId
analytics: analyticsConfig = {},
deploymentInfo
} = config;
const {
amplitudeAPPKey,
scriptURLs,
googleAnalyticsTrackingId
} = 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 = {};

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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('&');
}

View File

@ -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' ]
]) {
Object.keys(oldConfigToNewConfig).forEach(section => {
if (typeof oldValue[section] !== 'object') {
newValue = set(newValue, section, {});
}
/* 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)) {
const v = newValue[oldKey];
// Do not modify oldValue.
if (newValue === oldValue) {
newValue = {
...newValue
};
}
delete newValue[oldKey];
// Do not modify oldValue.
if (newValue === oldValue) {
newValue = {
...newValue
// 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;
}

View File

@ -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));
}
/**