|
@@ -1,15 +1,43 @@
|
|
1
|
+var ScriptUtil = require('../util/ScriptUtil');
|
|
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
|
+ ScriptUtil.loadScript(
|
|
13
|
+ 'analytics.js?v=1',
|
|
14
|
+ /* async */ true,
|
|
15
|
+ /* prepend */ false);
|
|
16
|
+}
|
|
17
|
+
|
|
18
|
+// NoopAnalytics
|
1
|
19
|
function NoopAnalytics() {}
|
|
20
|
+
|
2
|
21
|
NoopAnalytics.prototype.sendEvent = function () {};
|
3
|
22
|
|
|
23
|
+// AnalyticsAdapter
|
4
|
24
|
function AnalyticsAdapter() {
|
5
|
|
- var AnalyticsImpl = window.Analytics || NoopAnalytics;
|
6
|
|
- this.analytics = new AnalyticsImpl();
|
|
25
|
+ // XXX Since we asynchronously load the integration of the analytics API and
|
|
26
|
+ // the analytics API may asynchronously load its implementation (e.g. Google
|
|
27
|
+ // Analytics), we cannot make the decision with respect to which analytics
|
|
28
|
+ // implementation we will use here and we have to postpone it i.e. we will
|
|
29
|
+ // make a lazy decision.
|
7
|
30
|
}
|
8
|
31
|
|
9
|
32
|
AnalyticsAdapter.prototype.sendEvent = function (action, data) {
|
|
33
|
+ var a = this.analytics;
|
|
34
|
+
|
|
35
|
+ if (a === null || typeof a === 'undefined') {
|
|
36
|
+ this.analytics = a = new (window.Analytics || NoopAnalytics)();
|
|
37
|
+ }
|
10
|
38
|
try {
|
11
|
|
- this.analytics.sendEvent.apply(this.analytics, arguments);
|
|
39
|
+ a.sendEvent.apply(a, arguments);
|
12
|
40
|
} catch (ignored) {}
|
13
|
41
|
};
|
14
|
42
|
|
15
|
|
-module.exports = new AnalyticsAdapter();
|
|
43
|
+module.exports = new AnalyticsAdapter();
|