ref(config): Create 'analytics' section.
This commit is contained in:
parent
e5a8d95f1f
commit
5ad98dd058
17
config.js
17
config.js
|
@ -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'
|
||||||
|
|
||||||
|
// 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"
|
// "https://example.com/my-custom-analytics.js"
|
||||||
// ],
|
// ],
|
||||||
|
},
|
||||||
// The Google Analytics Tracking ID
|
|
||||||
// googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1',
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
|
@ -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 = {};
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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('&');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,25 +157,26 @@ 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') {
|
|
||||||
newValue = set(newValue, 'p2p', {});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-disable indent */
|
|
||||||
|
|
||||||
// Translate the old config properties into the new config.p2p properties.
|
|
||||||
for (const [ oldKey, newKey ]
|
|
||||||
of [
|
|
||||||
[ 'backToP2PDelay', 'backToP2PDelay' ],
|
[ 'backToP2PDelay', 'backToP2PDelay' ],
|
||||||
[ 'enableP2P', 'enabled' ],
|
[ 'enableP2P', 'enabled' ],
|
||||||
[ 'p2pStunServers', 'stunServers' ]
|
[ 'p2pStunServers', 'stunServers' ]
|
||||||
]) {
|
],
|
||||||
|
analytics: [
|
||||||
|
[ 'analyticsScriptUrls', 'scriptURLs' ],
|
||||||
|
[ 'googleAnalyticsTrackingId', 'googleAnalyticsTrackingId' ]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
/* eslint-enable indent */
|
// Translate the old config properties into the new config.p2p properties.
|
||||||
|
Object.keys(oldConfigToNewConfig).forEach(section => {
|
||||||
|
if (typeof oldValue[section] !== 'object') {
|
||||||
|
newValue = set(newValue, section, {});
|
||||||
|
}
|
||||||
|
|
||||||
if (oldKey in newValue && !(newKey in newValue.p2p)) {
|
for (const [ oldKey, newKey ] of oldConfigToNewConfig[section]) {
|
||||||
|
if (oldKey in newValue && !(newKey in newValue[section])) {
|
||||||
const v = newValue[oldKey];
|
const v = newValue[oldKey];
|
||||||
|
|
||||||
// Do not modify oldValue.
|
// Do not modify oldValue.
|
||||||
|
@ -186,14 +187,15 @@ function _translateLegacyConfig(oldValue: Object) {
|
||||||
}
|
}
|
||||||
delete newValue[oldKey];
|
delete newValue[oldKey];
|
||||||
|
|
||||||
// Do not modify p2p because it may be from oldValue i.e. do not
|
// Do not modify the section because it may be from oldValue
|
||||||
// modify oldValue.
|
// i.e. do not modify oldValue.
|
||||||
newValue.p2p = {
|
newValue[section] = {
|
||||||
...newValue.p2p,
|
...newValue[section],
|
||||||
[newKey]: v
|
[newKey]: v
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue