浏览代码

feat(analytics): Add support for permanent properties and new parameters format

dev1
hristoterezov 8 年前
父节点
当前提交
5b656903ac

+ 4
- 3
JitsiConference.js 查看文件

@@ -824,9 +824,10 @@ function (jingleSession, jingleOffer, now) {
824 824
     var crossRegion = null;
825 825
     if (window.jitsiRegionInfo)
826 826
         crossRegion = window.jitsiRegionInfo["CrossRegion"];
827
-    Statistics.analytics.sendEvent("session.initiate",
828
-        (now - this.room.connectionTimes["muc.joined"]),
829
-        crossRegion);
827
+    Statistics.analytics.sendEvent("session.initiate",{
828
+            value: now - this.room.connectionTimes["muc.joined"],
829
+            label: crossRegion
830
+        });
830 831
     try{
831 832
         jingleSession.initialize(false /* initiator */,this.room);
832 833
     } catch (error) {

+ 6
- 3
JitsiConferenceEventManager.js 查看文件

@@ -103,11 +103,13 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
103 103
         {
104 104
             for (var ckey in chatRoom.connectionTimes){
105 105
                 var cvalue = chatRoom.connectionTimes[ckey];
106
-                Statistics.analytics.sendEvent('conference.' + ckey, cvalue);
106
+                Statistics.analytics.sendEvent('conference.' + ckey,
107
+                    {value: cvalue});
107 108
             }
108 109
             for (var xkey in chatRoom.xmpp.connectionTimes){
109 110
                 var xvalue = chatRoom.xmpp.connectionTimes[xkey];
110
-                Statistics.analytics.sendEvent('xmpp.' + xkey, xvalue);
111
+                Statistics.analytics.sendEvent('xmpp.' + xkey,
112
+                    {value: xvalue});
111 113
             }
112 114
         });
113 115
 
@@ -467,7 +469,8 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
467 469
         var now = window.performance.now();
468 470
         logger.log("(TIME) data channel opened ", now);
469 471
         conference.room.connectionTimes["data.channel.opened"] = now;
470
-        Statistics.analytics.sendEvent('conference.dataChannel.open', now);
472
+        Statistics.analytics.sendEvent('conference.dataChannel.open',
473
+            {value: now});
471 474
     });
472 475
 
473 476
     this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,

+ 2
- 1
JitsiConnection.js 查看文件

@@ -21,7 +21,8 @@ function JitsiConnection(appID, token, options) {
21 21
     this.addEventListener(JitsiConnectionEvents.CONNECTION_FAILED,
22 22
         function (errType, msg) {
23 23
             // sends analytics and callstats event
24
-            Statistics.sendEventToAll('connection.failed.' + errType, msg);
24
+            Statistics.sendEventToAll('connection.failed.' + errType,
25
+                {label: msg});
25 26
         }.bind(this));
26 27
 
27 28
     this.addEventListener(JitsiConnectionEvents.CONNECTION_DISCONNECTED,

+ 2
- 2
JitsiMeetJS.js 查看文件

@@ -200,7 +200,7 @@ var LibJitsiMeet = {
200 200
                     window.performance.now();
201 201
 
202 202
                 Statistics.analytics.sendEvent(addDeviceTypeToAnalyticsEvent(
203
-                    "getUserMedia.success", options), options);
203
+                    "getUserMedia.success", options), {value: options});
204 204
 
205 205
                 if(!RTC.options.disableAudioLevels)
206 206
                     for(let i = 0; i < tracks.length; i++) {
@@ -277,7 +277,7 @@ var LibJitsiMeet = {
277 277
                     Statistics.analytics.sendEvent(
278 278
                         addDeviceTypeToAnalyticsEvent(
279 279
                             "getUserMedia.failed", options) + '.' + error.name,
280
-                        options);
280
+                        {value: options});
281 281
                 }
282 282
 
283 283
                 window.connectionTimes["obtainPermissions.end"] =

+ 2
- 2
modules/RTC/JitsiLocalTrack.js 查看文件

@@ -145,8 +145,8 @@ JitsiLocalTrack.prototype._initNoDataFromSourceHandlers = function () {
145 145
                 this._setHandler("track_unmute", () => {
146 146
                     this._clearNoDataFromSourceMuteResources();
147 147
                     Statistics.sendEventToAll(
148
-                            this.getType() + ".track_unmute",
149
-                            window.performance.now() - now);
148
+                        this.getType() + ".track_unmute",
149
+                        {value: window.performance.now() - now});
150 150
                 });
151 151
             }
152 152
         });

+ 1
- 1
modules/RTC/JitsiRemoteTrack.js 查看文件

