Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

react-ga.js 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("react"), require("prop-types"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["react", "prop-types"], factory);
  6. else {
  7. var a = typeof exports === 'object' ? factory(require("react"), require("prop-types")) : factory(root["react"], root["prop-types"]);
  8. for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
  9. }
  10. })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__13__, __WEBPACK_EXTERNAL_MODULE__14__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 11);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ([
  98. /* 0 */
  99. /***/ (function(module, exports, __webpack_require__) {
  100. "use strict";
  101. Object.defineProperty(exports, "__esModule", {
  102. value: true
  103. });
  104. exports["default"] = warn;
  105. function warn(s) {
  106. console.warn('[react-ga]', s);
  107. }
  108. /***/ }),
  109. /* 1 */
  110. /***/ (function(module, exports, __webpack_require__) {
  111. "use strict";
  112. Object.defineProperty(exports, "__esModule", {
  113. value: true
  114. });
  115. exports["default"] = trim;
  116. // GA strings need to have leading/trailing whitespace trimmed, and not all
  117. // browsers have String.prototoype.trim().
  118. function trim(s) {
  119. return s && s.toString().replace(/^\s+|\s+$/g, '');
  120. }
  121. /***/ }),
  122. /* 2 */
  123. /***/ (function(module, exports, __webpack_require__) {
  124. "use strict";
  125. Object.defineProperty(exports, "__esModule", {
  126. value: true
  127. });
  128. exports.addTrackers = addTrackers;
  129. exports["default"] = void 0;
  130. exports.event = event;
  131. exports.exception = exception;
  132. exports.ga = ga;
  133. exports.initialize = initialize;
  134. exports.modalview = modalview;
  135. exports.outboundLink = outboundLink;
  136. exports.pageview = pageview;
  137. exports.plugin = void 0;
  138. exports.send = send;
  139. exports.set = set;
  140. exports.testModeAPI = void 0;
  141. exports.timing = timing;
  142. var _format2 = _interopRequireDefault(__webpack_require__(3));
  143. var _removeLeadingSlash = _interopRequireDefault(__webpack_require__(7));
  144. var _trim = _interopRequireDefault(__webpack_require__(1));
  145. var _loadGA = _interopRequireDefault(__webpack_require__(8));
  146. var _warn = _interopRequireDefault(__webpack_require__(0));
  147. var _log = _interopRequireDefault(__webpack_require__(9));
  148. var _testModeAPI = _interopRequireDefault(__webpack_require__(10));
  149. var _excluded = ["category", "action", "label", "value", "nonInteraction", "transport"];
  150. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  151. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  152. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  153. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
  154. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
  155. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  156. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  157. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  158. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  159. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  160. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  161. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  162. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  163. var _isNotBrowser = typeof window === 'undefined' || typeof document === 'undefined';
  164. var _debug = false;
  165. var _titleCase = true;
  166. var _testMode = false;
  167. var _alwaysSendToDefaultTracker = true;
  168. var _redactEmail = true;
  169. var internalGa = function internalGa() {
  170. var _window;
  171. if (_testMode) return _testModeAPI["default"].ga.apply(_testModeAPI["default"], arguments);
  172. if (_isNotBrowser) return false;
  173. if (!window.ga) return (0, _warn["default"])('ReactGA.initialize must be called first or GoogleAnalytics should be loaded manually');
  174. return (_window = window).ga.apply(_window, arguments);
  175. };
  176. function _format(s) {
  177. return (0, _format2["default"])(s, _titleCase, _redactEmail);
  178. }
  179. function _gaCommand(trackerNames) {
  180. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  181. args[_key - 1] = arguments[_key];
  182. }
  183. var command = args[0];
  184. if (typeof internalGa === 'function') {
  185. if (typeof command !== 'string') {
  186. (0, _warn["default"])('ga command must be a string');
  187. return;
  188. }
  189. if (_alwaysSendToDefaultTracker || !Array.isArray(trackerNames)) internalGa.apply(void 0, args);
  190. if (Array.isArray(trackerNames)) {
  191. trackerNames.forEach(function (name) {
  192. internalGa.apply(void 0, _toConsumableArray(["".concat(name, ".").concat(command)].concat(args.slice(1))));
  193. });
  194. }
  195. }
  196. }
  197. function _initialize(gaTrackingID, options) {
  198. if (!gaTrackingID) {
  199. (0, _warn["default"])('gaTrackingID is required in initialize()');
  200. return;
  201. }
  202. if (options) {
  203. if (options.debug && options.debug === true) {
  204. _debug = true;
  205. }
  206. if (options.titleCase === false) {
  207. _titleCase = false;
  208. }
  209. if (options.redactEmail === false) {
  210. _redactEmail = false;
  211. }
  212. if (options.useExistingGa) {
  213. return;
  214. }
  215. }
  216. if (options && options.gaOptions) {
  217. internalGa('create', gaTrackingID, options.gaOptions);
  218. } else {
  219. internalGa('create', gaTrackingID, 'auto');
  220. }
  221. }
  222. function addTrackers(configsOrTrackingId, options) {
  223. if (Array.isArray(configsOrTrackingId)) {
  224. configsOrTrackingId.forEach(function (config) {
  225. if (_typeof(config) !== 'object') {
  226. (0, _warn["default"])('All configs must be an object');
  227. return;
  228. }
  229. _initialize(config.trackingId, config);
  230. });
  231. } else {
  232. _initialize(configsOrTrackingId, options);
  233. }
  234. return true;
  235. }
  236. function initialize(configsOrTrackingId, options) {
  237. if (options && options.testMode === true) {
  238. _testMode = true;
  239. } else {
  240. if (_isNotBrowser) {
  241. return;
  242. }
  243. if (!options || options.standardImplementation !== true) (0, _loadGA["default"])(options);
  244. }
  245. _alwaysSendToDefaultTracker = options && typeof options.alwaysSendToDefaultTracker === 'boolean' ? options.alwaysSendToDefaultTracker : true;
  246. addTrackers(configsOrTrackingId, options);
  247. }
  248. /**
  249. * ga:
  250. * Returns the original GA object.
  251. */
  252. function ga() {
  253. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  254. args[_key2] = arguments[_key2];
  255. }
  256. if (args.length > 0) {
  257. internalGa.apply(void 0, args);
  258. if (_debug) {
  259. (0, _log["default"])("called ga('arguments');");
  260. (0, _log["default"])("with arguments: ".concat(JSON.stringify(args)));
  261. }
  262. }
  263. return window.ga;
  264. }
  265. /**
  266. * set:
  267. * GA tracker set method
  268. * @param {Object} fieldsObject - a field/value pair or a group of field/value pairs on the tracker
  269. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  270. */
  271. function set(fieldsObject, trackerNames) {
  272. if (!fieldsObject) {
  273. (0, _warn["default"])('`fieldsObject` is required in .set()');
  274. return;
  275. }
  276. if (_typeof(fieldsObject) !== 'object') {
  277. (0, _warn["default"])('Expected `fieldsObject` arg to be an Object');
  278. return;
  279. }
  280. if (Object.keys(fieldsObject).length === 0) {
  281. (0, _warn["default"])('empty `fieldsObject` given to .set()');
  282. }
  283. _gaCommand(trackerNames, 'set', fieldsObject);
  284. if (_debug) {
  285. (0, _log["default"])("called ga('set', fieldsObject);");
  286. (0, _log["default"])("with fieldsObject: ".concat(JSON.stringify(fieldsObject)));
  287. }
  288. }
  289. /**
  290. * send:
  291. * Clone of the low level `ga.send` method
  292. * WARNING: No validations will be applied to this
  293. * @param {Object} fieldObject - field object for tracking different analytics
  294. * @param {Array} trackerNames - trackers to send the command to
  295. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  296. */
  297. function send(fieldObject, trackerNames) {
  298. _gaCommand(trackerNames, 'send', fieldObject);
  299. if (_debug) {
  300. (0, _log["default"])("called ga('send', fieldObject);");
  301. (0, _log["default"])("with fieldObject: ".concat(JSON.stringify(fieldObject)));
  302. (0, _log["default"])("with trackers: ".concat(JSON.stringify(trackerNames)));
  303. }
  304. }
  305. /**
  306. * pageview:
  307. * Basic GA pageview tracking
  308. * @param {String} path - the current page page e.g. '/about'
  309. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  310. * @param {String} title - (optional) the page title e. g. 'My Website'
  311. */
  312. function pageview(rawPath, trackerNames, title) {
  313. if (!rawPath) {
  314. (0, _warn["default"])('path is required in .pageview()');
  315. return;
  316. }
  317. var path = (0, _trim["default"])(rawPath);
  318. if (path === '') {
  319. (0, _warn["default"])('path cannot be an empty string in .pageview()');
  320. return;
  321. }
  322. var extraFields = {};
  323. if (title) {
  324. extraFields.title = title;
  325. }
  326. if (typeof ga === 'function') {
  327. _gaCommand(trackerNames, 'send', _objectSpread({
  328. hitType: 'pageview',
  329. page: path
  330. }, extraFields));
  331. if (_debug) {
  332. (0, _log["default"])("called ga('send', 'pageview', path);");
  333. var extraLog = '';
  334. if (title) {
  335. extraLog = " and title: ".concat(title);
  336. }
  337. (0, _log["default"])("with path: ".concat(path).concat(extraLog));
  338. }
  339. }
  340. }
  341. /**
  342. * modalview:
  343. * a proxy to basic GA pageview tracking to consistently track
  344. * modal views that are an equivalent UX to a traditional pageview
  345. * @param {String} modalName e.g. 'add-or-edit-club'
  346. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  347. */
  348. function modalview(rawModalName, trackerNames) {
  349. if (!rawModalName) {
  350. (0, _warn["default"])('modalName is required in .modalview(modalName)');
  351. return;
  352. }
  353. var modalName = (0, _removeLeadingSlash["default"])((0, _trim["default"])(rawModalName));
  354. if (modalName === '') {
  355. (0, _warn["default"])('modalName cannot be an empty string or a single / in .modalview()');
  356. return;
  357. }
  358. if (typeof ga === 'function') {
  359. var path = "/modal/".concat(modalName);
  360. _gaCommand(trackerNames, 'send', 'pageview', path);
  361. if (_debug) {
  362. (0, _log["default"])("called ga('send', 'pageview', path);");
  363. (0, _log["default"])("with path: ".concat(path));
  364. }
  365. }
  366. }
  367. /**
  368. * timing:
  369. * GA timing
  370. * @param args.category {String} required
  371. * @param args.variable {String} required
  372. * @param args.value {Int} required
  373. * @param args.label {String} required
  374. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  375. */
  376. function timing() {
  377. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  378. category = _ref.category,
  379. variable = _ref.variable,
  380. value = _ref.value,
  381. label = _ref.label;
  382. var trackerNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
  383. if (typeof ga === 'function') {
  384. if (!category || !variable || typeof value !== 'number') {
  385. (0, _warn["default"])('args.category, args.variable ' + 'AND args.value are required in timing() ' + 'AND args.value has to be a number');
  386. return;
  387. } // Required Fields
  388. var fieldObject = {
  389. hitType: 'timing',
  390. timingCategory: _format(category),
  391. timingVar: _format(variable),
  392. timingValue: value
  393. };
  394. if (label) {
  395. fieldObject.timingLabel = _format(label);
  396. }
  397. send(fieldObject, trackerNames);
  398. }
  399. }
  400. /**
  401. * event:
  402. * GA event tracking
  403. * @param args.category {String} required
  404. * @param args.action {String} required
  405. * @param args.label {String} optional
  406. * @param args.value {Int} optional
  407. * @param args.nonInteraction {boolean} optional
  408. * @param args.transport {string} optional
  409. * @param {{action: string, category: string}} trackerNames - (optional) a list of extra trackers to run the command on
  410. */
  411. function event() {
  412. var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  413. category = _ref2.category,
  414. action = _ref2.action,
  415. label = _ref2.label,
  416. value = _ref2.value,
  417. nonInteraction = _ref2.nonInteraction,
  418. transport = _ref2.transport,
  419. args = _objectWithoutProperties(_ref2, _excluded);
  420. var trackerNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
  421. if (typeof ga === 'function') {
  422. // Simple Validation
  423. if (!category || !action) {
  424. (0, _warn["default"])('args.category AND args.action are required in event()');
  425. return;
  426. } // Required Fields
  427. var fieldObject = {
  428. hitType: 'event',
  429. eventCategory: _format(category),
  430. eventAction: _format(action)
  431. }; // Optional Fields
  432. if (label) {
  433. fieldObject.eventLabel = _format(label);
  434. }
  435. if (typeof value !== 'undefined') {
  436. if (typeof value !== 'number') {
  437. (0, _warn["default"])('Expected `args.value` arg to be a Number.');
  438. } else {
  439. fieldObject.eventValue = value;
  440. }
  441. }
  442. if (typeof nonInteraction !== 'undefined') {
  443. if (typeof nonInteraction !== 'boolean') {
  444. (0, _warn["default"])('`args.nonInteraction` must be a boolean.');
  445. } else {
  446. fieldObject.nonInteraction = nonInteraction;
  447. }
  448. }
  449. if (typeof transport !== 'undefined') {
  450. if (typeof transport !== 'string') {
  451. (0, _warn["default"])('`args.transport` must be a string.');
  452. } else {
  453. if (['beacon', 'xhr', 'image'].indexOf(transport) === -1) {
  454. (0, _warn["default"])('`args.transport` must be either one of these values: `beacon`, `xhr` or `image`');
  455. }
  456. fieldObject.transport = transport;
  457. }
  458. }
  459. Object.keys(args).filter(function (key) {
  460. return key.substr(0, 'dimension'.length) === 'dimension';
  461. }).forEach(function (key) {
  462. fieldObject[key] = args[key];
  463. });
  464. Object.keys(args).filter(function (key) {
  465. return key.substr(0, 'metric'.length) === 'metric';
  466. }).forEach(function (key) {
  467. fieldObject[key] = args[key];
  468. }); // Send to GA
  469. send(fieldObject, trackerNames);
  470. }
  471. }
  472. /**
  473. * exception:
  474. * GA exception tracking
  475. * @param args.description {String} optional
  476. * @param args.fatal {boolean} optional
  477. * @param {Array} trackerNames - (optional) a list of extra trackers to run the command on
  478. */
  479. function exception(_ref3, trackerNames) {
  480. var description = _ref3.description,
  481. fatal = _ref3.fatal;
  482. if (typeof ga === 'function') {
  483. // Required Fields
  484. var fieldObject = {
  485. hitType: 'exception'
  486. }; // Optional Fields
  487. if (description) {
  488. fieldObject.exDescription = _format(description);
  489. }
  490. if (typeof fatal !== 'undefined') {
  491. if (typeof fatal !== 'boolean') {
  492. (0, _warn["default"])('`args.fatal` must be a boolean.');
  493. } else {
  494. fieldObject.exFatal = fatal;
  495. }
  496. } // Send to GA
  497. send(fieldObject, trackerNames);
  498. }
  499. }
  500. var plugin = {
  501. /**
  502. * require:
  503. * GA requires a plugin
  504. * @param name {String} e.g. 'ecommerce' or 'myplugin'
  505. * @param options {Object} optional e.g {path: '/log', debug: true}
  506. * @param trackerName {String} optional e.g 'trackerName'
  507. */
  508. require: function require(rawName, options, trackerName) {
  509. if (typeof ga === 'function') {
  510. // Required Fields
  511. if (!rawName) {
  512. (0, _warn["default"])('`name` is required in .require()');
  513. return;
  514. }
  515. var name = (0, _trim["default"])(rawName);
  516. if (name === '') {
  517. (0, _warn["default"])('`name` cannot be an empty string in .require()');
  518. return;
  519. }
  520. var requireString = trackerName ? "".concat(trackerName, ".require") : 'require'; // Optional Fields
  521. if (options) {
  522. if (_typeof(options) !== 'object') {
  523. (0, _warn["default"])('Expected `options` arg to be an Object');
  524. return;
  525. }
  526. if (Object.keys(options).length === 0) {
  527. (0, _warn["default"])('Empty `options` given to .require()');
  528. }
  529. ga(requireString, name, options);
  530. if (_debug) {
  531. (0, _log["default"])("called ga('require', '".concat(name, "', ").concat(JSON.stringify(options)));
  532. }
  533. } else {
  534. ga(requireString, name);
  535. if (_debug) {
  536. (0, _log["default"])("called ga('require', '".concat(name, "');"));
  537. }
  538. }
  539. }
  540. },
  541. /**
  542. * execute:
  543. * GA execute action for plugin
  544. * Takes variable number of arguments
  545. * @param pluginName {String} e.g. 'ecommerce' or 'myplugin'
  546. * @param action {String} e.g. 'addItem' or 'myCustomAction'
  547. * @param actionType {String} optional e.g. 'detail'
  548. * @param payload {Object} optional e.g { id: '1x5e', name : 'My product to track' }
  549. */
  550. execute: function execute(pluginName, action) {
  551. var payload;
  552. var actionType;
  553. for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
  554. args[_key3 - 2] = arguments[_key3];
  555. }
  556. if (args.length === 1) {
  557. payload = args[0];
  558. } else {
  559. actionType = args[0];
  560. payload = args[1];
  561. }
  562. if (typeof ga === 'function') {
  563. if (typeof pluginName !== 'string') {
  564. (0, _warn["default"])('Expected `pluginName` arg to be a String.');
  565. } else if (typeof action !== 'string') {
  566. (0, _warn["default"])('Expected `action` arg to be a String.');
  567. } else {
  568. var command = "".concat(pluginName, ":").concat(action);
  569. payload = payload || null;
  570. if (actionType && payload) {
  571. ga(command, actionType, payload);
  572. if (_debug) {
  573. (0, _log["default"])("called ga('".concat(command, "');"));
  574. (0, _log["default"])("actionType: \"".concat(actionType, "\" with payload: ").concat(JSON.stringify(payload)));
  575. }
  576. } else if (payload) {
  577. ga(command, payload);
  578. if (_debug) {
  579. (0, _log["default"])("called ga('".concat(command, "');"));
  580. (0, _log["default"])("with payload: ".concat(JSON.stringify(payload)));
  581. }
  582. } else {
  583. ga(command);
  584. if (_debug) {
  585. (0, _log["default"])("called ga('".concat(command, "');"));
  586. }
  587. }
  588. }
  589. }
  590. }
  591. };
  592. /**
  593. * outboundLink:
  594. * GA outboundLink tracking
  595. * @param args.label {String} e.g. url, or 'Create an Account'
  596. * @param {function} hitCallback - Called after processing a hit.
  597. */
  598. exports.plugin = plugin;
  599. function outboundLink(args, hitCallback, trackerNames) {
  600. if (typeof hitCallback !== 'function') {
  601. (0, _warn["default"])('hitCallback function is required');
  602. return;
  603. }
  604. if (typeof ga === 'function') {
  605. // Simple Validation
  606. if (!args || !args.label) {
  607. (0, _warn["default"])('args.label is required in outboundLink()');
  608. return;
  609. } // Required Fields
  610. var fieldObject = {
  611. hitType: 'event',
  612. eventCategory: 'Outbound',
  613. eventAction: 'Click',
  614. eventLabel: _format(args.label)
  615. };
  616. var safetyCallbackCalled = false;
  617. var safetyCallback = function safetyCallback() {
  618. // This prevents a delayed response from GA
  619. // causing hitCallback from being fired twice
  620. safetyCallbackCalled = true;
  621. hitCallback();
  622. }; // Using a timeout to ensure the execution of critical application code
  623. // in the case when the GA server might be down
  624. // or an ad blocker prevents sending the data
  625. // register safety net timeout:
  626. var t = setTimeout(safetyCallback, 250);
  627. var clearableCallbackForGA = function clearableCallbackForGA() {
  628. clearTimeout(t);
  629. if (!safetyCallbackCalled) {
  630. hitCallback();
  631. }
  632. };
  633. fieldObject.hitCallback = clearableCallbackForGA; // Send to GA
  634. send(fieldObject, trackerNames);
  635. } else {
  636. // if ga is not defined, return the callback so the application
  637. // continues to work as expected
  638. setTimeout(hitCallback, 0);
  639. }
  640. }
  641. var testModeAPI = _testModeAPI["default"];
  642. exports.testModeAPI = testModeAPI;
  643. var _default = {
  644. initialize: initialize,
  645. ga: ga,
  646. set: set,
  647. send: send,
  648. pageview: pageview,
  649. modalview: modalview,
  650. timing: timing,
  651. event: event,
  652. exception: exception,
  653. plugin: plugin,
  654. outboundLink: outboundLink,
  655. testModeAPI: _testModeAPI["default"]
  656. };
  657. exports["default"] = _default;
  658. /***/ }),
  659. /* 3 */
  660. /***/ (function(module, exports, __webpack_require__) {
  661. "use strict";
  662. Object.defineProperty(exports, "__esModule", {
  663. value: true
  664. });
  665. exports["default"] = format;
  666. var _redactEmail = _interopRequireDefault(__webpack_require__(4));
  667. var _toTitleCase = _interopRequireDefault(__webpack_require__(6));
  668. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  669. function format() {
  670. var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  671. var titleCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  672. var redactingEmail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  673. var _str = s || '';
  674. if (titleCase) {
  675. _str = (0, _toTitleCase["default"])(s);
  676. }
  677. if (redactingEmail) {
  678. _str = (0, _redactEmail["default"])(_str);
  679. }
  680. return _str;
  681. }
  682. /***/ }),
  683. /* 4 */
  684. /***/ (function(module, exports, __webpack_require__) {
  685. "use strict";
  686. Object.defineProperty(exports, "__esModule", {
  687. value: true
  688. });
  689. exports["default"] = redactEmail;
  690. var _warn = _interopRequireDefault(__webpack_require__(0));
  691. var _mightBeEmail = _interopRequireDefault(__webpack_require__(5));
  692. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  693. var redacted = 'REDACTED (Potential Email Address)';
  694. function redactEmail(string) {
  695. if ((0, _mightBeEmail["default"])(string)) {
  696. (0, _warn["default"])('This arg looks like an email address, redacting.');
  697. return redacted;
  698. }
  699. return string;
  700. }
  701. /***/ }),
  702. /* 5 */
  703. /***/ (function(module, exports, __webpack_require__) {
  704. "use strict";
  705. Object.defineProperty(exports, "__esModule", {
  706. value: true
  707. });
  708. exports["default"] = mightBeEmail;
  709. // See if s could be an email address. We don't want to send personal data like email.
  710. // https://support.google.com/analytics/answer/2795983?hl=en
  711. function mightBeEmail(s) {
  712. // There's no point trying to validate rfc822 fully, just look for ...@...
  713. return typeof s === 'string' && s.indexOf('@') !== -1;
  714. }
  715. /***/ }),
  716. /* 6 */
  717. /***/ (function(module, exports, __webpack_require__) {
  718. "use strict";
  719. Object.defineProperty(exports, "__esModule", {
  720. value: true
  721. });
  722. exports["default"] = toTitleCase;
  723. var _trim = _interopRequireDefault(__webpack_require__(1));
  724. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  725. /**
  726. * To Title Case 2.1 - http://individed.com/code/to-title-case/
  727. * Copyright 2008-2013 David Gouch. Licensed under the MIT License.
  728. * https://github.com/gouch/to-title-case
  729. */
  730. var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i; // test
  731. function toTitleCase(string) {
  732. return (0, _trim["default"])(string).replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function (match, index, title) {
  733. if (index > 0 && index + match.length !== title.length && match.search(smallWords) > -1 && title.charAt(index - 2) !== ':' && (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') && title.charAt(index - 1).search(/[^\s-]/) < 0) {
  734. return match.toLowerCase();
  735. }
  736. if (match.substr(1).search(/[A-Z]|\../) > -1) {
  737. return match;
  738. }
  739. return match.charAt(0).toUpperCase() + match.substr(1);
  740. });
  741. }
  742. /***/ }),
  743. /* 7 */
  744. /***/ (function(module, exports, __webpack_require__) {
  745. "use strict";
  746. Object.defineProperty(exports, "__esModule", {
  747. value: true
  748. });
  749. exports["default"] = removeLeadingSlash;
  750. function removeLeadingSlash(string) {
  751. if (string.substring(0, 1) === '/') {
  752. return string.substring(1);
  753. }
  754. return string;
  755. }
  756. /***/ }),
  757. /* 8 */
  758. /***/ (function(module, exports, __webpack_require__) {
  759. "use strict";
  760. Object.defineProperty(exports, "__esModule", {
  761. value: true
  762. });
  763. exports["default"] = _default;
  764. var isLoaded = false;
  765. function _default(options) {
  766. if (isLoaded) return;
  767. isLoaded = true;
  768. var gaAddress = 'https://www.google-analytics.com/analytics.js';
  769. if (options && options.gaAddress) {
  770. gaAddress = options.gaAddress;
  771. } else if (options && options.debug) {
  772. gaAddress = 'https://www.google-analytics.com/analytics_debug.js';
  773. }
  774. var onerror = options && options.onerror; // https://developers.google.com/analytics/devguides/collection/analyticsjs/
  775. /* eslint-disable */
  776. (function (i, s, o, g, r, a, m) {
  777. i['GoogleAnalyticsObject'] = r;
  778. i[r] = i[r] || function () {
  779. (i[r].q = i[r].q || []).push(arguments);
  780. }, i[r].l = 1 * new Date();
  781. a = s.createElement(o), m = s.getElementsByTagName(o)[0];
  782. a.async = 1;
  783. a.src = g;
  784. a.onerror = onerror;
  785. m.parentNode.insertBefore(a, m);
  786. })(window, document, 'script', gaAddress, 'ga');
  787. /* eslint-enable */
  788. }
  789. /***/ }),
  790. /* 9 */
  791. /***/ (function(module, exports, __webpack_require__) {
  792. "use strict";
  793. Object.defineProperty(exports, "__esModule", {
  794. value: true
  795. });
  796. exports["default"] = log;
  797. function log(s) {
  798. console.info('[react-ga]', s);
  799. }
  800. /***/ }),
  801. /* 10 */
  802. /***/ (function(module, exports, __webpack_require__) {
  803. "use strict";
  804. Object.defineProperty(exports, "__esModule", {
  805. value: true
  806. });
  807. exports.gaCalls = exports["default"] = void 0;
  808. var gaCalls = [];
  809. exports.gaCalls = gaCalls;
  810. var _default = {
  811. calls: gaCalls,
  812. ga: function ga() {
  813. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  814. args[_key] = arguments[_key];
  815. }
  816. gaCalls.push([].concat(args));
  817. },
  818. resetCalls: function resetCalls() {
  819. gaCalls.length = 0;
  820. }
  821. };
  822. exports["default"] = _default;
  823. /***/ }),
  824. /* 11 */
  825. /***/ (function(module, exports, __webpack_require__) {
  826. "use strict";
  827. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  828. Object.defineProperty(exports, "__esModule", {
  829. value: true
  830. });
  831. exports.timing = exports.testModeAPI = exports.set = exports.send = exports.plugin = exports.pageview = exports.outboundLink = exports.modalview = exports.initialize = exports.ga = exports.exception = exports.event = exports["default"] = exports.addTrackers = exports.OutboundLink = void 0;
  832. var _OutboundLink = _interopRequireDefault(__webpack_require__(12));
  833. var Defaults = _interopRequireWildcard(__webpack_require__(2));
  834. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  835. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  836. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  837. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
  838. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
  839. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  840. var initialize = Defaults.initialize;
  841. exports.initialize = initialize;
  842. var addTrackers = Defaults.addTrackers;
  843. exports.addTrackers = addTrackers;
  844. var ga = Defaults.ga;
  845. exports.ga = ga;
  846. var set = Defaults.set;
  847. exports.set = set;
  848. var send = Defaults.send;
  849. exports.send = send;
  850. var pageview = Defaults.pageview;
  851. exports.pageview = pageview;
  852. var modalview = Defaults.modalview;
  853. exports.modalview = modalview;
  854. var timing = Defaults.timing;
  855. exports.timing = timing;
  856. var event = Defaults.event;
  857. exports.event = event;
  858. var exception = Defaults.exception;
  859. exports.exception = exception;
  860. var plugin = Defaults.plugin;
  861. exports.plugin = plugin;
  862. var outboundLink = Defaults.outboundLink;
  863. exports.outboundLink = outboundLink;
  864. var testModeAPI = Defaults.testModeAPI;
  865. exports.testModeAPI = testModeAPI;
  866. _OutboundLink["default"].origTrackLink = _OutboundLink["default"].trackLink;
  867. _OutboundLink["default"].trackLink = Defaults.outboundLink;
  868. var OutboundLink = _OutboundLink["default"];
  869. exports.OutboundLink = OutboundLink;
  870. var _default = _objectSpread(_objectSpread({}, Defaults), {}, {
  871. OutboundLink: OutboundLink
  872. });
  873. exports["default"] = _default;
  874. /***/ }),
  875. /* 12 */
  876. /***/ (function(module, exports, __webpack_require__) {
  877. "use strict";
  878. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  879. Object.defineProperty(exports, "__esModule", {
  880. value: true
  881. });
  882. exports["default"] = void 0;
  883. var _react = _interopRequireWildcard(__webpack_require__(13));
  884. var _propTypes = _interopRequireDefault(__webpack_require__(14));
  885. var _warn = _interopRequireDefault(__webpack_require__(0));
  886. var _excluded = ["to", "target"];
  887. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  888. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  889. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  890. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
  891. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
  892. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  893. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  894. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  895. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  896. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  897. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  898. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  899. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  900. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  901. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  902. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  903. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  904. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  905. var NEWTAB = '_blank';
  906. var MIDDLECLICK = 1;
  907. var OutboundLink = /*#__PURE__*/function (_Component) {
  908. _inherits(OutboundLink, _Component);
  909. var _super = _createSuper(OutboundLink);
  910. function OutboundLink() {
  911. var _this;
  912. _classCallCheck(this, OutboundLink);
  913. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  914. args[_key] = arguments[_key];
  915. }
  916. _this = _super.call.apply(_super, [this].concat(args));
  917. _defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
  918. var _this$props = _this.props,
  919. target = _this$props.target,
  920. eventLabel = _this$props.eventLabel,
  921. to = _this$props.to,
  922. onClick = _this$props.onClick,
  923. trackerNames = _this$props.trackerNames;
  924. var eventMeta = {
  925. label: eventLabel
  926. };
  927. var sameTarget = target !== NEWTAB;
  928. var normalClick = !(event.ctrlKey || event.shiftKey || event.metaKey || event.button === MIDDLECLICK);
  929. if (sameTarget && normalClick) {
  930. event.preventDefault();
  931. OutboundLink.trackLink(eventMeta, function () {
  932. window.location.href = to;
  933. }, trackerNames);
  934. } else {
  935. OutboundLink.trackLink(eventMeta, function () {}, trackerNames);
  936. }
  937. if (onClick) {
  938. onClick(event);
  939. }
  940. });
  941. return _this;
  942. }
  943. _createClass(OutboundLink, [{
  944. key: "render",
  945. value: function render() {
  946. var _this$props2 = this.props,
  947. href = _this$props2.to,
  948. target = _this$props2.target,
  949. oldProps = _objectWithoutProperties(_this$props2, _excluded);
  950. var props = _objectSpread(_objectSpread({}, oldProps), {}, {
  951. target: target,
  952. href: href,
  953. onClick: this.handleClick
  954. });
  955. if (target === NEWTAB) {
  956. props.rel = "".concat(props.rel ? props.rel : '', " noopener noreferrer").trim();
  957. }
  958. delete props.eventLabel;
  959. delete props.trackerNames;
  960. return /*#__PURE__*/_react["default"].createElement('a', props);
  961. }
  962. }]);
  963. return OutboundLink;
  964. }(_react.Component);
  965. exports["default"] = OutboundLink;
  966. _defineProperty(OutboundLink, "trackLink", function () {
  967. (0, _warn["default"])('ga tracking not enabled');
  968. });
  969. OutboundLink.propTypes = {
  970. eventLabel: _propTypes["default"].string.isRequired,
  971. target: _propTypes["default"].string,
  972. to: _propTypes["default"].string,
  973. onClick: _propTypes["default"].func,
  974. trackerNames: _propTypes["default"].arrayOf(_propTypes["default"].string)
  975. };
  976. OutboundLink.defaultProps = {
  977. target: null,
  978. to: null,
  979. onClick: null,
  980. trackerNames: null
  981. };
  982. /***/ }),
  983. /* 13 */
  984. /***/ (function(module, exports) {
  985. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  986. /***/ }),
  987. /* 14 */
  988. /***/ (function(module, exports) {
  989. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  990. /***/ })
  991. /******/ ]);
  992. });