You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnalyticsAdapter.js 1.6KB

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