|
@@ -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();
|