Procházet zdrojové kódy

ref(config): Create 'analytics' section.

j8
Hristo Terezov před 6 roky
rodič
revize
5ad98dd058

+ 13
- 8
config.js Zobrazit soubor

@@ -334,14 +334,19 @@ var config = {
334 334
         // backToP2PDelay: 5
335 335
     },
336 336
 
337
-    // A list of scripts to load as lib-jitsi-meet "analytics handlers".
338
-    // analyticsScriptUrls: [
339
-    //      "libs/analytics-ga.js", // google-analytics
340
-    //      "https://example.com/my-custom-analytics.js"
341
-    // ],
342
-
343
-    // The Google Analytics Tracking ID
344
-    // googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1',
337
+    analytics: {
338
+        // The Google Analytics Tracking ID:
339
+        // googleAnalyticsTrackingId: 'your-tracking-id-UA-123456-1'
340
+
341
+        // The Amplitude APP Key:
342
+        // amplitudeAPPKey: '<APP_KEY>'
343
+
344
+        // Array of script URLs to load as lib-jitsi-meet "analytics handlers".
345
+        // scriptURLs: [
346
+        //      "libs/analytics-ga.min.js", // google-analytics
347
+        //      "https://example.com/my-custom-analytics.js"
348
+        // ],
349
+    },
345 350
 
346 351
     // Information about the jitsi-meet instance we are connecting to, including
347 352
     // the user region as seen by the server.

+ 7
- 4
react/features/analytics/functions.js Zobrazit soubor

@@ -43,12 +43,15 @@ export function initAnalytics({ getState }: { getState: Function }) {
43 43
 
44 44
     const state = getState();
45 45
     const config = state['features/base/config'];
46
+    const {
47
+        analytics: analyticsConfig = {},
48
+        deploymentInfo
49
+    } = config;
46 50
     const {
47 51
         amplitudeAPPKey,
48
-        analyticsScriptUrls,
49
-        deploymentInfo,
52
+        scriptURLs,
50 53
         googleAnalyticsTrackingId
51
-    } = config;
54
+    } = analyticsConfig;
52 55
     const { group, server, user } = state['features/base/jwt'];
