@codecademy/tracking 0.25.1-alpha.5b36ce.0 → 0.25.1-alpha.62d330.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 53b2821e10cf2062
1
+ @codecademy/tracking:build: cache hit, replaying output 2f9548fffeaf407c
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 (2060ms).
10
+ @codecademy/tracking:build: Successfully compiled 18 files with Babel (1786ms).
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.5b36ce.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.5b36ce.0) (2022-10-24)
6
+ ### [0.25.1-alpha.62d330.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.25.0...@codecademy/tracking@0.25.1-alpha.62d330.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>;
@@ -8,63 +8,69 @@ import { conditionallyLoadAnalytics } from './conditionallyLoadAnalytics';
8
8
  import { Consent } from './consent';
9
9
  import { fetchDestinationsForWriteKey } from './fetchDestinationsForWriteKey';
10
10
  import { mapDestinations } from './mapDestinations';
11
- import { initializeOneTrust } from './onetrust';
11
+ import { initializeOneTrust, updateConsentForOptedOutUsers } from './onetrust';
12
12
  import { runSegmentSnippet } from './runSegmentSnippet';
13
-
13
+ var optedOutActiveGroups = [Consent.StrictlyNecessary, Consent.Functional];
14
14
  /**
15
15
  * @see README.md for details and usage.
16
16
  */
17
+
17
18
  export var initializeTrackingIntegrations = /*#__PURE__*/function () {
18
19
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
19
- var onError, production, scope, user, writeKey, optedOut, destinations, _mapDestinations, destinationPreferences, identifyPreferences;
20
+ var onError, production, scope, user, optedOutExternalTracking, writeKey, destinations, consentDecision, _mapDestinations, destinationPreferences, identifyPreferences;
20
21
 
21
22
  return _regeneratorRuntime.wrap(function _callee$(_context) {
22
23
  while (1) {
23
24
  switch (_context.prev = _context.next) {
24
25
  case 0:
25
- onError = _ref.onError, production = _ref.production, scope = _ref.scope, user = _ref.user, writeKey = _ref.writeKey;
26
- optedOut = user === null || user === void 0 ? void 0 : user.opted_out_external_tracking; // 1. Wait 1000ms to allow any other post-hydration logic to run first
27
-
28
- _context.next = 4;
26
+ onError = _ref.onError, production = _ref.production, scope = _ref.scope, user = _ref.user, optedOutExternalTracking = _ref.optedOutExternalTracking, writeKey = _ref.writeKey;
27
+ _context.next = 3;
29
28
  return new Promise(function (resolve) {
30
29
  return setTimeout(resolve, 1000);
31
30
  });
32
31
 
33
- case 4:
34
- _context.next = 6;
32
+ case 3:
33
+ _context.next = 5;
35
34
  return initializeOneTrust({
36
35
  scope: scope,
37
36
  production: production
38
37
  });
39
38
 
40
- case 6:
41
- if (optedOut) {
42
- scope.OnetrustActiveGroups = [Consent.StrictlyNecessary, Consent.Functional];
43
- } // 3. Segment's copy-and-paste snippet is run to load the Segment global library
44
-
39
+ case 5:
40
+ if (optedOutExternalTracking) updateConsentForOptedOutUsers(scope); // 3. Segment's copy-and-paste snippet is run to load the Segment global library
45
41
 
46
42
  runSegmentSnippet(); // 4. Destination integrations for Segment are fetched
47
43
 
48
- _context.next = 10;
44
+ _context.next = 9;
49
45
  return fetchDestinationsForWriteKey({
50
46
  onError: onError,
51
47
  writeKey: writeKey
52
48
  });
53
49
 
54
- case 10:
50
+ case 9:
55
51
  destinations = _context.sent;
56
52
 
57
53
  if (destinations) {
58
- _context.next = 13;
54
+ _context.next = 12;
59
55
  break;
60
56
  }
61
57
 
62
58
  return _context.abrupt("return");
63
59
 
64
- case 13:
65
- // 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
+
66
72
  _mapDestinations = mapDestinations({
67
- consentDecision: scope.OnetrustActiveGroups,
73
+ consentDecision: consentDecision,
68
74
  destinations: destinations
69
75
  }), destinationPreferences = _mapDestinations.destinationPreferences, identifyPreferences = _mapDestinations.identifyPreferences; // 6. We load only those allowed destinations using Segment's `analytics.load`
70
76
 
@@ -76,7 +82,7 @@ export var initializeTrackingIntegrations = /*#__PURE__*/function () {
76
82
  writeKey: writeKey
77
83
  });
78
84
 
79
- case 15:
85
+ case 16:
80
86
  case "end":
81
87
  return _context.stop();
82
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,21 @@ 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 = [];
57
+ (_scope$OneTrust = scope.OneTrust) === null || _scope$OneTrust === void 0 ? void 0 : _scope$OneTrust.RejectAll();
58
+ (_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');
59
+ scope.dataLayer.push({
60
+ user_opted_out_external_tracking: 'true'
61
+ });
62
+ }; // For now, these three values duplicate theme colors from gamut-styles
49
63
  // We don't want to take a full dependency on that package here...
50
64
 
51
65
  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";
@@ -2,7 +2,6 @@ import { Consent } from './consent';
2
2
  export interface UserIntegrationSummary {
3
3
  email: string;
4
4
  id: string;
5
- opted_out_external_tracking: boolean;
6
5
  }
7
6
  export interface SegmentAnalytics {
8
7
  identify(id: string, details: Record<string, string>, options: SegmentAnalyticsOptions): void;
@@ -17,9 +16,14 @@ export interface SegmentDestination {
17
16
  export interface SegmentAnalyticsOptions {
18
17
  integrations: Record<string, boolean>;
19
18
  }
19
+ export interface OneTrustSDK {
20
+ RejectAll: () => void;
21
+ UpdateConsent?: (category: string, code: string) => void;
22
+ }
20
23
  export interface TrackingWindow {
21
24
  analytics?: SegmentAnalytics;
22
25
  dataLayer?: unknown[];
23
- OnetrustActiveGroups?: Consent[];
26
+ OnetrustActiveGroups?: Consent[] | string;
24
27
  OptanonWrapper?: () => void;
28
+ OneTrust?: OneTrustSDK;
25
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.5b36ce.0",
4
+ "version": "0.25.1-alpha.62d330.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": "29503baa2905555fad928184d58a78776afdad0c"
38
+ "gitHead": "d6bb477c3bac75a5da7c3a209a55449e89bde8c6"
39
39
  }