@codecademy/tracking 0.25.1-alpha.1a54e4.0 → 0.25.1-alpha.42681.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,6 @@
1
- @codecademy/tracking:build: cache hit, replaying output 216c90d217c37b75
1
+ @codecademy/tracking:build: cache hit, replaying output f545e66ede74e142
2
2
  @codecademy/tracking:build: $ yarn build:clean && yarn build:compile && yarn build:types
3
3
  @codecademy/tracking:build: $ rm -rf dist
4
4
  @codecademy/tracking:build: $ babel ./src --out-dir ./dist --copy-files --extensions ".ts,.tsx"
5
- @codecademy/tracking:build: Browserslist: caniuse-lite is outdated. Please run:
6
- @codecademy/tracking:build: npx browserslist@latest --update-db
7
- @codecademy/tracking:build: 
8
- @codecademy/tracking:build: Why you should do it regularly:
9
- @codecademy/tracking:build: https://github.com/browserslist/browserslist#browsers-data-updating
10
- @codecademy/tracking:build: Successfully compiled 18 files with Babel (1747ms).
5
+ @codecademy/tracking:build: Successfully compiled 18 files with Babel (2184ms).
11
6
  @codecademy/tracking:build: $ tsc --emitDeclarationOnly
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ### [0.25.1-alpha.1a54e4.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.1a54e4.0) (2022-10-20)
6
+ ### [0.25.1-alpha.42681.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.42681.0) (2022-10-21)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/tracking
9
9
 
@@ -1,13 +1,8 @@
1
- var _class, _temp;
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
1
+ var _class;
2
+ 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; }
3
+ 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; }
7
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
5
  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; }
10
-
11
6
  import { createTracker } from '../track';
12
7
  var apiBaseUrl = 'https://www.codecademy.com';
13
8
  var fakeWindow = {
@@ -29,9 +24,9 @@ Object.defineProperties(window, {
29
24
  value: fakeWindow.location
30
25
  },
31
26
  Request: {
32
- value: (_temp = _class = function MockRequest() {
27
+ value: (_class = function MockRequest() {
33
28
  _classCallCheck(this, MockRequest);
34
- }, _defineProperty(_class, "keepalive", true), _temp)
29
+ }, _defineProperty(_class, "keepalive", true), _class)
35
30
  }
36
31
  });
37
32
  Object.defineProperty(window.document, 'title', {
@@ -46,7 +41,6 @@ jest.mock('../../integrations/device', function () {
46
41
  get getClientType() {
47
42
  return mockClientType;
48
43
  }
49
-
50
44
  };
51
45
  });
52
46
  describe('createTracker', function () {
@@ -129,7 +123,6 @@ describe('createTracker', function () {
129
123
  });
130
124
  });
131
125
  };
132
-
133
126
  describeEvent('click');
134
127
  describeEvent('impression');
135
128
  describeEvent('visit');
@@ -1,9 +1,6 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
2
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
4
  import fetch from 'fetch-mock';
8
5
  import { fetchUser } from '../user';
9
6
  var apiBaseUrl = 'https://www.codecademy.com';
@@ -23,7 +20,6 @@ describe('fetchUser', function () {
23
20
  fetch.getOnce('*', JSON.stringify(authUser));
24
21
  _context.next = 3;
25
22
  return fetchUser(apiBaseUrl);
26
-
27
23
  case 3:
28
24
  user = _context.sent;
29
25
  expect(user).toEqual(authUser);
@@ -31,7 +27,6 @@ describe('fetchUser', function () {
31
27
  expect(fetch.calls()[0][0]).toBe("".concat(apiBaseUrl, "/users/web"));
32
28
  expect(fetch.calls()[0][1].method).toBe('GET');
33
29
  expect(fetch.calls()[0][1].credentials).toBe('include');
34
-
35
30
  case 9:
36
31
  case "end":
37
32
  return _context.stop();
@@ -1,46 +1,31 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
1
+ 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; }
2
+ 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; }
5
3
  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; }
6
-
7
4
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
-
9
5
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
6
  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); }
