瀏覽代碼

feat: Makes the google analytics tracking id configurable.

master
Boris Grozev 7 年之前
父節點
當前提交
03fc711e81
共有 3 個文件被更改,包括 16 次插入4 次删除
  1. 10
    3
      analytics-ga.js
  2. 3
    0
      config.js
  3. 3
    1
      react/features/analytics/functions.js

+ 10
- 3
analytics-ga.js 查看文件

@@ -4,16 +4,23 @@
4 4
     /**
5 5
      *
6 6
      */
7
-    function Analytics() {
7
+    function Analytics(options) {
8 8
         /* eslint-disable */
9 9
 
10
+        if (!options.googleAnalyticsTrackingId) {
11
+            console.log(
12
+                'Failed to initialize Google Analytics handler, no tracking ID');
13
+             return;
14
+        }
15
+
10 16
         /**
11 17
          * Google Analytics
18
+         * TODO: Keep this local, there's no need to add it to window.
12 19
          */
13 20
         (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
14 21
             (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
15 22
         })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
16
-        ga('create', 'UA-319188-14', 'jit.si');
23
+        ga('create', options.googleAnalyticsTrackingId, 'jit.si');
17 24
         ga('send', 'pageview');
18 25
 
19 26
         /* eslint-enable */
@@ -114,7 +121,7 @@
114 121
      * lib-jitsi-meet.
115 122
      */
116 123
     Analytics.prototype.sendEvent = function(event) {
117
-        if (!event) {
124
+        if (!event || !ga) {
118 125
             return;
119 126
         }
120 127
 

+ 3
- 0
config.js 查看文件

@@ -313,6 +313,9 @@ var config = {
313 313
     //      "https://example.com/my-custom-analytics.js"
314 314
     // ],
315 315
 
316
+    // The Google Analytics Tracking ID
317
+    // googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1',
318
+
316 319
     // Information about the jitsi-meet instance we are connecting to, including
317 320
     // the user region as seen by the server.
318 321
     deploymentInfo: {

+ 3
- 1
react/features/analytics/functions.js 查看文件

@@ -43,10 +43,12 @@ export function initAnalytics({ getState }: { getState: Function }) {
43 43
 
44 44
     const state = getState();
45 45
     const config = state['features/base/config'];
46
-    const { analyticsScriptUrls, deploymentInfo } = config;
46
+    const { analyticsScriptUrls, deploymentInfo, googleAnalyticsTrackingId }
47
+        = config;
47 48
     const { group, server, user } = state['features/base/jwt'];
48 49
     const handlerConstructorOptions = {
49 50
         envType: (deploymentInfo && deploymentInfo.envType) || 'dev',
51
+        googleAnalyticsTrackingId,
50 52
         group,
51 53
         product: deploymentInfo && deploymentInfo.product,
52 54
         subproduct: deploymentInfo && deploymentInfo.environment,

Loading…
取消
儲存