@@ -148,7 +148,7 @@ JitsiRemoteTrack.prototype._playCallback = function () {
148 148
     var eventName = type +'.ttfm';
149 149
     if(this.hasBeenMuted)
150 150
         eventName += '.muted';
151
-    Statistics.analytics.sendEvent(eventName, ttfm);
151
+    Statistics.analytics.sendEvent(eventName, {value: ttfm});
152 152
 };
153 153
 
154 154
 /**

+ 2
- 1
modules/connectivity/ParticipantConnectionStatus.js 查看文件

@@ -195,7 +195,8 @@ ParticipantConnectionStatus.prototype._changeConnectionStatus
195 195
             }));
196 196
 
197 197
         // and analytics
198
-        Statistics.analytics.sendEvent('peer.conn.status', null, newStatus);
198
+        Statistics.analytics.sendEvent('peer.conn.status',
199
+            {label: newStatus});
199 200
 
200 201
         this.conference.eventEmitter.emit(
201 202
             JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,

+ 23
- 41
modules/statistics/AnalyticsAdapter.js 查看文件

@@ -5,6 +5,10 @@ NoopAnalytics.prototype.sendEvent = function () {};
5 5
 
6 6
 function AnalyticsAdapter() {
7 7
     this.browserName = RTCBrowserType.getBrowserName();
8
+    /**
9
+     * Map of properties that will be added to every event
10
+     */
11
+    this.permanentProperties = {};
8 12
 }
9 13
 
10 14
 // some events may happen before init or implementation script download
@@ -13,36 +17,18 @@ AnalyticsAdapter.eventsQueue = [];
13 17
 
14 18
 /**
15 19
  * Sends analytics event.
16
- * @param action
17
- * @param data
18
- * @param label
19
- */
20
-AnalyticsAdapter.prototype.sendEvent = function (action, data, label) {
21
-    if(this._checkAnalyticsAndMaybeCacheEvent(
22
-        "sendEvent", action, data,label)) {
23
-        try {
24
-            this.analytics.sendEvent(action, data, label, this.browserName);
25
-        } catch (ignored) { // eslint-disable-line no-empty
26
-        }
27
-    }
28
-};
29
-
30
-/**
31
- * Sends feedback.
32
- * @param {object} data with proprties:
33
- * - {int} overall an integer between 1 and 5 indicating the user feedback
34
- * - {string} detailed detailed feedback from the user.
35
- * @param label
20
+ * @param {String} action the name of the event
21
+ * @param {Object} data can be any JSON object
36 22
  */