12
-
13
7
  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; }
14
-
15
- function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
16
-
8
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
9
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
-
19
10
  import { getClientType } from '../integrations/device';
20
11
  /* eslint-disable no-console */
21
12
 
22
13
  var browserSupportsKeepalive = function browserSupportsKeepalive() {
23
14
  return 'keepalive' in window.Request.prototype;
24
15
  };
25
-
26
16
  export var createTracker = function createTracker(_ref) {
27
17
  var apiBaseUrl = _ref.apiBaseUrl,
28
- verbose = _ref.verbose;
29
-
18
+ verbose = _ref.verbose;
30
19
  var beacon = function beacon(endpoint, data) {
31
20
  var uri = new URL(endpoint, apiBaseUrl).toString();
32
21
  var form = new FormData();
33
-
34
22
  for (var _i2 = 0, _Object$entries = Object.entries(data); _i2 < _Object$entries.length; _i2++) {
35
23
  var _ref4 = _Object$entries[_i2];
36
-
37
24
  var _ref3 = _slicedToArray(_ref4, 2);
38
-
39
25
  var k = _ref3[0];
40
26
  var v = _ref3[1];
41
27
  form.append(k, v.toString());
42
28
  }
43
-
44
29
  try {
45
30
  // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
46
31
  // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
@@ -49,12 +34,13 @@ export var createTracker = function createTracker(_ref) {
49
34
  if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
50
35
  return;
51
36
  }
52
- } catch (_unused) {// Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
53
- } // Either way, we fall back to standard fetch if sendBeacon fails.
37
+ } catch (_unused) {
38
+ // Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
39
+ }
40
+
41
+ // Either way, we fall back to standard fetch if sendBeacon fails.
54
42
  // We don't mind this rejecting with an error because it's tracking, and we'll know if that starts to fail.
55
43
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
56
-
57
-
58
44
  window.fetch(uri, _objectSpread({
59
45
  method: 'POST',
60
46
  body: form
@@ -62,10 +48,8 @@ export var createTracker = function createTracker(_ref) {
62
48
  keepalive: true
63
49
  }));
64
50
  };
65
-
66
51
  var event = function event(category, _event, userData) {
67
52
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
68
-
69
53
  var properties = _objectSpread(_objectSpread({}, userData), {}, {
70
54
  fullpath: window.location.pathname + window.location.search,
71
55
  search: window.location.search,
@@ -75,7 +59,6 @@ export var createTracker = function createTracker(_ref) {
75
59
  referrer: userData.referrer || window.document.referrer,
76
60
  client: getClientType()
77
61
  });
78
-
79
62
  if (verbose) {
80
63
  console.groupCollapsed("%cTracking Event Fired: ".concat(category, ":").concat(_event), 'color: #4b35ef; font-style: italic;');
81
64
  console.log({
@@ -84,9 +67,9 @@ export var createTracker = function createTracker(_ref) {
84
67
  properties: properties
85
68
  });
86
69
  console.groupEnd();
87
- } // This allows the UTM query params to get registered in the user session.
88
-
70
+ }
89
71
 
72
+ // This allows the UTM query params to get registered in the user session.
90
73
  var queryParams = window.location.search;
91
74
  beacon("/analytics/".concat(category).concat(queryParams), {
92
75
  category: category,
@@ -95,7 +78,6 @@ export var createTracker = function createTracker(_ref) {
95
78
  gdpr_safe: "".concat(options.gdprSafe)
96
79
  });
97
80
  };
98
-
99
81
  return {
100
82
  event: event,
101
83
  click: function click(data) {
@@ -109,7 +91,6 @@ export var createTracker = function createTracker(_ref) {
109
91
  },
110
92
  pushDataLayerEvent: function pushDataLayerEvent(eventName) {
111
93
  var _ref5;
112
-
113
94
  ((_ref5 = window).dataLayer || (_ref5.dataLayer = [])).push({
114
95
  event: eventName
115
96
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,6 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
2
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
4
  export var fetchUser = /*#__PURE__*/function () {
8
5
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(apiBaseUrl) {
9
6
  var response;
@@ -20,11 +17,9 @@ export var fetchUser = /*#__PURE__*/function () {
20
17
  },
21
18
  credentials: 'include'
22
19
  });
23
-
24
20
  case 2:
25
21
  response = _context.sent;
26
22
  return _context.abrupt("return", response.json());
27
-
28
23
  case 4:
29
24
  case "end":
30
25
  return _context.stop();
@@ -32,7 +27,6 @@ export var fetchUser = /*#__PURE__*/function () {
32
27
  }
33
28
  }, _callee);
34
29
  }));
35
-
36
30
  return function fetchUser(_x) {
37
31
  return _ref.apply(this, arguments);
38
32
  };
@@ -1,20 +1,17 @@
1
1
  import { getClientType } from './device';
2
2
  export var conditionallyLoadAnalytics = function conditionallyLoadAnalytics(_ref) {
3
3
  var analytics = _ref.analytics,
4
- destinationPreferences = _ref.destinationPreferences,
5
- identifyPreferences = _ref.identifyPreferences,
6
- user = _ref.user,
7
- writeKey = _ref.writeKey;
8
-
4
+ destinationPreferences = _ref.destinationPreferences,
5
+ identifyPreferences = _ref.identifyPreferences,
6
+ user = _ref.user,
7
+ writeKey = _ref.writeKey;
9
8
  if (analytics.initialize) {
10
9
  return;
11
10
  }
12
-
13
11
  analytics.load(writeKey, {
14
12
  integrations: destinationPreferences
15
13
  });
16
14
  analytics.page();
17
-
18
15
  if (user) {
19
16
  var identifyParams = {
20
17
  email: user.email,
@@ -2,7 +2,6 @@
2
2
  * @see https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41
3
3
  */
4
4
  export var Consent;
5
-
6
5
  (function (Consent) {
7
6
  Consent["Functional"] = "C0003";
8
7
  Consent["Performance"] = "C0002";
@@ -2,24 +2,24 @@
2
2
  * @returns Whether the site is running both in ChromeOS and in PWA mode.
3
3
  */
4
4
  export var isChromeOSPWA = function isChromeOSPWA() {
5
- return isChromeOS() && 'getDigitalGoodsService' in window && // https://stackoverflow.com/questions/41742390/javascript-to-check-if-pwa-or-mobile-web
5
+ return isChromeOS() && 'getDigitalGoodsService' in window &&
6
+ // https://stackoverflow.com/questions/41742390/javascript-to-check-if-pwa-or-mobile-web
6
7
  window.matchMedia('(display-mode: standalone)').matches;
7
8
  };
9
+
8
10
  /**
9
11
  * @returns Whether the site is running in ChromeOS
10
12
  */
11
-
12
13
  export var isChromeOS = function isChromeOS() {
13
- return typeof navigator !== 'undefined' && // https://stackoverflow.com/questions/29657165/detecting-chrome-os-with-javascript
14
+ return typeof navigator !== 'undefined' &&
15
+ // https://stackoverflow.com/questions/29657165/detecting-chrome-os-with-javascript
14
16
  /\bCrOS\b/.test(navigator.userAgent);
15
17
  };
16
18
  export var ClientTypes;
17
-
18
19
  (function (ClientTypes) {
19
20
  ClientTypes["PWA"] = "pwa";
20
21
  ClientTypes["Default"] = "default";
21
22
  })(ClientTypes || (ClientTypes = {}));
22
-
23
23
  export var getClientType = function getClientType() {
24
24
  return isChromeOSPWA() ? ClientTypes.PWA : ClientTypes.Default;
25
25
  };
@@ -1,26 +1,18 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4
-
5
3
  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); }
6
-
7
4
  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; }
8
-
9
5
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
-
11
6
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
12
-
13
7
  var knownFetchFailures = ['Failed to fetch', 'Load failed', 'NetworkError when attempting to fetch resource', 'Resource blocked by content blocker'];
14
8
  export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
15
9
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
16
10
  var writeKey, onError, filteredOnError, response, destinations, _iterator, _step, destination;
17
-
18
11
  return _regeneratorRuntime.wrap(function _callee$(_context) {
19
12
  while (1) {
20
13
  switch (_context.prev = _context.next) {
21
14
  case 0:
22
15
  writeKey = _ref.writeKey, onError = _ref.onError;
23
-
24
16
  filteredOnError = function filteredOnError(error) {
25
17
  if (!knownFetchFailures.some(function (failure) {
26
18
  return error.includes(failure);
@@ -28,30 +20,23 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
28
20
  onError(error);
29
21
  }
30
22
  };
31
-
32
23
  _context.prev = 2;
33
24
  _context.next = 5;
34
25
  return fetch("https://cdn.segment.com/v1/projects/".concat(writeKey, "/integrations"));
35
-
36
26
  case 5:
37
27
  response = _context.sent;
38
-
39
28
  if (response.ok) {
40
29
  _context.next = 9;
41
30
  break;
42
31
  }
43
-
44
32
  filteredOnError("Failed to fetch integrations for write key ".concat(writeKey, ": HTTP ").concat(response.status, " ").concat(response.statusText));
45
33
  return _context.abrupt("return", []);
46
-
47
34
  case 9:
48
35
  _context.next = 11;
49
36
  return response.json();
50
-
51
37
  case 11:
52
38
  destinations = _context.sent;
53
39
  _iterator = _createForOfIteratorHelper(destinations);
54
-
55
40
  try {
56
41
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
42
  destination = _step.value;
@@ -63,15 +48,12 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
63
48
  } finally {
64
49
  _iterator.f();
65
50
  }
66
-
67
51
  return _context.abrupt("return", destinations);
68
-
69
52
  case 17:
70
53
  _context.prev = 17;
71
54
  _context.t0 = _context["catch"](2);
72
55
  filteredOnError("Unknown error fetching Segment destinations for write key ".concat(writeKey, ": ").concat(_context.t0));
73
56
  return _context.abrupt("return", []);
74
-
75
57
  case 21:
76
58
  case "end":
77
59
  return _context.stop();
@@ -79,7 +61,6 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
79
61
  }
80
62
  }, _callee, null, [[2, 17]]);
81
63
  }));
82
-
83
64
  return function fetchDestinationsForWriteKey(_x) {
84
65
  return _ref2.apply(this, arguments);
85
66
  };
@@ -1,22 +1,17 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
2
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
4
  import { conditionallyLoadAnalytics } from './conditionallyLoadAnalytics';
8
5
  import { fetchDestinationsForWriteKey } from './fetchDestinationsForWriteKey';
9
6
  import { mapDestinations } from './mapDestinations';
10
7
  import { initializeOneTrust } from './onetrust';
11
8
  import { runSegmentSnippet } from './runSegmentSnippet';
12
-
13
9
  /**
14
10
  * @see README.md for details and usage.
15
11
  */
16
12
  export var initializeTrackingIntegrations = /*#__PURE__*/function () {
17
13
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
18
14
  var onError, production, scope, user, writeKey, destinations, _mapDestinations, destinationPreferences, identifyPreferences;
19
-
20
15
  return _regeneratorRuntime.wrap(function _callee$(_context) {
21
16
  while (1) {
22
17
  switch (_context.prev = _context.next) {
@@ -26,41 +21,35 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
26
21
  return new Promise(function (resolve) {
27
22
  return setTimeout(resolve, 1000);
28
23
  });
29
-
30
24
  case 3:
31
25
  _context.next = 5;
32
26
  return initializeOneTrust({
33
27
  scope: scope,
34
28
  production: production
35
29
  });
36
-
37
30
  case 5:
38
31
  // 3. Segment's copy-and-paste snippet is run to load the Segment global library
39
- runSegmentSnippet(); // 4. Destination integrations for Segment are fetched
32
+ runSegmentSnippet();
40
33
 
34
+ // 4. Destination integrations for Segment are fetched
41
35
  _context.next = 8;
42
36
  return fetchDestinationsForWriteKey({
43
37
  onError: onError,
44
38
  writeKey: writeKey
45
39
  });
46
-
47
40
  case 8:
48
41
  destinations = _context.sent;
49
-
50
42
  if (destinations) {
51
43
  _context.next = 11;
52
44
  break;
53
45
  }
54
-
55
46
  return _context.abrupt("return");
56
-
57
47
  case 11:
58
48
  // 5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
59
49
  _mapDestinations = mapDestinations({
60
50
  consentDecision: scope.OnetrustActiveGroups,
61
51
  destinations: destinations
62
52
  }), destinationPreferences = _mapDestinations.destinationPreferences, identifyPreferences = _mapDestinations.identifyPreferences; // 6. We load only those allowed destinations using Segment's `analytics.load`
63
-
64
53
  conditionallyLoadAnalytics({
65
54
  analytics: scope.analytics,
66
55
  destinationPreferences: destinationPreferences,
@@ -68,7 +57,6 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
68
57
  user: user,
69
58
  writeKey: writeKey
70
59
  });
71
-
72
60
  case 13:
73
61
  case "end":
74
62
  return _context.stop();
@@ -76,7 +64,6 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
76
64
  }
77
65
  }, _callee);
78
66
  }));
79
-
80
67
  return function initializeTrackingIntegrations(_x) {
81
68
  return _ref2.apply(this, arguments);
82
69
  };
@@ -1,45 +1,35 @@
1
1
  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; }
2
-
3
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
-
5
3
  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."); }
6
-
7
4
  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); }
8
-
9
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
-
11
6
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
-
13
7
  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; }
