Browse Source

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

master
hristoterezov 8 years ago
parent
commit
6e4a710df6
4 changed files with 47 additions and 16 deletions
  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 View File

16
     /* eslint-enable */
16
     /* eslint-enable */
17
   }
17
   }
18
 
18
 
19
-  Analytics.prototype.sendEvent = function (action, data, label, browserName) {
19
+  Analytics.prototype.sendEvent = function (action, data) {
20
     // empty label if missing value for it and add the value,
20
     // empty label if missing value for it and add the value,
21
     // the value should be integer or null
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
     ga('send', 'event', 'jit.si',
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
   ctx.Analytics = Analytics;
30
   ctx.Analytics = Analytics;

+ 0
- 5
app.js View File

110
     var isUIReady = APP.UI.start();
110
     var isUIReady = APP.UI.start();
111
     if (isUIReady) {
111
     if (isUIReady) {
112
         APP.conference.init({roomName: buildRoomName()}).then(function () {
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
             APP.UI.initConference();
113
             APP.UI.initConference();
119
 
114
 
120
             APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
115
             APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {

+ 41
- 4
conference.js View File

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
 export default {
521
 export default {
489
     isModerator: false,
522
     isModerator: false,
490
     audioMuted: false,
523
     audioMuted: false,
532
         }
565
         }
533
 
566
 
534
         return JitsiMeetJS.init(config)
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
                 console.log('initialized with %s local tracks', tracks.length);
573
                 console.log('initialized with %s local tracks', tracks.length);
538
                 APP.connection = connection = con;
574
                 APP.connection = connection = con;
539
                 this._createRoom(tracks);
575
                 this._createRoom(tracks);
1452
             // Longer delays will be caused by something else and will just
1488
             // Longer delays will be caused by something else and will just
1453
             // poison the data.
1489
             // poison the data.
1454
             if (delay < 2000) {
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
      */
1801
      */
1765
     logEvent(name, value) {
1802
     logEvent(name, value) {
1766
         if(JitsiMeetJS.analytics) {
1803
         if(JitsiMeetJS.analytics) {
1767
-            JitsiMeetJS.analytics.sendEvent(name, value);
1804
+            JitsiMeetJS.analytics.sendEvent(name, {value});
1768
         }
1805
         }
1769
         if(room) {
1806
         if(room) {
1770
             room.sendApplicationLog(JSON.stringify({name, value}));
1807
             room.sendApplicationLog(JSON.stringify({name, value}));

+ 1
- 0
modules/TokenData/TokenData.js View File

99
         if(!this.payload.context)
99
         if(!this.payload.context)
100
             return;
100
             return;
101
         this.server = this.payload.context.server;
101
         this.server = this.payload.context.server;
102
+        this.group = this.payload.context.group;
102
         let callerData = this.payload.context.user;
103
         let callerData = this.payload.context.user;
103
         let calleeData = this.payload.context.callee;
104
         let calleeData = this.payload.context.callee;
104
         if(callerData)
105
         if(callerData)

Loading…
Cancel
Save