瀏覽代碼

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

dev1
hristoterezov 9 年之前
父節點
當前提交
5b656903ac

+ 4
- 3
JitsiConference.js 查看文件

824
     var crossRegion = null;
824
     var crossRegion = null;
825
     if (window.jitsiRegionInfo)
825
     if (window.jitsiRegionInfo)
826
         crossRegion = window.jitsiRegionInfo["CrossRegion"];
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
     try{
831
     try{
831
         jingleSession.initialize(false /* initiator */,this.room);
832
         jingleSession.initialize(false /* initiator */,this.room);
832
     } catch (error) {
833
     } catch (error) {

+ 6
- 3
JitsiConferenceEventManager.js 查看文件

103
         {
103
         {
104
             for (var ckey in chatRoom.connectionTimes){
104
             for (var ckey in chatRoom.connectionTimes){
105
                 var cvalue = chatRoom.connectionTimes[ckey];
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
             for (var xkey in chatRoom.xmpp.connectionTimes){
109
             for (var xkey in chatRoom.xmpp.connectionTimes){
109
                 var xvalue = chatRoom.xmpp.connectionTimes[xkey];
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
         var now = window.performance.now();
469
         var now = window.performance.now();
468
         logger.log("(TIME) data channel opened ", now);
470
         logger.log("(TIME) data channel opened ", now);
469
         conference.room.connectionTimes["data.channel.opened"] = now;
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
     this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,
476
     this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,

+ 2
- 1
JitsiConnection.js 查看文件

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

+ 2
- 2
JitsiMeetJS.js 查看文件

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

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

145
                 this._setHandler("track_unmute", () => {
145
                 this._setHandler("track_unmute", () => {
146
                     this._clearNoDataFromSourceMuteResources();
146
                     this._clearNoDataFromSourceMuteResources();
147
                     Statistics.sendEventToAll(
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
     var eventName = type +'.ttfm';
148
     var eventName = type +'.ttfm';
149
     if(this.hasBeenMuted)
149
     if(this.hasBeenMuted)
150
         eventName += '.muted';
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
             }));
195
             }));
196
 
196
 
197
         // and analytics
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
         this.conference.eventEmitter.emit(
201
         this.conference.eventEmitter.emit(
201
             JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,
202
             JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,

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

5
 
5
 
6
 function AnalyticsAdapter() {
6
 function AnalyticsAdapter() {
7
     this.browserName = RTCBrowserType.getBrowserName();
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
 // some events may happen before init or implementation script download
14
 // some events may happen before init or implementation script download
13
 
17
 
14
 /**
18
 /**
15
  * Sends analytics event.
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
         try {
26
         try {
41
-            this.analytics.sendFeedback(data, label, this.browserName);
27
+            this.analytics.sendEvent(action,
28
+                Object.assign({}, this.permanentProperties, data));
42
         } catch (ignored) { // eslint-disable-line no-empty
29
         } catch (ignored) { // eslint-disable-line no-empty
43
         }
30
         }
44
     }
31
     }
45
-
46
 };
32
 };
47
 
33
 
48
 /**
34
 /**
53
  * a lazy decision, will wait for loaded or dispose methods to be called.
39
  * a lazy decision, will wait for loaded or dispose methods to be called.
54
  * in the meantime we accumulate any events received. We should call this
40
  * in the meantime we accumulate any events received. We should call this
55
  * method before trying to send the event.
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
  * @param action
42
  * @param action
59
  * @param data
43
  * @param data
60
- * @param label
61
  */
44
  */
62
 AnalyticsAdapter.prototype._checkAnalyticsAndMaybeCacheEvent
45
 AnalyticsAdapter.prototype._checkAnalyticsAndMaybeCacheEvent
63
-= function (method, action, data, label) {
46
+= function (action, data) {
64
     if (this.analytics === null || typeof this.analytics === 'undefined') {
47
     if (this.analytics === null || typeof this.analytics === 'undefined') {
65
         // missing this.analytics but have window implementation, let's use it
48
         // missing this.analytics but have window implementation, let's use it
66
         if (window.Analytics) {
49
         if (window.Analytics) {
68
         }
51
         }
69
         else {
52
         else {
70
             AnalyticsAdapter.eventsQueue.push({
53
             AnalyticsAdapter.eventsQueue.push({
71
-                method: method,
72
                 action: action,
54
                 action: action,
73
-                data: data,
74
-                label: label
55
+                data: data
75
             });
56
             });
76
             // stored, lets break here
57
             // stored, lets break here
77
             return false;
58
             return false;
90
     AnalyticsAdapter.eventsQueue.length = 0;
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
  * Loaded analytics script. Sens queued events.
84
  * Loaded analytics script. Sens queued events.
95
  */
85
  */
101
     // new analytics lets send all events if any
91
     // new analytics lets send all events if any
102
     if (AnalyticsAdapter.eventsQueue.length) {
92
     if (AnalyticsAdapter.eventsQueue.length) {
103
         AnalyticsAdapter.eventsQueue.forEach(function (event) {
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
         }.bind(this));
95
         }.bind(this));
114
         AnalyticsAdapter.eventsQueue.length = 0;
96
         AnalyticsAdapter.eventsQueue.length = 0;
115
     }
97
     }

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

478
 Statistics.prototype.sendFeedback = function(overall, detailed) {
478
 Statistics.prototype.sendFeedback = function(overall, detailed) {
479
     if(this.callstats)
479
     if(this.callstats)
480
         this.callstats.sendFeedback(overall, detailed);
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
 Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
485
 Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
498
 
499
 
499
 /**
500
 /**
500
  * Sends event to analytics and callstats.
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
 module.exports = Statistics;
510
 module.exports = Statistics;

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

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

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

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

Loading…
取消
儲存