Переглянути джерело

feat(analytics): Add analytics permanent properties and use new paramenters format

j8
hristoterezov 8 роки тому
джерело
коміт
6e4a710df6
4 змінених файлів з 47 додано та 16 видалено
  1. 5
    7
      analytics.js
  2. 0
    5
      app.js
  3. 41
    4
      conference.js
  4. 1
    0
      modules/TokenData/TokenData.js

+ 5
- 7
analytics.js Переглянути файл

@@ -16,17 +16,15 @@
16 16
     /* eslint-enable */
17 17
   }
18 18
 
19
-  Analytics.prototype.sendEvent = function (action, data, label, browserName) {
19
+  Analytics.prototype.sendEvent = function (action, data) {
20 20
     // empty label if missing value for it and add the value,
21 21
     // the value should be integer or null
22
-    var value = Math.round(parseFloat(data));
22
+    var value = data.value;
23
+    value = value? Math.round(parseFloat(value)) : null;
24
+    var label = data.label || "";
23 25
 
24 26
     ga('send', 'event', 'jit.si',
25
-        action + '.' + browserName, label ? label : "", value ? value : null);
26
-  };
27
-
28
-  Analytics.prototype.sendFeedback = function (data, label, browserName) {
29
-      this.sendEvent('feedback.rating', data.overall, label, browserName);
27
+        action + '.' + data.browserName, label, value);
30 28
   };
31 29
 
32 30
   ctx.Analytics = Analytics;

+ 0
- 5
app.js Переглянути файл

@@ -110,11 +110,6 @@ function init() {
110 110
     var isUIReady = APP.UI.start();
111 111
     if (isUIReady) {
112 112
         APP.conference.init({roomName: buildRoomName()}).then(function () {
113
-            let server = APP.tokenData.server;
114
-            if(server) {
115
-                APP.conference.logEvent("server." + server, 1);
116
-            }
117
-
118 113
             APP.UI.initConference();
119 114
 
120 115
             APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {

+ 41
- 4
conference.js Переглянути файл

@@ -485,6 +485,39 @@ class ConferenceConnector {
485 485
     }
486 486
 }
487 487
 
488
+/**
489
+ * Sends statistics from APP.tokenData
490
+ */
491
+function sendTokenDataStats() {
492
+    let {server, group} = APP.tokenData;
493
+    if(server) {
494
+        APP.conference.logEvent("server." + server, 1);
495
+    }
496
+    if(group) {
497
+        APP.conference.logEvent("group", group);
498
+    }
499
+}
500
+
501
+/**
502
+ * Set permanent ptoperties to analytics.
503
+ * NOTE: Has to be used after JitsiMeetJS.init. otherwise analytics will be
504
+ * null.
505
+ */
506
+function setAnalyticsPermanentProperties() {
507
+    let permanentProperties = {
508
+        userAgent: navigator.userAgent,
509
+        roomName: APP.conference.roomName
510
+    };
511
+    let {server, group} = APP.tokenData;
512
+    if(server) {
513
+        permanentProperties.server = server;
514
+    }
515
+    if(group) {
516
+        permanentProperties.group = group;
517
+    }
518
+    JitsiMeetJS.analytics.addPermanentProperties(permanentProperties);
519
+}
520
+
488 521
 export default {
489 522
     isModerator: false,
490 523
     audioMuted: false,
@@ -532,8 +565,11 @@ export default {
532 565
         }
533 566
 
534 567
         return JitsiMeetJS.init(config)
535
-            .then(() => createInitialLocalTracksAndConnect(options.roomName))
536
-            .then(([tracks, con]) => {
568
+            .then(() => {
569
+                setAnalyticsPermanentProperties();
570
+                sendTokenDataStats();
571
+                return createInitialLocalTracksAndConnect(options.roomName);
572
+            }).then(([tracks, con]) => {
537 573
                 console.log('initialized with %s local tracks', tracks.length);
538 574
                 APP.connection = connection = con;
539 575
                 this._createRoom(tracks);
@@ -1452,7 +1488,8 @@ export default {
1452 1488
             // Longer delays will be caused by something else and will just
1453 1489
             // poison the data.
1454 1490
             if (delay < 2000) {
1455
-                JitsiMeetJS.analytics.sendEvent('stream.switch.delay', delay);
1491
+                JitsiMeetJS.analytics.sendEvent('stream.switch.delay',
1492
+                    {value: delay});
1456 1493
             }
1457 1494
         });
1458 1495
 
@@ -1764,7 +1801,7 @@ export default {
1764 1801
      */
1765 1802
     logEvent(name, value) {
1766 1803
         if(JitsiMeetJS.analytics) {
1767
-            JitsiMeetJS.analytics.sendEvent(name, value);
1804
+            JitsiMeetJS.analytics.sendEvent(name, {value});
1768 1805
         }
1769 1806
         if(room) {
1770 1807
             room.sendApplicationLog(JSON.stringify({name, value}));

+ 1
- 0
modules/TokenData/TokenData.js Переглянути файл

@@ -99,6 +99,7 @@ class TokenData{
99 99
         if(!this.payload.context)
100 100
             return;
101 101
         this.server = this.payload.context.server;
102
+        this.group = this.payload.context.group;
102 103
         let callerData = this.payload.context.user;
103 104
         let calleeData = this.payload.context.callee;
104 105
         if(callerData)

Завантаження…
Відмінити
Зберегти