37
-AnalyticsAdapter.prototype.sendFeedback = function (data, label) {
38
-    if(this._checkAnalyticsAndMaybeCacheEvent(
39
-        "sendFeedback", null, data,label)) {
23
+AnalyticsAdapter.prototype.sendEvent = function (action, data = {}) {
24
+    if(this._checkAnalyticsAndMaybeCacheEvent(action, data)) {
25
+        data.browserName = this.browserName;
40 26
         try {
41
-            this.analytics.sendFeedback(data, label, this.browserName);
27
+            this.analytics.sendEvent(action,
28
+                Object.assign({}, this.permanentProperties, data));
42 29
         } catch (ignored) { // eslint-disable-line no-empty
43 30
         }
44 31
     }
45
-
46 32
 };
47 33
 
48 34
 /**
@@ -53,14 +39,11 @@ AnalyticsAdapter.prototype.sendFeedback = function (data, label) {
53 39
  * a lazy decision, will wait for loaded or dispose methods to be called.
54 40
  * in the meantime we accumulate any events received. We should call this
55 41
  * method before trying to send the event.
56
- * @param {string} method - Identifies which method should we use later for the
57
- * cached events - "sendEvent" or "sendFeedback".
58 42
  * @param action
59 43
  * @param data
60
- * @param label
61 44
  */
62 45
 AnalyticsAdapter.prototype._checkAnalyticsAndMaybeCacheEvent
63
-= function (method, action, data, label) {
46
+= function (action, data) {
64 47
     if (this.analytics === null || typeof this.analytics === 'undefined') {
65 48
         // missing this.analytics but have window implementation, let's use it
66 49
         if (window.Analytics) {
@@ -68,10 +51,8 @@ AnalyticsAdapter.prototype._checkAnalyticsAndMaybeCacheEvent
68 51
         }
69 52
         else {
70 53
             AnalyticsAdapter.eventsQueue.push({
71
-                method: method,
72 54
                 action: action,
73
-                data: data,
74
-                label: label
55
+                data: data
75 56
             });
76 57
             // stored, lets break here
77 58
             return false;
@@ -90,6 +71,15 @@ AnalyticsAdapter.prototype.dispose = function () {
90 71
     AnalyticsAdapter.eventsQueue.length = 0;
91 72
 };
92 73
 
74
+/**
75
+ * Adds map of properties that will be added to every event.
76
+ * @param {Object} properties the map of properties
77
+ */
78
+AnalyticsAdapter.prototype.addPermanentProperties = function (properties) {
79
+    this.permanentProperties
80
+        = Object.assign(this.permanentProperties, properties);
81
+};
82
+
93 83
 /**
94 84
  * Loaded analytics script. Sens queued events.
95 85
  */
@@ -101,15 +91,7 @@ AnalyticsAdapter.prototype.loaded = function () {
101 91
     // new analytics lets send all events if any
102 92
     if (AnalyticsAdapter.eventsQueue.length) {
103 93
         AnalyticsAdapter.eventsQueue.forEach(function (event) {
104
-            switch(event.method) {
105
-                case "sendEvent":
106
-                    this.sendEvent(event.action, event.data, event.label);
107
-                    break;
108
-                case "sendFeedback":
109
-                    this.sendFeedback(event.data, event.label);
110
-                    break;
111
-            }
112
-
94
+            this.sendEvent(event.action, event.data);
113 95
         }.bind(this));
114 96
         AnalyticsAdapter.eventsQueue.length = 0;
115 97
     }

+ 7
- 6
modules/statistics/statistics.js 查看文件

@@ -478,7 +478,8 @@ Statistics.sendLog = function (m) {
478 478
 Statistics.prototype.sendFeedback = function(overall, detailed) {
479 479
     if(this.callstats)
480 480
         this.callstats.sendFeedback(overall, detailed);
481
-    Statistics.analytics.sendFeedback({overall, detailed});
481
+    Statistics.analytics.sendEvent("feedback.rating",
482
+        {value: overall, detailed: detailed});
482 483
 };
483 484
 
484 485
 Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
@@ -498,12 +499,12 @@ Statistics.reportGlobalError = function (error) {
498 499
 
499 500
 /**
500 501
  * Sends event to analytics and callstats.
501
- * @param eventName {string} the event name.
502
- * @param msg {String} optional event info/messages.
502
+ * @param {string} eventName the event name.
503
+ * @param {Object} data the data to be sent.
503 504
  */
504
-Statistics.sendEventToAll = function (eventName, msg) {
505
-    this.analytics.sendEvent(eventName, null, msg);
506
-    Statistics.sendLog({name: eventName, msg: msg ? msg : ""});
505
+Statistics.sendEventToAll = function (eventName, data) {
506
+    this.analytics.sendEvent(eventName, data);
507
+    Statistics.sendLog({name: eventName, data});
507 508
 };
508 509
 
509 510
 module.exports = Statistics;

+ 1
- 1
modules/xmpp/JingleSessionPC.js 查看文件

@@ -133,7 +133,7 @@ JingleSessionPC.prototype.doInitialize = function () {
133 133
         logger.log("(TIME) ICE " + self.peerconnection.iceConnectionState +
134 134
                     ":\t", now);
135 135
         Statistics.analytics.sendEvent(
136
-            'ice.' + self.peerconnection.iceConnectionState, now);
136
+            'ice.' + self.peerconnection.iceConnectionState, {value: now});
137 137
         switch (self.peerconnection.iceConnectionState) {
138 138
             case 'connected':
139 139
 

+ 4
- 3
modules/xmpp/strophe.jingle.js 查看文件

@@ -110,7 +110,7 @@ class JingleConnectionPlugin extends ConnectionPlugin {
110 110
                     this.terminate(sess.sid);
111 111
                 }
112 112
                 Statistics.analytics.sendEvent(
113
-                    'xmpp.session-initiate', now);
113
+                    'xmpp.session-initiate', {value: now});
114 114
                 break;
115 115
             }
116 116
             case 'session-terminate': {
@@ -130,14 +130,15 @@ class JingleConnectionPlugin extends ConnectionPlugin {
130 130
             case 'transport-replace':
131 131
                 logger.info("(TIME) Start transport replace", now);
132 132
                 Statistics.analytics.sendEvent(
133
-                    'xmpp.transport-replace.start', now);
133
+                    'xmpp.transport-replace.start', {value: now});
134 134
 
135 135
                 sess.replaceTransport($(iq).find('>jingle'), () => {
136 136
                     const successTime = window.performance.now();
137 137
                     logger.info(
138 138
                         "(TIME) Transport replace success!", successTime);
139 139
                     Statistics.analytics.sendEvent(
140
-                        'xmpp.transport-replace.success', successTime);
140
+                        'xmpp.transport-replace.success',
141
+                        {value: successTime});
141 142
                 }, (error) => {
142 143
                     GlobalOnErrorHandler.callErrorHandler(error);
143 144
                     logger.error('Transport replace failed', error);

正在加载...
取消
保存