Browse Source

Merge pull request #269 from jitsi/analytics_feedback

feat(feedback): Tries to send the detailed feedback to analytics
dev1
yanas 8 years ago
parent
commit
4bc4a737dd
2 changed files with 63 additions and 13 deletions
  1. 62
    12
      modules/statistics/AnalyticsAdapter.js
  2. 1
    1
      modules/statistics/statistics.js

+ 62
- 12
modules/statistics/AnalyticsAdapter.js View File

11
 // in this case we accumulate them in this array and send them on init
11
 // in this case we accumulate them in this array and send them on init
12
 AnalyticsAdapter.eventsQueue = [];
12
 AnalyticsAdapter.eventsQueue = [];
13
 
13
 
14
-// XXX Since we asynchronously load the integration of the analytics API and the
15
-// analytics API may asynchronously load its implementation (e.g. Google
16
-// Analytics), we cannot make the decision with respect to which analytics
17
-// implementation we will use here and we have to postpone it i.e. we will make
18
-// a lazy decision, will wait for loaded or dispose methods to be called.
19
-// in the meantime we accumulate any events received
14
+/**
15
+ * Sends analytics event.
16
+ * @param action
17
+ * @param data
18
+ * @param label
19
+ */
20
 AnalyticsAdapter.prototype.sendEvent = function (action, data, label) {
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
36
+ */
37
+AnalyticsAdapter.prototype.sendFeedback = function (data, label) {
38
+    if(this._checkAnalyticsAndMaybeCacheEvent(
39
+        "sendFeedback", null, data,label)) {
40
+        try {
41
+            this.analytics.sendFeedback(data, label, this.browserName);
42
+        } catch (ignored) { // eslint-disable-line no-empty
43
+        }
44
+    }
45
+
46
+};
47
+
48
+/**
49
+ * Since we asynchronously load the integration of the analytics API and the
50
+ * analytics API may asynchronously load its implementation (e.g. Google
51
+ * Analytics), we cannot make the decision with respect to which analytics
52
+ * implementation we will use here and we have to postpone it i.e. we will make
53
+ * 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
55
+ * 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
59
+ * @param data
60
+ * @param label
61
+ */
62
+AnalyticsAdapter.prototype._checkAnalyticsAndMaybeCacheEvent
63
+= function (method, action, data, label) {
21
     if (this.analytics === null || typeof this.analytics === 'undefined') {
64
     if (this.analytics === null || typeof this.analytics === 'undefined') {
22
         // missing this.analytics but have window implementation, let's use it
65
         // missing this.analytics but have window implementation, let's use it
23
         if (window.Analytics) {
66
         if (window.Analytics) {
25
         }
68
         }
26
         else {
69
         else {
27
             AnalyticsAdapter.eventsQueue.push({
70
             AnalyticsAdapter.eventsQueue.push({
71
+                method: method,
28
                 action: action,
72
                 action: action,
29
                 data: data,
73
                 data: data,
30
                 label: label
74
                 label: label
31
             });
75
             });
32
             // stored, lets break here
76
             // stored, lets break here
33
-            return;
77
+            return false;
34
         }
78
         }
35
     }
79
     }
36
-    try {
37
-        this.analytics.sendEvent(action, data, label, this.browserName);
38
-    } catch (ignored) { // eslint-disable-line no-empty
39
-    }
80
+    return true;
40
 };
81
 };
41
 
82
 
83
+
42
 /**
84
 /**
43
  * Dispose analytics. Clears any available queue element and sets
85
  * Dispose analytics. Clears any available queue element and sets
44
  * NoopAnalytics to be used.
86
  * NoopAnalytics to be used.
59
     // new analytics lets send all events if any
101
     // new analytics lets send all events if any
60
     if (AnalyticsAdapter.eventsQueue.length) {
102
     if (AnalyticsAdapter.eventsQueue.length) {
61
         AnalyticsAdapter.eventsQueue.forEach(function (event) {
103
         AnalyticsAdapter.eventsQueue.forEach(function (event) {
62
-            this.sendEvent(event.action, event.data, event.label);
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
+
63
         }.bind(this));
113
         }.bind(this));
64
         AnalyticsAdapter.eventsQueue.length = 0;
114
         AnalyticsAdapter.eventsQueue.length = 0;
65
     }
115
     }

+ 1
- 1
modules/statistics/statistics.js View File

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.sendEvent('feedback.rating', overall);
481
+    Statistics.analytics.sendFeedback({overall, detailed});
482
 };
482
 };
483
 
483
 
484
 Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
484
 Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;

Loading…
Cancel
Save