<commit_before>/* Code to create the Google Analytics code for a Firefox Screenshots page.
   Stubs out ga() if no gaId is configured
   Disables analytics if Do-Not-Track is set
   Hashes page names
   */

const React = require("react"); // eslint-disable-line no-unused-vars

const dntJs = `
// Copied from https://github.com/mozilla/bedrock/blob/22079855caeb660724319f735de51e3a7472a50f/media/js/base/dnt-helper.js
function _dntEnabled(dnt, ua) {

    'use strict';

    // for old version of IE we need to use the msDoNotTrack property of navigator
    // on newer versions, and newer platforms, this is doNotTrack but, on the window object
    // Safari also exposes the property on the window object.
    var dntStatus = dnt || navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
    var ua = ua || navigator.userAgent;

    // List of Windows versions known to not implement DNT according to the standard.
    var anomalousWinVersions = ['Windows NT 6.1', 'Windows NT 6.2', 'Windows NT 6.3'];

    var fxMatch = ua.match(/Firefox\\/(\\d+)/);
    var ieRegEx = /MSIE|Trident/i;
    var isIE = ieRegEx.test(ua);
    // Matches from Windows up to the first occurance of ; un-greedily
    // http://www.regexr.com/3c2el
    var platform = ua.match(/Windows.+?(?=;)/g);

    // With old versions of IE, DNT did not exist so we simply return false;
    if (isIE && typeof Array.prototype.indexOf !== 'function') {
        return false;
    } else if (fxMatch && parseInt(fxMatch[1], 10) < 32) {
        // Can't say for sure if it is 1 or 0, due to Fx bug 887703
        dntStatus = 'Unspecified';
    } else if (isIE && platform && anomalousWinVersions.indexOf(platform.toString()) !== -1) {
        // default is on, which does not honor the specification
        dntStatus = 'Unspecified';
    } else {
        // sets dntStatus to Disabled or Enabled based on the value returned by the browser.
        // If dntStatus is undefined, it will be set to Unspecified
        dntStatus = { '0': 'Disabled', '1': 'Enabled' }[dntStatus] || 'Unspecified';
    }

    return dntStatus === 'Enabled' ? true : false;
}
`;

const stubGaJs = `
window.ga = function () {
  console.info.apply(console, ["stubbed ga("].concat(Array.from(arguments)).concat([")"]));
};

window.sendEvent = function () {
  console.info.apply(console, ["stubbed sendEvent("].concat(Array.from(arguments)).concat([")"]));
};

window.abTests = __ABTESTS__;
`;

