| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | 
							- var RTCBrowserType = require("../RTC/RTCBrowserType");
 - 
 - function NoopAnalytics() {}
 - NoopAnalytics.prototype.sendEvent = function () {};
 - 
 - function AnalyticsAdapter() {
 -     this.browserActionSuffix = '.' + RTCBrowserType.getBrowserName();
 - }
 - 
 - // some events may happen before init or implementation script download
 - // in this case we accumulate them in this array and send them on init
 - AnalyticsAdapter.eventsQueue = [];
 - 
 - // XXX Since we asynchronously load the integration of the analytics API and the
 - // analytics API may asynchronously load its implementation (e.g. Google
 - // Analytics), we cannot make the decision with respect to which analytics
 - // implementation we will use here and we have to postpone it i.e. we will make
 - // a lazy decision, will wait for loaded or dispose methods to be called.
 - // in the meantime we accumulate any events received
 - AnalyticsAdapter.prototype.sendEvent = function (action, data) {
 -     if (this.analytics === null || typeof this.analytics === 'undefined') {
 -         // missing this.analytics but have window implementation, let's use it
 -         if (window.Analytics) {
 -             this.loaded();
 -         }
 -         else {
 -             AnalyticsAdapter.eventsQueue.push({
 -                 action: action,
 -                 data: data
 -             });
 -             // stored, lets break here
 -             return;
 -         }
 -     }
 -     try {
 -         this.analytics.sendEvent(action + this.browserActionSuffix, data);
 -     } catch (ignored) {}
 - };
 - 
 - /**
 -  * Dispose analytics. Clears any available queue element and sets
 -  * NoopAnalytics to be used.
 -  */
 - AnalyticsAdapter.prototype.dispose = function () {
 -     this.analytics = new NoopAnalytics();
 -     AnalyticsAdapter.eventsQueue.length = 0;
 - };
 - 
 - /**
 -  * Loaded analytics script. Sens queued events.
 -  */
 - AnalyticsAdapter.prototype.loaded = function () {
 -     var AnalyticsImpl = window.Analytics || NoopAnalytics;
 - 
 -     this.analytics = new AnalyticsImpl();
 - 
 -     // new analytics lets send all events if any
 -     if (AnalyticsAdapter.eventsQueue.length) {
 -         AnalyticsAdapter.eventsQueue.forEach(function (event) {
 -             this.sendEvent(event.action, event.data);
 -         }.bind(this));
 -         AnalyticsAdapter.eventsQueue.length = 0;
 -     }
 - };
 - 
 - module.exports = new AnalyticsAdapter();
 
 
  |