ソースを参照

Merge pull request #269 from jitsi/analytics_feedback

feat(feedback): Tries to send the detailed feedback to analytics
dev1
yanas 8年前
コミット
4bc4a737dd
2個のファイルの変更63行の追加13行の削除
  1. 62
    12
      modules/statistics/AnalyticsAdapter.js
  2. 1
    1
      modules/statistics/statistics.js

+ 62
- 12
modules/statistics/AnalyticsAdapter.js ファイルの表示

@@ -11,13 +11,56 @@ function AnalyticsAdapter() {
11 11
 // in this case we accumulate them in this array and send them on init
12 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 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 64
     if (this.analytics === null || typeof this.analytics === 'undefined') {
22 65
         // missing this.analytics but have window implementation, let's use it
23 66
         if (window.Analytics) {
@@ -25,20 +68,19 @@ AnalyticsAdapter.prototype.sendEvent = function (action, data, label) {
25 68
         }
26 69
         else {
27 70
             AnalyticsAdapter.eventsQueue.push({
71
+                method: method,
28 72
                 action: action,
29 73
                 data: data,
30 74
                 label: label
31 75
             });
32 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 85
  * Dispose analytics. Clears any available queue element and sets
44 86
  * NoopAnalytics to be used.
@@ -59,7 +101,15 @@ AnalyticsAdapter.prototype.loaded = function () {
59 101
     // new analytics lets send all events if any
60 102
     if (AnalyticsAdapter.eventsQueue.length) {
61 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 113
         }.bind(this));
64 114
         AnalyticsAdapter.eventsQueue.length = 0;
65 115
     }

+ 1
- 1
modules/statistics/statistics.js ファイルの表示

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

読み込み中…
キャンセル
保存