瀏覽代碼

ref(config): Create 'analytics' section.

master
Hristo Terezov 6 年之前
父節點
當前提交
5ad98dd058

+ 13
- 8
config.js 查看文件

334
         // backToP2PDelay: 5
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
     // Information about the jitsi-meet instance we are connecting to, including
351
     // Information about the jitsi-meet instance we are connecting to, including
347
     // the user region as seen by the server.
352
     // the user region as seen by the server.

+ 7
- 4
react/features/analytics/functions.js 查看文件

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

+ 4
- 5
react/features/analytics/handlers/AbstractHandler.js 查看文件

7
      */
7
      */
8
     constructor() {
8
     constructor() {
9
         this._enabled = false;
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
             return true;
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
         // Temporary removing some of the events that are too noisy.
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 查看文件

37
     /**
37
     /**
38
      * Sets the Amplitude user properties.
38
      * Sets the Amplitude user properties.
39
      *
39
      *
40
-     * @param {Object} props - The user portperties.
40
+     * @param {Object} userProps - The user portperties.
41
      * @returns {void}
41
      * @returns {void}
42
      */
42
      */
43
-    setUserProperties(props) {
43
+    setUserProperties(userProps) {
44
         if (this._enabled) {
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 查看文件

97
     /**
97
     /**
98
      * Sets the permanent properties for the current session.
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
      * @returns {void}
101
      * @returns {void}
102
      */
102
      */
103
-    setUserProperties(props = {}) {
103
+    setUserProperties(userProps = {}) {
104
         if (!this._enabled) {
104
         if (!this._enabled) {
105
             return;
105
             return;
106
         }
106
         }
111
         const filter = [ 'user_agent', 'callstats_name' ];
111
         const filter = [ 'user_agent', 'callstats_name' ];
112
 
112
 
113
         this._userPropertiesString
113
         this._userPropertiesString
114
-            = Object.keys(props)
114
+            = Object.keys(userProps)
115
                 .filter(key => filter.indexOf(key) === -1)
115
                 .filter(key => filter.indexOf(key) === -1)
116
-                .map(key => `permanent_${key}=${props[key]}`)
116
+                .map(key => `permanent_${key}=${userProps[key]}`)
117
                 .join('&');
117
                 .join('&');
118
     }
118
     }
119
 
119
 

+ 34
- 32
react/features/base/config/reducer.js 查看文件

157
 
157
 
158
     let newValue = oldValue;
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
     // Translate the old config properties into the new config.p2p properties.
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
     return newValue;
200
     return newValue;
199
 }
201
 }

+ 4
- 3
react/features/base/lib-jitsi-meet/functions.js 查看文件

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

Loading…
取消
儲存