Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AnalyticsAdapter.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* global config */
  2. var ScriptUtil = require('../util/ScriptUtil');
  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. // NoopAnalytics
  18. function NoopAnalytics() {}
  19. NoopAnalytics.prototype.sendEvent = function () {};
  20. // AnalyticsAdapter
  21. function AnalyticsAdapter() {
  22. // XXX Since we asynchronously load the integration of the analytics API and
  23. // the 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
  26. // make a lazy decision.
  27. }
  28. AnalyticsAdapter.prototype.sendEvent = function (action, data) {
  29. var a = this.analytics;
  30. if (a === null || typeof a === 'undefined') {
  31. var AnalyticsImpl = window.Analytics || NoopAnalytics;
  32. this.analytics = a = new AnalyticsImpl();
  33. }
  34. try {
  35. a.sendEvent.apply(a, arguments);
  36. } catch (ignored) {}
  37. };
  38. module.exports = new AnalyticsAdapter();