@codecademy/tracking 0.25.1-alpha.8dfef4.0 → 0.25.1-alpha.90fc7a.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 216c90d217c37b75
1
+ @codecademy/tracking:build: cache hit, replaying output 51d12316ef14cae9
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 (1747ms).
10
+ @codecademy/tracking:build: Successfully compiled 18 files with Babel (1854ms).
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.8dfef4.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.8dfef4.0) (2022-10-21)
6
+ ### [0.25.1-alpha.90fc7a.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.90fc7a.0) (2022-10-27)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/tracking
9
9
 
@@ -16,6 +16,10 @@ export declare type TrackingIntegrationsSettings = {
16
16
  * User details to identify in Segment.
17
17
  */
18
18
  user?: UserIntegrationSummary;
19
+ /**
20
+ * Whether user has opted out or is excluded from external tracking
21
+ */
22
+ optedOutExternalTracking?: boolean;
19
23
  /**
20
24
  * Segment write key.
21
25
  */
@@ -24,4 +28,4 @@ export declare type TrackingIntegrationsSettings = {
24
28
  /**
25
29
  * @see README.md for details and usage.
26
30
  */
27
- export declare const initializeTrackingIntegrations: ({ onError, production, scope, user, writeKey, }: TrackingIntegrationsSettings) => Promise<void>;
31
+ export declare const initializeTrackingIntegrations: ({ onError, production, scope, user, optedOutExternalTracking, writeKey, }: TrackingIntegrationsSettings) => Promise<void>;
@@ -5,23 +5,25 @@ 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';
8
9
  import { fetchDestinationsForWriteKey } from './fetchDestinationsForWriteKey';
9
10
  import { mapDestinations } from './mapDestinations';
10
- import { initializeOneTrust } from './onetrust';
11
+ import { initializeOneTrust, updateConsentForOptedOutUsers } from './onetrust';
11
12
  import { runSegmentSnippet } from './runSegmentSnippet';
12
-
13
+ var optedOutActiveGroups = [Consent.StrictlyNecessary, Consent.Functional];
13
14
  /**
14
15
  * @see README.md for details and usage.
15
16
  */
17
+
16
18
  export var initializeTrackingIntegrations = /*#__PURE__*/function () {
17
19
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
18
- var onError, production, scope, user, writeKey, destinations, _mapDestinations, destinationPreferences, identifyPreferences;
20
+ var onError, production, scope, user, optedOutExternalTracking, writeKey, destinations, consentDecision, _mapDestinations, destinationPreferences, identifyPreferences;
19
21
 
20
22
  return _regeneratorRuntime.wrap(function _callee$(_context) {
21
23
  while (1) {
22
24
  switch (_context.prev = _context.next) {
23
25
  case 0:
24
- onError = _ref.onError, production = _ref.production, scope = _ref.scope, user = _ref.user, writeKey = _ref.writeKey;
26
+ onError = _ref.onError, production = _ref.production, scope = _ref.scope, user = _ref.user, optedOutExternalTracking = _ref.optedOutExternalTracking, writeKey = _ref.writeKey;
25
27
  _context.next = 3;
26
28
  return new Promise(function (resolve) {
27
29
  return setTimeout(resolve, 1000);
@@ -35,29 +37,40 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
35
37
  });
36
38
 
37
39
  case 5:
38
- // 3. Segment's copy-and-paste snippet is run to load the Segment global library
40
+ if (optedOutExternalTracking) updateConsentForOptedOutUsers(scope); // 3. Segment's copy-and-paste snippet is run to load the Segment global library
41
+
39
42
  runSegmentSnippet(); // 4. Destination integrations for Segment are fetched
40
43
 
41
- _context.next = 8;
44
+ _context.next = 9;
42
45
  return fetchDestinationsForWriteKey({
43
46
  onError: onError,
44
47
  writeKey: writeKey
45
48
  });
46
49
 
47
- case 8:
50
+ case 9:
48
51
  destinations = _context.sent;
49
52
 
50
53
  if (destinations) {
51
- _context.next = 11;
54
+ _context.next = 12;
52
55
  break;
53
56
  }
54
57
 
55
58
  return _context.abrupt("return");
56
59
 
57
- case 11:
58
- // 5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
60
+ case 12:
61
+ consentDecision = [];
62
+
63
+ if (optedOutExternalTracking) {
64
+ consentDecision = optedOutActiveGroups;
65
+ } else if (typeof scope.OnetrustActiveGroups === 'string') {
66
+ consentDecision = scope.OnetrustActiveGroups.split(',').filter(Boolean);
67
+ } else if (scope.OnetrustActiveGroups) {
68
+ consentDecision = scope.OnetrustActiveGroups;
69
+ } // 5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
70
+
71
+
59
72
  _mapDestinations = mapDestinations({
60
- consentDecision: scope.OnetrustActiveGroups,
73
+ consentDecision: consentDecision,
61
74
  destinations: destinations
62
75
  }), destinationPreferences = _mapDestinations.destinationPreferences, identifyPreferences = _mapDestinations.identifyPreferences; // 6. We load only those allowed destinations using Segment's `analytics.load`
63
76
 
@@ -69,7 +82,7 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
69
82
  writeKey: writeKey
70
83
  });
71
84
 
72
- case 13:
85
+ case 16:
73
86
  case "end":
74
87
  return _context.stop();
75
88
  }
@@ -4,3 +4,7 @@ export declare type OneTrustSettings = {
4
4
  scope: TrackingWindow;
5
5
  };
6
6
  export declare const initializeOneTrust: ({ production, scope, }: OneTrustSettings) => Promise<void>;
7
+ /**
8
+ * update OneTrust constent for
9
+ */
10
+ export declare const updateConsentForOptedOutUsers: (scope: TrackingWindow) => void;
@@ -45,7 +45,24 @@ export var initializeOneTrust = /*#__PURE__*/function () {
45
45
  return function initializeOneTrust(_x) {
46
46
  return _ref2.apply(this, arguments);
47
47
  };
48
- }(); // For now, these three values duplicate theme colors from gamut-styles
48
+ }();
49
+ /**
50
+ * update OneTrust constent for
51
+ */
52
+
53
+ export var updateConsentForOptedOutUsers = function updateConsentForOptedOutUsers(scope) {
54
+ var _scope$dataLayer2, _scope$OneTrust, _scope$OneTrust2, _scope$OneTrust2$Upda;
55
+
56
+ (_scope$dataLayer2 = scope.dataLayer) !== null && _scope$dataLayer2 !== void 0 ? _scope$dataLayer2 : scope.dataLayer = []; // Disable all consent options except StrictlyNecessary
57
+
58
+ (_scope$OneTrust = scope.OneTrust) === null || _scope$OneTrust === void 0 ? void 0 : _scope$OneTrust.RejectAll(); // Enable Functional trackers
59
+
60
+ (_scope$OneTrust2 = scope.OneTrust) === null || _scope$OneTrust2 === void 0 ? void 0 : (_scope$OneTrust2$Upda = _scope$OneTrust2.UpdateConsent) === null || _scope$OneTrust2$Upda === void 0 ? void 0 : _scope$OneTrust2$Upda.call(_scope$OneTrust2, 'Category', 'C0003:1'); // Indicate to GTM that this user has opted out
61
+
62
+ scope.dataLayer.push({
63
+ user_opted_out_external_tracking: 'true'
64
+ });
65
+ }; // For now, these three values duplicate theme colors from gamut-styles
49
66
  // We don't want to take a full dependency on that package here...
50
67
 
51
68
  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";
@@ -16,9 +16,14 @@ 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
+ }
19
23
  export interface TrackingWindow {
20
24
  analytics?: SegmentAnalytics;
21
25
  dataLayer?: unknown[];
22
- OnetrustActiveGroups?: Consent[];
26
+ OnetrustActiveGroups?: Consent[] | string;
23
27
  OptanonWrapper?: () => void;
28
+ OneTrust?: OneTrustSDK;
24
29
  }
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.8dfef4.0",
4
+ "version": "0.25.1-alpha.90fc7a.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.8dfef4.0",
19
+ "babel-preset-codecademy": "^6.0.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": "32974d2ad56900ed07f344f4bcab459f04eff818"
38
+ "gitHead": "b9adc4102f5b0e9698ec30d812c8f84ad6ddf364"
39
39
  }