@codecademy/tracking 0.23.0 → 0.23.4

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.
Files changed (46) hide show
  1. package/.eslintrc.json +30 -0
  2. package/CHANGELOG.md +77 -206
  3. package/babel.config.js +9 -3
  4. package/dist/events/__tests__/track.test.d.js +1 -0
  5. package/dist/events/__tests__/track.test.js +13 -14
  6. package/dist/events/__tests__/user.test.d.js +1 -0
  7. package/dist/events/__tests__/user.test.js +3 -7
  8. package/dist/events/track.js +27 -37
  9. package/dist/events/types.js +2 -0
  10. package/dist/events/user.js +5 -7
  11. package/dist/integrations/__tests__/conditionallyLoadAnalytics.test.js +97 -0
  12. package/dist/integrations/__tests__/fetchDestinationsForWriteKey.test.js +112 -0
  13. package/dist/integrations/__tests__/mapDestinations.test.js +120 -0
  14. package/dist/integrations/device.js +2 -0
  15. package/dist/integrations/fetchDestinationsForWriteKey.js +27 -24
  16. package/dist/integrations/index.js +4 -6
  17. package/dist/integrations/mapDestinations.js +19 -20
  18. package/dist/integrations/onetrust.js +7 -9
  19. package/dist/integrations/runSegmentSnippet.js +0 -1
  20. package/dist/integrations/types.js +2 -0
  21. package/dist/{events → libs/tracking/src/events}/index.d.ts +0 -0
  22. package/dist/{events → libs/tracking/src/events}/track.d.ts +0 -0
  23. package/dist/{events → libs/tracking/src/events}/types.d.ts +0 -0
  24. package/dist/{events → libs/tracking/src/events}/user.d.ts +0 -0
  25. package/dist/{index.d.ts → libs/tracking/src/index.d.ts} +0 -0
  26. package/dist/{integrations → libs/tracking/src/integrations}/conditionallyLoadAnalytics.d.ts +0 -0
  27. package/dist/{integrations → libs/tracking/src/integrations}/consent.d.ts +0 -0
  28. package/dist/{integrations → libs/tracking/src/integrations}/device.d.ts +0 -0
  29. package/dist/{integrations → libs/tracking/src/integrations}/fetchDestinationsForWriteKey.d.ts +0 -0
  30. package/dist/{integrations → libs/tracking/src/integrations}/index.d.ts +0 -0
  31. package/dist/{integrations → libs/tracking/src/integrations}/mapDestinations.d.ts +0 -0
  32. package/dist/{integrations → libs/tracking/src/integrations}/onetrust.d.ts +0 -0
  33. package/dist/{integrations → libs/tracking/src/integrations}/runSegmentSnippet.d.ts +0 -0
  34. package/dist/{integrations → libs/tracking/src/integrations}/types.d.ts +0 -0
  35. package/package.json +5 -27
  36. package/project.json +45 -0
  37. package/tsconfig.json +13 -4
  38. package/tsconfig.lib.json +10 -0
  39. package/tsconfig.spec.json +9 -0
  40. package/.turbo/turbo-build.log +0 -11
  41. package/dist/events/__tests__/track.test.d.ts +0 -1
  42. package/dist/events/__tests__/user.test.d.ts +0 -1
  43. package/dist/integrations/__tests__/conditionallyLoadAnalytics-test.d.ts +0 -1
  44. package/dist/integrations/__tests__/fetchDestinationsForWriteKey-test.d.ts +0 -1
  45. package/dist/integrations/__tests__/mapDestinations-test.d.ts +0 -1
  46. package/jest.config.js +0 -1
@@ -1,17 +1,8 @@
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
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
-
5
- 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
- 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
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
-
11
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
-
13
- 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
-
1
+ import "core-js/modules/es.object.assign.js";
2
+ import "core-js/modules/es.array.concat.js";
3
+ import "core-js/modules/es.array.includes.js";
4
+ import "core-js/modules/es.string.includes.js";
5
+ import "core-js/modules/es.array.map.js";
15
6
  import { Consent } from './consent';
16
7
  // The Functional category may need to be added here in the future.
17
8
  var targetingCategories = ['Advertising', 'Attribution', 'Email Marketing'];
