@codecademy/tracking 0.25.1-alpha.a42678.0 → 0.25.1-alpha.bf090d.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,4 +1,4 @@
1
- @codecademy/tracking:build: cache hit, replaying output 3f7e2f12bf268299
1
+ @codecademy/tracking:build: cache hit, replaying output 69502ae40927292b
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"
@@ -7,5 +7,5 @@
7
7
  @codecademy/tracking:build: 
8
8
  @codecademy/tracking:build: Why you should do it regularly:
9
9
  @codecademy/tracking:build: https://github.com/browserslist/browserslist#browsers-data-updating
10
- @codecademy/tracking:build: Successfully compiled 18 files with Babel (1752ms).
10
+ @codecademy/tracking:build: Successfully compiled 20 files with Babel (2158ms).
11
11
  @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.a42678.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.a42678.0) (2022-10-27)
6
+ ### [0.25.1-alpha.bf090d.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.bf090d.0) (2022-10-27)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/tracking
9
9
 
@@ -0,0 +1,58 @@
1
+ import { Consent } from '../consent';
2
+ import { getConsentDecision, OPT_OUT_DATALAYER_VAR } from '../getConsentDecision';
3
+ var MINIMUM_CONSENT = [Consent.StrictlyNecessary];
4
+ var FULL_CONSENT = [Consent.StrictlyNecessary, Consent.Functional, Consent.Performance, Consent.Targeting];
5
+ var FULL_CONSENT_STRING = [','].concat(FULL_CONSENT).join(',');
6
+ describe('getConsentDecision', function () {
7
+ it('converts a stringified consent decision into an array', function () {
8
+ var result = getConsentDecision({
9
+ scope: {
10
+ OnetrustActiveGroups: FULL_CONSENT_STRING
11
+ }
12
+ });
13
+ expect(result).toEqual(FULL_CONSENT);
14
+ });
15
+ it('does not modify an array formatted consent decision', function () {
16
+ var result = getConsentDecision({
17
+ scope: {
18
+ OnetrustActiveGroups: FULL_CONSENT
19
+ }
20
+ });
21
+ expect(result).toEqual(FULL_CONSENT);
22
+ });
23
+ describe('optedOutExternalTracking', function () {
24
+ it('reduces the consent decision to necessary and functional for opted out users', function () {
25
+ var result = getConsentDecision({
26
+ scope: {
27
+ OnetrustActiveGroups: FULL_CONSENT
28
+ },
29
+ optedOutExternalTracking: true
30
+ });
31
+ expect(result).toEqual([Consent.StrictlyNecessary, Consent.Functional]);
32
+ });
33
+ it('does not add Functional tracking if the user has opted out of it', function () {
34
+ var result = getConsentDecision({
35
+ scope: {
36
+ OnetrustActiveGroups: MINIMUM_CONSENT
37
+ },
38
+ optedOutExternalTracking: true
39
+ });
40
+ expect(result).toEqual(MINIMUM_CONSENT);
41
+ });
42
+ it('triggers the opt out datalayer variable', function () {
43
+ var _scope$dataLayer;
44
+
45
+ var scope = {
46
+ OnetrustActiveGroups: FULL_CONSENT
47
+ };
48
+ getConsentDecision({
49
+ scope: scope,
50
+ optedOutExternalTracking: true
51
+ });
52
+ var dataLayerVars = (_scope$dataLayer = scope.dataLayer) === null || _scope$dataLayer === void 0 ? void 0 : _scope$dataLayer.map(function (v) {
53
+ return Object.keys(v);
54
+ }).flat();
55
+ expect(dataLayerVars).toEqual([OPT_OUT_DATALAYER_VAR]);
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,8 @@
1
+ import { Consent } from './consent';
2
+ import { TrackingWindow } from './types';
3
+ export interface ConsentDecisionOptions {
4
+ scope: TrackingWindow;
5
+ optedOutExternalTracking?: boolean;
6
+ }
7
+ export declare const OPT_OUT_DATALAYER_VAR = "user_opted_out_external_tracking";
8
+ export declare const getConsentDecision: ({ scope, optedOutExternalTracking, }: ConsentDecisionOptions) => Consent[];
@@ -0,0 +1,32 @@
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
+ import { Consent } from './consent';
4
+ export var OPT_OUT_DATALAYER_VAR = 'user_opted_out_external_tracking';
5
+ export var getConsentDecision = function getConsentDecision(_ref) {
6
+ var scope = _ref.scope,
7
+ optedOutExternalTracking = _ref.optedOutExternalTracking;
8
+ var consentDecision = [];
9
+
10
+ if (typeof scope.OnetrustActiveGroups === 'string') {
11
+ consentDecision = scope.OnetrustActiveGroups.split(',').filter(Boolean);
12
+ } else if (scope.OnetrustActiveGroups) {
13
+ consentDecision = scope.OnetrustActiveGroups;
14
+ }
15
+
16
+ if (optedOutExternalTracking) {
17
+ var _scope$dataLayer;
18
+
19
+ /**
20
+ * If user has already opted out of everything but the essentials
21
+ * don't force them to consent to Functional trackers
22
+ */
23
+ if (consentDecision.length > 1) {
24
+ consentDecision = [Consent.StrictlyNecessary, Consent.Functional];
25
+ }
26
+
27
+ (_scope$dataLayer = scope.dataLayer) !== null && _scope$dataLayer !== void 0 ? _scope$dataLayer : scope.dataLayer = [];
28
+ scope.dataLayer.push(_defineProperty({}, OPT_OUT_DATALAYER_VAR, true));
29
+ }
30
+
31
+ return consentDecision;
32
+ };
@@ -5,19 +5,18 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
5
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
6
 
7
7
  import { conditionallyLoadAnalytics } from './conditionallyLoadAnalytics';
8
- import { Consent } from './consent';
9
8
  import { fetchDestinationsForWriteKey } from './fetchDestinationsForWriteKey';
9
+ import { getConsentDecision } from './getConsentDecision';
10
10
  import { mapDestinations } from './mapDestinations';
11
11
  import { initializeOneTrust } from './onetrust';
12
12
  import { runSegmentSnippet } from './runSegmentSnippet';
13
- var optedOutActiveGroups = [Consent.StrictlyNecessary, Consent.Functional];
13
+
14
14
  /**
15
15
  * @see README.md for details and usage.
16
16
  */
17
-
18
17
  export var initializeTrackingIntegrations = /*#__PURE__*/function () {
19
18
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
20
- var onError, production, scope, user, optedOutExternalTracking, writeKey, destinations, consentDecision, _scope$dataLayer, _mapDestinations, destinationPreferences, identifyPreferences;
19
+ var onError, production, scope, user, optedOutExternalTracking, writeKey, destinations, consentDecision, _mapDestinations, destinationPreferences, identifyPreferences;
21
20
 
22
21
  return _regeneratorRuntime.wrap(function _callee$(_context) {
23
22
  while (1) {
@@ -57,29 +56,10 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
57
56
  return _context.abrupt("return");
58
57
 
59
58
  case 11:
60
- consentDecision = [];
61
-
62
- if (typeof scope.OnetrustActiveGroups === 'string') {
63
- consentDecision = scope.OnetrustActiveGroups.split(',').filter(Boolean);
64
- } else if (scope.OnetrustActiveGroups) {
65
- consentDecision = scope.OnetrustActiveGroups;
66
- }
67
-
68
- if (optedOutExternalTracking) {
69
- /**
70
- * If user has already opted out of everything but the essentials
71
- * don't force them to consent to Functional trackers
72
- */
73
- if (consentDecision.length > 1) {
74
- consentDecision = optedOutActiveGroups;
75
- }
76
-
77
- (_scope$dataLayer = scope.dataLayer) !== null && _scope$dataLayer !== void 0 ? _scope$dataLayer : scope.dataLayer = [];
78
- scope.dataLayer.push({
79
- user_opted_out_external_tracking: true
80
- });
81
- } // 5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
82
-
59
+ consentDecision = getConsentDecision({
60
+ scope: scope,
61
+ optedOutExternalTracking: optedOutExternalTracking
62
+ }); // 5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
83
63
 
84
64
  _mapDestinations = mapDestinations({
85
65
  consentDecision: consentDecision,
@@ -94,7 +74,7 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
94
74
  writeKey: writeKey
95
75
  });
96
76
 
97
- case 16:
77
+ case 14:
98
78
  case "end":
99
79
  return _context.stop();
100
80
  }
@@ -23,13 +23,14 @@ export var initializeOneTrust = /*#__PURE__*/function () {
23
23
  document.body.appendChild(style);
24
24
  return _context.abrupt("return", new Promise(function (resolve) {
25
25
  scope.OptanonWrapper = function () {
26
- var _scope$dataLayer;
26
+ var _scope$dataLayer, _script$parentNode;
27
27
 
28
28
  (_scope$dataLayer = scope.dataLayer) !== null && _scope$dataLayer !== void 0 ? _scope$dataLayer : scope.dataLayer = [];
29
29
  scope.dataLayer.push({
30
30
  event: 'OneTrustGroupsUpdated'
31
31
  });
32
- resolve(); // script.parentNode?.removeChild(script);
32
+ resolve();
33
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
33
34
  };
34
35
  }));
35
36
 
@@ -16,14 +16,9 @@ export interface SegmentDestination {
16
16
  export interface SegmentAnalyticsOptions {
17
17
  integrations: Record<string, boolean>;
18
18
  }
19
- export interface OneTrustSDK {
20
- RejectAll: () => void;
21
- UpdateConsent?: (category: string, code: string) => void;
22
- }
23
19
  export interface TrackingWindow {
24
20
  analytics?: SegmentAnalytics;
25
21
  dataLayer?: unknown[];
26
22
  OnetrustActiveGroups?: Consent[] | string;
27
23
  OptanonWrapper?: () => void;
28
- OneTrust?: OneTrustSDK;
29
24
  }
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.a42678.0",
4
+ "version": "0.25.1-alpha.bf090d.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.js",
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "f7711e1cd87e586f2c916783c7c5ab95764928b1"
38
+ "gitHead": "990aba53946f174730bc3691f84d3b38571bc41c"
39
39
  }