function Metrics()

in packages/fxa-content-server/app/scripts/lib/metrics.js [146:206]


function Metrics(options = {}) {
  // Supplying a custom start time is a good way to create invalid metrics. We
  // are deprecating this option.
  if (options.startTime !== undefined) {
    throw new Error('Supplying an external start time is no longer supported!');
  }

  this._speedTrap = new SpeedTrap(options);
  this._speedTrap.init();

  // `timers` and `events` are part of the public API
  this.timers = this._speedTrap.timers;
  this.events = this._speedTrap.events;

  this._window = options.window || window;

  this._activeExperiments = {};
  this._brokerType = options.brokerType || NOT_REPORTED_VALUE;
  this._maxEventOffset = options.maxEventOffset;
  this._clientHeight = options.clientHeight || NOT_REPORTED_VALUE;
  this._clientWidth = options.clientWidth || NOT_REPORTED_VALUE;
  // by default, send the metrics to the content server.
  this._collector = options.collector || '';
  this._context = options.context || Constants.CONTENT_SERVER_CONTEXT;
  this._devicePixelRatio = options.devicePixelRatio || NOT_REPORTED_VALUE;
  this._emailDomain = NOT_REPORTED_VALUE;
  this._entrypoint = options.entrypoint || NOT_REPORTED_VALUE;
  this._entrypointExperiment =
    options.entrypointExperiment || NOT_REPORTED_VALUE;
  this._entrypointVariation = options.entrypointVariation || NOT_REPORTED_VALUE;
  this._env = options.environment || new Environment(this._window);
  this._eventMemory = {};
  this._inactivityFlushMs =
    options.inactivityFlushMs || DEFAULT_INACTIVITY_TIMEOUT_MS;
  // All user metrics are sent to the backend. Data is only
  // reported to metrics if `isSampledUser===true`.
  this._isSampledUser = options.isSampledUser || false;
  this._lang = options.lang || 'unknown';
  this._marketingImpressions = {};
  this._numStoredAccounts = options.numStoredAccounts || '';
  this._referrer = this._window.document.referrer || NOT_REPORTED_VALUE;
  this._newsletters = NOT_REPORTED_VALUE;
  this._screenHeight = options.screenHeight || NOT_REPORTED_VALUE;
  this._screenWidth = options.screenWidth || NOT_REPORTED_VALUE;
  this._sentryMetrics = options.sentryMetrics;
  this._service = options.service || NOT_REPORTED_VALUE;
  this._startTime = this._speedTrap.baseTime;
  this._syncEngines = options.syncEngines || [];
  this._uid = options.uid || NOT_REPORTED_VALUE;
  this._metricsEnabled = options.metricsEnabled ?? true;
  this._uniqueUserId = options.uniqueUserId;
  this._userPreferences = {};
  this._utmCampaign = options.utmCampaign || NOT_REPORTED_VALUE;
  this._utmContent = options.utmContent || NOT_REPORTED_VALUE;
  this._utmMedium = options.utmMedium || NOT_REPORTED_VALUE;
  this._utmSource = options.utmSource || NOT_REPORTED_VALUE;
  this._utmTerm = options.utmTerm || NOT_REPORTED_VALUE;
  this._xhr = options.xhr || xhr;

  this.initialize(options);
}