53 56
     const handlerConstructorOptions = {
54 57
         amplitudeAPPKey,
@@ -61,7 +64,7 @@ export function initAnalytics({ getState }: { getState: Function }) {
61 64
         version: JitsiMeetJS.version
62 65
     };
63 66
 
64
-    _loadHandlers(analyticsScriptUrls, handlerConstructorOptions)
67
+    _loadHandlers(scriptURLs, handlerConstructorOptions)
65 68
         .then(handlers => {
66 69
             const roomName = state['features/base/conference'].room;
67 70
             const permanentProperties = {};

+ 4
- 5
react/features/analytics/handlers/AbstractHandler.js Zobrazit soubor

@@ -7,6 +7,9 @@ export default class AbstractHandler {
7 7
      */
8 8
     constructor() {
9 9
         this._enabled = false;
10
+        this._ignoredEvents
11
+            = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
12
+                'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
10 13
     }
11 14
 
12 15
     /**
@@ -57,11 +60,7 @@ export default class AbstractHandler {
57 60
             return true;
58 61
         }
59 62
 
60
-        const ignoredEvents
61
-            = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
62
-                'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
63
-
64 63
         // Temporary removing some of the events that are too noisy.
65
-        return ignoredEvents.indexOf(event.action) !== -1;
64
+        return this._ignoredEvents.indexOf(event.action) !== -1;
66 65
     }
67 66
 }

+ 3
- 3
react/features/analytics/handlers/AmplitudeHandler.js Zobrazit soubor

@@ -37,12 +37,12 @@ class AmplitudeHandler extends AbstractHandler {
37 37
     /**
38 38
      * Sets the Amplitude user properties.
39 39
      *
40
-     * @param {Object} props - The user portperties.
40
+     * @param {Object} userProps - The user portperties.
41 41
      * @returns {void}
42 42
      */
43
-    setUserProperties(props) {
43
+    setUserProperties(userProps) {
44 44
         if (this._enabled) {
45
-            amplitude.getInstance().setUserProperties(props);
45
+            amplitude.getInstance().setUserProperties(userProps);
46 46
         }
47 47
     }
48 48
 

+ 4
- 4
react/features/analytics/handlers/GoogleAnalyticsHandler.js Zobrazit soubor

@@ -97,10 +97,10 @@ class GoogleAnalyticsHandler extends AbstractHandler {
97 97
     /**
98 98
      * Sets the permanent properties for the current session.
99 99
      *
100
-     * @param {Object} props - The permanent portperties.
100
+     * @param {Object} userProps - The permanent portperties.
101 101
      * @returns {void}
102 102
      */
103
-    setUserProperties(props = {}) {
103
+    setUserProperties(userProps = {}) {
104 104
         if (!this._enabled) {
105 105
             return;
106 106
         }
@@ -111,9 +111,9 @@ class GoogleAnalyticsHandler extends AbstractHandler {
111 111
         const filter = [ 'user_agent', 'callstats_name' ];
112 112
 
113 113
         this._userPropertiesString
114
-            = Object.keys(props)
114
+            = Object.keys(userProps)
115 115
                 .filter(key => filter.indexOf(key) === -1)
116
-                .map(key => `permanent_${key}=${props[key]}`)
116
+                .map(key => `permanent_${key}=${userProps[key]}`)
117 117
                 .join('&');
118 118
     }
119 119
 

+ 34
- 32
react/features/base/config/reducer.js Zobrazit soubor

@@ -157,43 +157,45 @@ function _translateLegacyConfig(oldValue: Object) {
157 157
 
158 158
     let newValue = oldValue;
159 159
 
160
-    // At the time of this writing lib-jitsi-meet will rely on config having a
161
-    // property with the name p2p and with a value of type Object.
162
-    if (typeof oldValue.p2p !== 'object') {
163
-        newValue = set(newValue, 'p2p', {});
164
-    }
165
-
166
-    /* eslint-disable indent */
160
+    const oldConfigToNewConfig = {
161
+        p2p: [
162
+            [ 'backToP2PDelay', 'backToP2PDelay' ],
163
+            [ 'enableP2P', 'enabled' ],
164
+            [ 'p2pStunServers', 'stunServers' ]
165
+        ],
166
+        analytics: [
167
+            [ 'analyticsScriptUrls', 'scriptURLs' ],
168
+            [ 'googleAnalyticsTrackingId', 'googleAnalyticsTrackingId' ]
169
+        ]
170
+    };
167 171
 
168 172
     // Translate the old config properties into the new config.p2p properties.
169
-    for (const [ oldKey, newKey ]
170
-            of [
171
-                [ 'backToP2PDelay', 'backToP2PDelay' ],
172
-                [ 'enableP2P', 'enabled' ],
173
-                [ 'p2pStunServers', 'stunServers' ]
174
-            ]) {
175
-
176
-    /* eslint-enable indent */
177
-
178
-        if (oldKey in newValue && !(newKey in newValue.p2p)) {
179
-            const v = newValue[oldKey];
180
-
181
-            // Do not modify oldValue.
182
-            if (newValue === oldValue) {
183
-                newValue = {
184
-                    ...newValue
173
+    Object.keys(oldConfigToNewConfig).forEach(section => {
174
+        if (typeof oldValue[section] !== 'object') {
175
+            newValue = set(newValue, section, {});
176
+        }
177
+
178
+        for (const [ oldKey, newKey ] of oldConfigToNewConfig[section]) {
179
+            if (oldKey in newValue && !(newKey in newValue[section])) {
180
+                const v = newValue[oldKey];
181
+
182
+                // Do not modify oldValue.
183
+                if (newValue === oldValue) {
184
+                    newValue = {
185
+                        ...newValue
186
+                    };
187
+                }
188
+                delete newValue[oldKey];
189
+
190
+                // Do not modify the section because it may be from oldValue
191
+                // i.e. do not modify oldValue.
192
+                newValue[section] = {
193
+                    ...newValue[section],
194
+                    [newKey]: v
185 195
                 };
186 196
             }
187
-            delete newValue[oldKey];
188
-
189
-            // Do not modify p2p because it may be from oldValue i.e. do not
190
-            // modify oldValue.
191
-            newValue.p2p = {
192
-                ...newValue.p2p,
193
-                [newKey]: v
194
-            };
195 197
         }
196
-    }
198
+    });
197 199
 
198 200
     return newValue;
199 201
 }

+ 4
- 3
react/features/base/lib-jitsi-meet/functions.js Zobrazit soubor

@@ -44,14 +44,15 @@ export function createLocalTrack(type: string, deviceId: string) {
44 44
  */
45 45
 export function isAnalyticsEnabled(stateful: Function | Object) {
46 46
     const {
47
-        analyticsScriptUrls,
47
+        analytics = {},
48 48
         disableThirdPartyRequests
49 49
     } = toState(stateful)['features/base/config'];
50
+    const { scriptURLs } = analytics;
50 51
 
51 52
     return (
52 53
         !disableThirdPartyRequests
53
-            && Array.isArray(analyticsScriptUrls)
54
-            && Boolean(analyticsScriptUrls.length));
54
+            && Array.isArray(scriptURLs)
55
+            && Boolean(scriptURLs.length));
55 56
 }
56 57
 
57 58
 /**

Načítá se…
Zrušit
Uložit