const gaJs = `
(function () {

  ${dntJs}

  if (_dntEnabled()) {
    ${stubGaJs}
    return;
  }
  window.abTests = __ABTESTS__;
  window.GoogleAnalyticsObject = "ga";
  window.ga = window.ga || function () {
    (window.ga.q = window.ga.q || []).push(arguments);
  };
  window.ga.l = 1 * new Date();
  var clientId = "__USER_ID__";
  var gaOptions = "auto";
  var gaLocation;
  if (clientId) {
    gaOptions = {clientId: clientId};
  }
  if (location.hostname === "localhost") {
    if (typeof gaOptions === "string") {
      gaOptions = {};
    }
    gaOptions.cookieDomain = "none";
  }
  if (__HASH_LOCATION__) {
    if (window.crypto) {
      var bytes = [];
      for (var i=0; i<location.pathname.length; i++) {
        bytes.push(location.pathname.charAt(i));
      }
      window.crypto.subtle.digest("sha-256", new Uint8Array(bytes)).then(function (result) {
        result = new Uint8Array(result);
        var c = [];
        for (var i=0; i<10; i++) {
          c.push(result[i].toString(16));
        }
        gaLocation = "/a-shot/" + c.join("");
        finish();
      });
    } else {
      gaLocation = "/a-shot/unknown";
      finish();
    }
  } else {
    gaLocation = null;
    finish();
  }
  function finish() {
    ga("create", "__GA_ID__", gaOptions);
    if (gaLocation) {
      ga("set", "location", gaLocation);
    }
    if (__HASH_LOCATION__) {
      ga("set", "title", "");
    }
    ga("send", "pageview", gaLocation || location.href);
  }
})();

window.sendEvent = function (action, label, options) {
  var event = "web";
  if (typeof label == "object") {<commit_msg>Fix #2717, send only referrer origin to GA<commit_after>/* Code to create the Google Analytics code for a Firefox Screenshots page.
   Stubs out ga() if no gaId is configured
   Disables analytics if Do-Not-Track is set
   Hashes page names
   */

const React = require("react"); // eslint-disable-line no-unused-vars

const dntJs = `
// Copied from https://github.com/mozilla/bedrock/blob/22079855caeb660724319f735de51e3a7472a50f/media/js/base/dnt-helper.js
function _dntEnabled(dnt, ua) {

    'use strict';

    // for old version of IE we need to use the msDoNotTrack property of navigator
    // on newer versions, and newer platforms, this is doNotTrack but, on the window object
    // Safari also exposes the property on the window object.
    var dntStatus = dnt || navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
    var ua = ua || navigator.userAgent;

    // List of Windows versions known to not implement DNT according to the standard.
    var anomalousWinVersions = ['Windows NT 6.1', 'Windows NT 6.2', 'Windows NT 6.3'];

    var fxMatch = ua.match(/Firefox\\/(\\d+)/);
    var ieRegEx = /MSIE|Trident/i;
    var isIE = ieRegEx.test(ua);
    // Matches from Windows up to the first occurance of ; un-greedily
    // http://www.regexr.com/3c2el
    var platform = ua.match(/Windows.+?(?=;)/g);

    // With old versions of IE, DNT did not exist so we simply return false;
    if (isIE && typeof Array.prototype.indexOf !== 'function') {
        return false;
    } else if (fxMatch && parseInt(fxMatch[1], 10) < 32) {
        // Can't say for sure if it is 1 or 0, due to Fx bug 887703
        dntStatus = 'Unspecified';
    } else if (isIE && platform && anomalousWinVersions.indexOf(platform.toString()) !== -1) {
        // default is on, which does not honor the specification
        dntStatus = 'Unspecified';
    } else {
        // sets dntStatus to Disabled or Enabled based on the value returned by the browser.
        // If dntStatus is undefined, it will be set to Unspecified
        dntStatus = { '0': 'Disabled', '1': 'Enabled' }[dntStatus] || 'Unspecified';
    }

    return dntStatus === 'Enabled' ? true : false;
}
`;

const stubGaJs = `
window.ga = function () {
  console.info.apply(console, ["stubbed ga("].concat(Array.from(arguments)).concat([")"]));
};

window.sendEvent = function () {
  console.info.apply(console, ["stubbed sendEvent("].concat(Array.from(arguments)).concat([")"]));
};

window.abTests = __ABTESTS__;
`;

const gaJs = `
(function () {

  ${dntJs}

  if (_dntEnabled()) {
    ${stubGaJs}
    return;
  }
  window.abTests = __ABTESTS__;
  window.GoogleAnalyticsObject = "ga";
  window.ga = window.ga || function () {
    (window.ga.q = window.ga.q || []).push(arguments);
  };
  window.ga.l = 1 * new Date();
  var clientId = "__USER_ID__";
  var gaOptions = "auto";
  var gaLocation;
  if (clientId) {
    gaOptions = {clientId: clientId};
  }
  if (location.hostname === "localhost") {
    if (typeof gaOptions === "string") {
      gaOptions = {};
    }
    gaOptions.cookieDomain = "none";
  }
  if (__HASH_LOCATION__) {
    if (window.crypto) {
      var bytes = [];
      for (var i=0; i<location.pathname.length; i++) {
        bytes.push(location.pathname.charAt(i));
      }
      window.crypto.subtle.digest("sha-256", new Uint8Array(bytes)).then(function (result) {
        result = new Uint8Array(result);
        var c = [];
        for (var i=0; i<10; i++) {
          c.push(result[i].toString(16));
        }
        gaLocation = "/a-shot/" + c.join("");
        finish();
      });
    } else {
      gaLocation = "/a-shot/unknown";
      finish();
    }
  } else {
    gaLocation = null;
    finish();
  }
  function finish() {
    ga("create", "__GA_ID__", gaOptions);
    if (gaLocation) {
      ga("set", "location", gaLocation);
    }
    if (window.URL && document.referrer) {
      ga("set", "referrer", (new URL(document.referrer)).origin);
    } else {
      ga("set", "referrer", "");
    }
    if (__HASH_LOCATION__) {
      ga("set", "title", "");
    }
    ga("send", "pageview", gaLocation || location.href);
  }
})();

window.sendEvent = function (action, label, options) {
  var event = "web";
  if (typeof label == "object") {
{'fraction_non_alphanumeric': 0.15275096525096524, 'fraction_numerical': 0.016167953667953667, 'mean_word_length': 2.8446196660482377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '746101', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2732, 'n_words': 747}