14
-
15
8
  import { Consent } from './consent';
16
9
  // The Functional category may need to be added here in the future.
17
10
  var targetingCategories = ['Advertising', 'Attribution', 'Email Marketing'];
18
11
  var performanceCategories = ['Analytics', 'Customer Success', 'Surveys', 'Heatmaps & Recording'];
19
12
  var functionalCategories = ['SMS & Push Notifications'];
13
+
20
14
  /**
21
15
  * @see https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41
22
16
  */
23
-
24
17
  export var mapDestinations = function mapDestinations(_ref) {
25
18
  var _ref$consentDecision = _ref.consentDecision,
26
- consentDecision = _ref$consentDecision === void 0 ? [Consent.StrictlyNecessary] : _ref$consentDecision,
27
- destinations = _ref.destinations;
19
+ consentDecision = _ref$consentDecision === void 0 ? [Consent.StrictlyNecessary] : _ref$consentDecision,
20
+ destinations = _ref.destinations;
28
21
  var destinationPreferences = Object.assign.apply(Object, [{
29
22
  'Segment.io': consentDecision.includes(Consent.Functional)
30
23
  }].concat(_toConsumableArray(destinations.map(function (dest) {
31
24
  if (targetingCategories.includes(dest.category)) {
32
25
  return _defineProperty({}, dest.id, consentDecision.includes(Consent.Targeting));
33
26
  }
34
-
35
27
  if (performanceCategories.includes(dest.category)) {
36
28
  return _defineProperty({}, dest.id, consentDecision.includes(Consent.Performance));
37
29
  }
38
-
39
30
  if (functionalCategories.includes(dest.category)) {
40
31
  return _defineProperty({}, dest.id, consentDecision.includes(Consent.Functional));
41
32
  }
42
-
43
33
  return _defineProperty({}, dest.id, true);
44
34
  }))));
45
35
  var identifyPreferences = {
@@ -1,9 +1,6 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
2
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
4
  export var initializeOneTrust = /*#__PURE__*/function () {
8
5
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
9
6
  var production, scope, script, style;
@@ -24,7 +21,6 @@ export var initializeOneTrust = /*#__PURE__*/function () {
24
21
  return _context.abrupt("return", new Promise(function (resolve) {
25
22
  scope.OptanonWrapper = function () {
26
23
  var _scope$dataLayer, _script$parentNode;
27
-
28
24
  (_scope$dataLayer = scope.dataLayer) !== null && _scope$dataLayer !== void 0 ? _scope$dataLayer : scope.dataLayer = [];
29
25
  scope.dataLayer.push({
30
26
  event: 'OneTrustGroupsUpdated'
@@ -33,7 +29,6 @@ export var initializeOneTrust = /*#__PURE__*/function () {
33
29
  (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
34
30
  };
35
31
  }));
36
-
37
32
  case 11:
38
33
  case "end":
39
34
  return _context.stop();
@@ -41,11 +36,11 @@ export var initializeOneTrust = /*#__PURE__*/function () {
41
36
  }
42
37
  }, _callee);
43
38
  }));
44
-
45
39
  return function initializeOneTrust(_x) {
46
40
  return _ref2.apply(this, arguments);
47
41
  };
48
- }(); // For now, these three values duplicate theme colors from gamut-styles
49
- // We don't want to take a full dependency on that package here...
42
+ }();
50
43
 
44
+ // For now, these three values duplicate theme colors from gamut-styles
45
+ // We don't want to take a full dependency on that package here...
51
46
  var rawStyles = "\n:root {\n --onetrust-brand-purple: #3A10E5;\n --onetrust-color-gray-500: #828285;\n --onetrust-color-white: #fff;\n}\n\n#onetrust-banner-sdk {\n padding: 1rem !important;\n}\n#onetrust-banner-sdk > .ot-sdk-container {\n width: 100% !important;\n}\n#onetrust-banner-sdk > .ot-sdk-container > .ot-sdk-row {\n display: flex !important;\n flex-direction: column !important;\n align-items: center !important;\n max-width: 1436px !important;\n margin: 0 auto !important;\n}\n#onetrust-banner-sdk > .ot-sdk-container > .ot-sdk-row:after {\n content: none !important;\n}\n#onetrust-group-container {\n display: flex !important;\n justify-content: center;\n float: none !important;\n width: 100% !important;\n max-width: 1148px !important;\n margin-left: 0 !important;\n margin-bottom: 0.625rem !important;\n}\n#onetrust-policy,\n#onetrust-policy-text {\n margin: 0 !important;\n font-size: 0.875rem !important;\n line-height: 1.375rem !important;\n text-align: center !important;\n float: none !important;\n}\n#onetrust-policy-text a {\n text-decoration: none;\n line-height: 26px !important;\n margin-left: 0 !important;\n}\n#onetrust-button-group-parent {\n position: relative !important;\n top: initial !important;\n left: initial !important;\n transform: initial !important;\n width: 264px !important;\n margin: 0 !important;\n padding: 0 !important;\n float: none !important;\n}\n#onetrust-button-group {\n display: flex !important;\n margin: 0 !important;\n}\n#onetrust-pc-btn-handler, #onetrust-accept-btn-handler {\n min-width: initial !important;\n padding: 0.375rem 1rem !important;\n margin: 0 !important;\n opacity: 1 !important;\n border-radius: 2px !important;\n line-height: 1.5 !important;\n user-select: none !important;\n font-size: 1rem !important;\n}\n#onetrust-pc-btn-handler:focus, #onetrust-accept-btn-handler:focus {\n box-shadow: 0 0 0 2px var(--onetrust-color-white), 0 0 0 4px var(--onetrust-brand-purple);\n text-decoration: none !important;\n outline: none !important;\n}\n#onetrust-pc-btn-handler{\n color: var(--onetrust-brand-purple) !important;\n border: 1px solid var(--onetrust-brand-purple)!important;\n background: var(--onetrust-color-white) !important\n}\n#onetrust-accept-btn-handler {\n color: var(--onetrust-color-white) !important;\n background: var(--onetrust-brand-purple)!important;\n margin-left: 1rem !important;\n}\n#onetrust-close-btn-container {\n display: none !important;\n}\n\n.pc-logo {\n display: none !important;\n}\n\n#accept-recommended-btn-handler,\n.ot-pc-refuse-all-handler,\n.save-preference-btn-handler {\n margin-left: 4px !important;\n font-size: 14px !important;\n}\n\n#accept-recommended-btn-handler:focus,\n#onetrust-pc-sdk .ot-pc-refuse-all-handler:focus,\n#onetrust-pc-sdk .save-preference-btn-handler:focus {\n box-shadow: 0 0 0 2px var(--onetrust-color-white), 0 0 0 4px var(--onetrust-brand-purple);\n text-decoration: none !important;\n outline: none !important;\n opacity: 1 !important;\n}\n\n.ot-switch-label {\n border: 1px solid var(--onetrust-color-gray-500) !important;\n background-color: var(--onetrust-color-gray-500) !important;\n}\n\n.ot-switch-nob {\n background: var(--onetrust-color-white) !important;\n}\n\n.ot-switch-inner:before {\n background-color: var(--onetrust-brand-purple) !important;\n}\n\n.switch-checkbox:checked+.ot-switch-label .ot-switch-nob {\n border-color: var(--onetrust-brand-purple) !important;\n}\n\n.ot-pc-footer-logo {\n display: none !important;\n}\n\n#onetrust-banner-sdk>.ot-sdk-container {\n overflow: visible !important;\n}\n\n@media (max-width: 30rem) {\n #accept-recommended-btn-handler,\n .ot-pc-refuse-all-handler,\n .save-preference-btn-handler {\n width: 96% !important;\n }\n}\n\n@media (min-width: 37.5rem) {\n #onetrust-banner-sdk {\n padding: 0.875rem 1rem !important;\n }\n}\n@media (min-width: 48rem) {\n #onetrust-banner-sdk {\n padding: 0.875rem 1.25rem !important;\n }\n}\n@media (min-width: 1650px) {\n #onetrust-banner-sdk > .ot-sdk-container > .ot-sdk-row {\n flex-direction: row !important;\n justify-content: space-between !important;\n }\n #onetrust-group-container {\n margin-bottom: 0 !important;\n }\n #onetrust-button-group {\n flex-direction: row !important;\n }\n}\n";
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/tracking",
3
3
  "description": "Tracking library for Codecademy apps.",
4
- "version": "0.25.1-alpha.1a54e4.0",
4
+ "version": "0.25.1-alpha.042681.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "@babel/cli": "^7.13.10",
17
17
  "@types/fetch-mock": "^7.3.3",
18
18
  "@types/jest": "^26.0.15",
19
- "babel-preset-codecademy": "6.0.1-alpha.1a54e4.0",
19
+ "babel-preset-codecademy": "6.0.1-alpha.042681.0",
20
20
  "fetch-mock": "^9.11.0",
21
21
  "jest-fetch-mock": "^3.0.3",
22
22
  "ts-jest": "^26.4.1",
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "4a0521b0b5a28071423bb6f61f2f14ac1a8da09c"
38
+ "gitHead": "a8c6b1ac467efb23d472d456a9779cb84c42eb18"
39
39
  }