소스 검색

Decides whether to use analytics after the analytics API has been given a chance to load.

j8
Lyubomir Marinov 9 년 전
부모
커밋
6dbbea9944
3개의 변경된 파일13957개의 추가작업 그리고 13862개의 파일을 삭제
  1. 0
    12
      index.html
  2. 13919
    13839
      libs/lib-jitsi-meet.js
  3. 38
    11
      modules/statistics/AnalyticsAdapter.js

+ 0
- 12
index.html 파일 보기

@@ -242,17 +242,5 @@
242 242
             <a id="feedbackButton" data-container="body" data-toggle="popover" data-placement="right" data-i18n="[data-content]feedback"><i class="fa fa-heart"></i></a>
243 243
         </div>
244 244
     </div>
245
-    <script type="text/javascript">
246
-      if (!config.disableThirdPartyRequests) {
247
-        [
248
-          'analytics.js?v=1'
249
-        ].forEach(function(extSrc) {
250
-          var extScript = document.createElement('script');
251
-          extScript.src = extSrc;
252
-          extScript.async = false;
253
-          document.head.appendChild(extScript);
254
-        });
255
-      }
256
-    </script>
257 245
   </body>
258 246
 </html>

+ 13919
- 13839
libs/lib-jitsi-meet.js
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 38
- 11
modules/statistics/AnalyticsAdapter.js 파일 보기

@@ -1,19 +1,46 @@
1
+/* global config JitsiMeetJS */
2
+
3
+// Load the integration of a third-party analytics API such as Google Analytics.
4
+// Since we cannot guarantee the quality of the third-party service (e.g. their
5
+// server may take noticeably long time to respond), it is in our best interest
6
+// (in the sense that the intergration of the analytics API is important to us
7
+// but not enough to allow it to prevent people from joining a conference) to
8
+// download the API asynchronously. Additionally, Google Analytics will download
9
+// its implementation asynchronously anyway so it makes sense to append the
10
+// loading on our side rather than prepend it.
11
+if (config.disableThirdPartyRequests !== true) {
12
+    JitsiMeetJS.util.ScriptUtil.loadScript(
13
+            'analytics.js?v=1',
14
+            /* async */ true,
15
+            /* prepend */ false);
16
+}
17
+
1 18
 class NoopAnalytics {
2
-  sendEvent () {}
19
+    sendEvent () {}
3 20
 }
4 21
 
5
-const AnalyticsImpl = window.Analytics || NoopAnalytics;
22
+// XXX Since we asynchronously load the integration of the analytics API and the
23
+// analytics API may asynchronously load its implementation (e.g. Google
24
+// Analytics), we cannot make the decision with respect to which analytics
25
+// implementation we will use here and we have to postpone it i.e. we will make
26
+// a lazy decision.
6 27
 
7 28
 class AnalyticsAdapter {
8
-  constructor () {
9
-    this.analytics = new AnalyticsImpl();
10
-  }
11
-
12
-  sendEvent (...args) {
13
-    try {
14
-      this.analytics.sendEvent(...args);
15
-    } catch (ignored) {}
16
-  }
29
+    constructor () {
30
+    }
31
+
32
+    sendEvent (...args) {
33
+        var a = this.analytics;
34
+
35
+        if (a === null || typeof a === 'undefined') {
36
+            var AnalyticsImpl = window.Analytics || NoopAnalytics;
37
+
38
+            this.analytics = a = new AnalyticsImpl();
39
+        }
40
+        try {
41
+            a.sendEvent(...args);
42
+        } catch (ignored) {}
43
+    }
17 44
 }
18 45
 
19 46
 export default new AnalyticsAdapter();

Loading…
취소
저장