<commit_before>var pellet = require('../pellet');

if(process.env.BROWSER_ENV) {
  var PARSE_STATSD = /^\["((.+)\.)?(.+)"\s*,\s*(.+)\]$/;

  function sendCmd(type, gaTrackID) {
    if(!gaTrackID) {
      gaTrackID = pellet.config[type];
    }

    if(!gaTrackID){
      return 'send';
    }

    return gaTrackID + '.send';
  }

  pellet.registerInitFn(function (next) {
    if(pellet.config && pellet.config.instrumentation) {
      var gaTimingFilterFn = pellet.config.instrumentation.gaTimingFilterFn
        , gaEventFilterFn = pellet.config.instrumentation.gaEventFilterFn;
    }

    pellet.instrumentation.bus.on(function (data) {
      var namespace = data.namespace
        , gaTrackID = data.gaTrackID
        , details = data.details
        , type = data.type
        , fn;

      if(type === 'uncaught-exception') {
        ga(sendCmd('gaExceptionTrackID', gaTrackID), 'exception', {
          exDescription: details.msg + ' lineno:' + details.no
        });
      } else if(type === 'statsd' && details.c === 'timing') {
        if(gaTimingFilterFn && (fn = pellet.instrumentation.getTransformFn(gaTimingFilterFn)) && !(data = fn(data))) {
          return;
        }

        // update the gaTrackID because
        // getTransformFn can update the value
        gaTrackID = data.gaTrackID;

        // convert the statsd data to a GA timing event
        data = data.details.a.match(PARSE_STATSD);
        if(data) {
          ga(sendCmd('gaTimingTrackID', gaTrackID), 'timing', {
            'timingCategory': data[2] || 'statsd',
            'timingVar': data[3],
            'timingValue': parseInt(data[4])
          });
        }
      } else if(type === 'event') {
        if(gaEventFilterFn && (fn=pellet.instrumentation.getTransformFn(gaEventFilterFn)) && !(data = fn(data))) {
          return;
        }

        // update the gaTrackID because
        // getTransformFn can update the value
        gaTrackID = data.gaTrackID;

        ga(sendCmd('gaEventTrackID', gaTrackID), 'event', data);
      } else if(type === 'routechange') {

        // for non 2XX status codes fire
        var statusCode = details.pipeline.statusCode();
        if(!pellet.config.gaSyntheticPageUrl || statusCode === 200) {
          ga('set', {
            page: details.originalUrl,
            title: document.title<commit_msg>fix: if no componentConstruction is call the pipeline is never available so default to 200<commit_after>var pellet = require('../pellet');

if(process.env.BROWSER_ENV) {
  var PARSE_STATSD = /^\["((.+)\.)?(.+)"\s*,\s*(.+)\]$/;

  function sendCmd(type, gaTrackID) {
    if(!gaTrackID) {
      gaTrackID = pellet.config[type];
    }

    if(!gaTrackID){
      return 'send';
    }

    return gaTrackID + '.send';
  }

  pellet.registerInitFn(function (next) {
    if(pellet.config && pellet.config.instrumentation) {
      var gaTimingFilterFn = pellet.config.instrumentation.gaTimingFilterFn
        , gaEventFilterFn = pellet.config.instrumentation.gaEventFilterFn;
    }

    pellet.instrumentation.bus.on(function (data) {
      var namespace = data.namespace
        , gaTrackID = data.gaTrackID
        , details = data.details
        , type = data.type
        , fn;

      if(type === 'uncaught-exception') {
        ga(sendCmd('gaExceptionTrackID', gaTrackID), 'exception', {
          exDescription: details.msg + ' lineno:' + details.no
        });
      } else if(type === 'statsd' && details.c === 'timing') {
        if(gaTimingFilterFn && (fn = pellet.instrumentation.getTransformFn(gaTimingFilterFn)) && !(data = fn(data))) {
          return;
        }

        // update the gaTrackID because
        // getTransformFn can update the value
        gaTrackID = data.gaTrackID;

        // convert the statsd data to a GA timing event
        data = data.details.a.match(PARSE_STATSD);
        if(data) {
          ga(sendCmd('gaTimingTrackID', gaTrackID), 'timing', {
            'timingCategory': data[2] || 'statsd',
            'timingVar': data[3],
            'timingValue': parseInt(data[4])
          });
        }
      } else if(type === 'event') {
        if(gaEventFilterFn && (fn=pellet.instrumentation.getTransformFn(gaEventFilterFn)) && !(data = fn(data))) {
          return;
        }

        // update the gaTrackID because
        // getTransformFn can update the value
        gaTrackID = data.gaTrackID;

        ga(sendCmd('gaEventTrackID', gaTrackID), 'event', data);
      } else if(type === 'routechange') {

        // for non 2XX status codes fire
        var statusCode = 200;
        if(details.pipeline.statusCode) {
          statusCode = details.pipeline.statusCode();
        }

        if(!pellet.config.gaSyntheticPageUrl || statusCode === 200) {
          ga('set', {
            page: details.originalUrl,
            title: document.title
{'fraction_non_alphanumeric': 0.14182194616977226, 'fraction_numerical': 0.004140786749482402, 'mean_word_length': 2.354861111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '354445', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1473, 'n_words': 288}