@@ -27,21 +18,29 @@ export var mapDestinations = function mapDestinations(_ref) {
27
18
  destinations = _ref.destinations;
28
19
  var destinationPreferences = Object.assign.apply(Object, [{
29
20
  'Segment.io': consentDecision.includes(Consent.Functional)
30
- }].concat(_toConsumableArray(destinations.map(function (dest) {
21
+ }].concat(destinations.map(function (dest) {
22
+ var _ref5;
23
+
31
24
  if (targetingCategories.includes(dest.category)) {
32
- return _defineProperty({}, dest.id, consentDecision.includes(Consent.Targeting));
25
+ var _ref2;
26
+
27
+ return _ref2 = {}, _ref2[dest.id] = consentDecision.includes(Consent.Targeting), _ref2;
33
28
  }
34
29
 
35
30
  if (performanceCategories.includes(dest.category)) {
36
- return _defineProperty({}, dest.id, consentDecision.includes(Consent.Performance));
31
+ var _ref3;
32
+
33
+ return _ref3 = {}, _ref3[dest.id] = consentDecision.includes(Consent.Performance), _ref3;
37
34
  }
38
35
 
39
36
  if (functionalCategories.includes(dest.category)) {
40
- return _defineProperty({}, dest.id, consentDecision.includes(Consent.Functional));
37
+ var _ref4;
38
+
39
+ return _ref4 = {}, _ref4[dest.id] = consentDecision.includes(Consent.Functional), _ref4;
41
40
  }
42
41
 
43
- return _defineProperty({}, dest.id, true);
44
- }))));
42
+ return _ref5 = {}, _ref5[dest.id] = true, _ref5;
43
+ })));
45
44
  var identifyPreferences = {
46
45
  All: false,
47
46
  FullStory: consentDecision.includes(Consent.Performance),
@@ -1,9 +1,7 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- 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
- 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
-
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
3
+ import "core-js/modules/es.object.to-string.js";
4
+ import "core-js/modules/es.promise.js";
7
5
  export var initializeOneTrust = /*#__PURE__*/function () {
8
6
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
9
7
  var production, scope, script, style;
@@ -16,7 +14,7 @@ export var initializeOneTrust = /*#__PURE__*/function () {
16
14
  script.setAttribute('async', 'true');
17
15
  script.setAttribute('src', 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js');
18
16
  script.setAttribute('type', 'text/javascript');
19
- script.setAttribute('data-domain-script', "cfa7b129-f37b-4f5a-9991-3f75ba7b85fb".concat(production ? '' : '-test'));
17
+ script.setAttribute('data-domain-script', "cfa7b129-f37b-4f5a-9991-3f75ba7b85fb" + (production ? '' : '-test'));
20
18
  document.body.appendChild(script);
21
19
  style = document.createElement('style');
22
20
  style.textContent = rawStyles;
@@ -25,12 +23,12 @@ export var initializeOneTrust = /*#__PURE__*/function () {
25
23
  scope.OptanonWrapper = function () {
26
24
  var _scope$dataLayer, _script$parentNode;
27
25
 
28
- (_scope$dataLayer = scope.dataLayer) !== null && _scope$dataLayer !== void 0 ? _scope$dataLayer : scope.dataLayer = [];
26
+ (_scope$dataLayer = scope.dataLayer) != null ? _scope$dataLayer : scope.dataLayer = [];
29
27
  scope.dataLayer.push({
30
28
  event: 'OneTrustGroupsUpdated'
31
29
  });
32
30
  resolve();
33
- (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
31
+ (_script$parentNode = script.parentNode) == null ? void 0 : _script$parentNode.removeChild(script);
34
32
  };
35
33
  }));
36
34
 
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console, prefer-rest-params */
2
1
  /**
3
2
  * This code is copypasta from the Segment documentation.
4
3
  * It creates the global analytics object and loads the Segment Analytics API that uses it.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ export {};
package/package.json CHANGED
@@ -1,39 +1,17 @@
1
1
  {
2
2
  "name": "@codecademy/tracking",
3
3
  "description": "Tracking library for Codecademy apps.",
4
- "version": "0.23.0",
4
+ "version": "0.23.4",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
- "module": "./dist/index.js",
7
- "main": "./dist/index.js",
8
- "repository": {
9
- "type": "git",
10
- "url": "git@github.com:Codecademy/client-modules.git"
11
- },
12
6
  "dependencies": {
13
7
  "@babel/runtime": "^7.12.1"
14
8
  },
15
- "devDependencies": {
16
- "@babel/cli": "^7.13.10",
17
- "@types/fetch-mock": "^7.3.3",
18
- "@types/jest": "^26.0.15",
19
- "babel-preset-codecademy": "^6.0.0",
20
- "fetch-mock": "^9.11.0",
21
- "jest-fetch-mock": "^3.0.3",
22
- "ts-jest": "^26.4.1",
23
- "typescript": "*"
24
- },
25
- "scripts": {
26
- "verify": "tsc --noEmit",
27
- "test": "jest",
28
- "test-watch": "jest --watch",
29
- "build:compile": "babel ./src --out-dir ./dist --copy-files --extensions \".ts,.tsx\"",
30
- "build:clean": "rm -rf dist",
31
- "build:types": "tsc --emitDeclarationOnly",
32
- "build": "yarn build:clean && yarn build:compile && yarn build:types"
33
- },
34
9
  "license": "MIT",
10
+ "main": "./dist/index.js",
11
+ "module": "./dist/index.js",
35
12
  "publishConfig": {
36
13
  "access": "public"
37
14
  },
38
- "gitHead": "35518429c4b243997db01c3600a4b86cc6fc2d7f"
15
+ "repository": "git@github.com:Codecademy/client-modules.git",
16
+ "gitHead": "af57b29fc3cc19e1a1bdee0033a6de2d98f89e73"
39
17
  }
package/project.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
3
+ "sourceRoot": "libs/tracking/src",
4
+ "projectType": "library",
5
+ "targets": {
6
+ "build": {
7
+ "outputs": ["{options.outputPath}"],
8
+ "executor": "nx:run-commands",
9
+ "options": {
10
+ "cwd": "libs/tracking",
11
+ "outputPath": "./dist",
12
+ "commands": [
13
+ "rm -rf ./dist",
14
+ "babel ./src --out-dir ./dist --copy-files --extensions \".ts,.tsx\"",
15
+ "tsc --emitDeclarationOnly --project ./tsconfig.lib.json"
16
+ ],
17
+ "parallel": false
18
+ }
19
+ },
20
+ "publish-build": {
21
+ "executor": "nx:run-commands",
22
+ "dependsOn": ["build"],
23
+ "options": {
24
+ "commands": [],
25
+ "parallel": false
26
+ }
27
+ },
28
+ "lint": {
29
+ "executor": "@nrwl/linter:eslint",
30
+ "outputs": ["{options.outputFile}"],
31
+ "options": {
32
+ "lintFilePatterns": ["libs/tracking/**/*.{ts,tsx,js,jsx}"]
33
+ }
34
+ },
35
+ "test": {
36
+ "executor": "@nrwl/jest:jest",
37
+ "outputs": ["coverage/libs/tracking"],
38
+ "options": {
39
+ "jestConfig": "libs/tracking/jest.config.ts",
40
+ "passWithNoTests": true
41
+ }
42
+ }
43
+ },
44
+ "tags": []
45
+ }
package/tsconfig.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "include": ["../../typings/*.d.ts", "./src/**/*.ts", "./src/**/*.tsx"],
2
+ "extends": "../../tsconfig.base.json",
4
3
  "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true,
5
11
  "allowJs": true,
6
- "outDir": "./dist"
7
- }
12
+ "declaration": true
13
+ },
14
+ "files": [],
15
+ "include": ["../../typings/*.d.ts", "./src/**/*.ts", "./src/**/*.tsx"],
16
+ "exclude": ["./dist"]
8
17
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "declaration": true,
6
+ "types": []
7
+ },
8
+ "include": ["**/*.ts"],
9
+ "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
9
+ }
@@ -1,11 +0,0 @@
1
- @codecademy/tracking:build: cache hit, replaying output a59512fe7c92ec96
2
- @codecademy/tracking:build: $ yarn build:clean && yarn build:compile && yarn build:types
3
- @codecademy/tracking:build: $ rm -rf dist
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 (1208ms).
11
- @codecademy/tracking:build: $ tsc --emitDeclarationOnly
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('../../jest.config.base')('tracking');