<commit_before>import AbstractTracker from './abstract-tracker';

function trackerFun(trackerFun, global = window) {
  if (typeof trackerFun === 'string') {
    trackerFun = global[trackerFun];
  }
  return trackerFun;
}

function trackingNamespace(name) {
  return (action) => (name ? name + '.' : '') + action;
}

function setFields(tracker, namespace, fields) {
  for (var propName in fields) {
    tracker(namespace('set'), propName, fields[propName]);
  }
}

class GoogleTracker extends AbstractTracker {
  constructor(trackerOptions = {}) {
    super();
    this.tracker  = () => trackerFun(trackerOptions.trackerFun || 'ga');
    this.name     = trackingNamespace(trackerOptions.name || '');

    if (trackerOptions.fields) {
      setFields(this.tracker(), this.name, trackerOptions.fields);
    }
  }

  set(key, value) {
    this.tracker()(this.name('set'), key, value);
  }

  send(fields = {}) {
    this.tracker()(this.name('send'), fields);
  }

  sendEvent(category, action, label, value) {
    let fields = {
      hitType:      'event',
      eventCategory: category,
      eventAction:   action,
      eventLabel:    label,
      eventValue:    value
    };

    this.send(fields);
  }

  trackPageView(path, fields) {
    fields = fields || {};
    if (!path) {
      let loc = window.location;
      path = loc.hash ? loc.hash.substring(1) : (loc.pathname + loc.search);
    }
    this.tracker()(this.name('send'), 'pageview', path, fields);<commit_msg>Rename 'GoogleTracker#tracker' getter to '#ga'<commit_after>import AbstractTracker from './abstract-tracker';

function trackerFun(trackerFun, global = window) {
  if (typeof trackerFun === 'string') {
    trackerFun = global[trackerFun];
  }
  return trackerFun;
}

function trackingNamespace(name) {
  return (action) => (name ? name + '.' : '') + action;
}

function setFields(ga, namespace, fields) {
  for (var propName in fields) {
    ga(namespace('set'), propName, fields[propName]);
  }
}

class GoogleTracker extends AbstractTracker {
  constructor(trackerOptions = {}) {
    super();
    this.ga       = () => trackerFun(trackerOptions.trackerFun || 'ga');
    this.name     = trackingNamespace(trackerOptions.name || '');

    if (trackerOptions.fields) {
      setFields(this.ga(), this.name, trackerOptions.fields);
    }
  }

  set(key, value) {
    this.ga()(this.name('set'), key, value);
  }

  send(fields = {}) {
    this.ga()(this.name('send'), fields);
  }

  sendEvent(category, action, label, value) {
    let fields = {
      hitType:      'event',
      eventCategory: category,
      eventAction:   action,
      eventLabel:    label,
      eventValue:    value
    };

    this.send(fields);
  }

  trackPageView(path, fields) {
    fields = fields || {};
    if (!path) {
      let loc = window.location;
      path = loc.hash ? loc.hash.substring(1) : (loc.pathname + loc.search);
    }
    this.ga()(this.name('send'), 'pageview', path, fields);
{'fraction_non_alphanumeric': 0.15869786368260427, 'fraction_numerical': 0.0006781959986436081, 'mean_word_length': 3.226361031518625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6578082', 'n_tokens_mistral': 954, 'n_tokens_neox': 935, 'n_words': 191}