class Analytics {
  constructor(trackingId, clientId, version) {
    this.version = version || 1;
    this.trackingId = trackingId;
    this.clientId = clientId;
  }

  send(hit) {

    hit.set({
      v: this.version,
      tid: this.trackingId,
      cid: this.clientId
    });

    fetch('https://ssl.google-analytics.com/collect?' + hit.toQueryString() + '&z=' + Math.round(Math.random() * 1e8), {
      method: 'get',
    });
  }
}

module.exports = Analytics;

class Analytics {
  constructor(trackingId, clientId, version, userAgent) {
    this.version = version || 1;
    this.trackingId = trackingId;
    this.clientId = clientId;
    this.userAgent = userAgent || null;
  }

  send(hit) {

    hit.set({
      v: this.version,
      tid: this.trackingId,
      cid: this.clientId
    });

    let options = {
      method: 'get',
    }

    if (this.userAgent) {
      options.headers = {
        'user-agent': this.userAgent
      };
    }

    fetch('https://ssl.google-analytics.com/collect?' + hit.toQueryString() + '&z=' + Math.round(Math.random() * 1e8), options);
  }
}

module.exports = Analytics;

Allow for custom user agent.
Allow for custom user agent.
