@codecademy/tracking 1.0.2 → 1.0.3-alpha.37044bcdd.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.
Files changed (34) hide show
  1. package/dist/README.md +100 -0
  2. package/dist/events/index.d.ts +3 -3
  3. package/dist/events/track.d.ts +12 -12
  4. package/dist/events/types.d.ts +250 -250
  5. package/dist/events/user.d.ts +2 -2
  6. package/dist/index.cjs +711 -0
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +595 -3
  9. package/dist/integrations/conditionallyLoadAnalytics.d.ts +9 -9
  10. package/dist/integrations/consent.d.ts +9 -9
  11. package/dist/integrations/device.d.ts +13 -13
  12. package/dist/integrations/fetchDestinationsForWriteKey.d.ts +6 -6
  13. package/dist/integrations/getConsentDecision.d.ts +8 -8
  14. package/dist/integrations/index.d.ts +31 -31
  15. package/dist/integrations/mapDestinations.d.ts +13 -13
  16. package/dist/integrations/onetrust.d.ts +6 -6
  17. package/dist/integrations/runSegmentSnippet.d.ts +7 -7
  18. package/dist/integrations/types.d.ts +24 -24
  19. package/dist/package.json +21 -0
  20. package/package.json +2 -2
  21. package/dist/events/index.js +0 -3
  22. package/dist/events/track.js +0 -115
  23. package/dist/events/types.js +0 -1
  24. package/dist/events/user.js +0 -41
  25. package/dist/integrations/conditionallyLoadAnalytics.js +0 -27
  26. package/dist/integrations/consent.js +0 -11
  27. package/dist/integrations/device.js +0 -25
  28. package/dist/integrations/fetchDestinationsForWriteKey.js +0 -88
  29. package/dist/integrations/getConsentDecision.js +0 -32
  30. package/dist/integrations/index.js +0 -90
  31. package/dist/integrations/mapDestinations.js +0 -55
  32. package/dist/integrations/onetrust.js +0 -53
  33. package/dist/integrations/runSegmentSnippet.js +0 -64
  34. package/dist/integrations/types.js +0 -1
@@ -1,31 +1,31 @@
1
- import { TrackingWindow, UserIntegrationSummary } from './types';
2
- export declare type TrackingIntegrationsSettings = {
3
- /**
4
- * Called whenever a network request fails.
5
- */
6
- onError: (message: string) => void;
7
- /**
8
- * Whether this is running in a production environment.
9
- */
10
- production: boolean;
11
- /**
12
- * Global scope (often the window) where globals such as analytics are stored.
13
- */
14
- scope: TrackingWindow;
15
- /**
16
- * User details to identify in Segment.
17
- */
18
- user?: UserIntegrationSummary;
19
- /**
20
- * Whether user has opted out or is excluded from external tracking
21
- */
22
- optedOutExternalTracking?: boolean;
23
- /**
24
- * Segment write key.
25
- */
26
- writeKey: string;
27
- };
28
- /**
29
- * @see README.md for details and usage.
30
- */
31
- export declare const initializeTrackingIntegrations: ({ onError, production, scope, user, optedOutExternalTracking, writeKey, }: TrackingIntegrationsSettings) => Promise<void>;
1
+ import { TrackingWindow, UserIntegrationSummary } from './types';
2
+ export declare type TrackingIntegrationsSettings = {
3
+ /**
4
+ * Called whenever a network request fails.
5
+ */
6
+ onError: (message: string) => void;
7
+ /**
8
+ * Whether this is running in a production environment.
9
+ */
10
+ production: boolean;
11
+ /**
12
+ * Global scope (often the window) where globals such as analytics are stored.
13
+ */
14
+ scope: TrackingWindow;
15
+ /**
16
+ * User details to identify in Segment.
17
+ */
18
+ user?: UserIntegrationSummary;
19
+ /**
20
+ * Whether user has opted out or is excluded from external tracking
21
+ */
22
+ optedOutExternalTracking?: boolean;
23
+ /**
24
+ * Segment write key.
25
+ */
26
+ writeKey: string;
27
+ };
28
+ /**
29
+ * @see README.md for details and usage.
30
+ */
31
+ export declare const initializeTrackingIntegrations: ({ onError, production, scope, user, optedOutExternalTracking, writeKey, }: TrackingIntegrationsSettings) => Promise<void>;
@@ -1,13 +1,13 @@
1
- import { Consent } from './consent';
2
- import { SegmentDestination } from './types';
3
- export declare type DestinationMapOptions = {
4
- consentDecision?: Consent[];
5
- destinations: SegmentDestination[];
6
- };
7
- /**
8
- * @see https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41
9
- */
10
- export declare const mapDestinations: ({ consentDecision, destinations, }: DestinationMapOptions) => {
11
- destinationPreferences: Record<string, boolean>;
12
- identifyPreferences: Record<string, boolean>;
13
- };
1
+ import { Consent } from './consent';
2
+ import { SegmentDestination } from './types';
3
+ export declare type DestinationMapOptions = {
4
+ consentDecision?: Consent[];
5
+ destinations: SegmentDestination[];
6
+ };
7
+ /**
8
+ * @see https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41
9
+ */
10
+ export declare const mapDestinations: ({ consentDecision, destinations, }: DestinationMapOptions) => {
11
+ destinationPreferences: Record<string, boolean>;
12
+ identifyPreferences: Record<string, boolean>;
13
+ };
@@ -1,6 +1,6 @@
1
- import { TrackingWindow } from './types';
2
- export declare type OneTrustSettings = {
3
- production: boolean;
4
- scope: TrackingWindow;
5
- };
6
- export declare const initializeOneTrust: ({ production, scope, }: OneTrustSettings) => Promise<void>;
1
+ import { TrackingWindow } from './types';
2
+ export declare type OneTrustSettings = {
3
+ production: boolean;
4
+ scope: TrackingWindow;
5
+ };
6
+ export declare const initializeOneTrust: ({ production, scope, }: OneTrustSettings) => Promise<void>;
@@ -1,7 +1,7 @@
1
- /**
2
- * This code is copypasta from the Segment documentation.
3
- * It creates the global analytics object and loads the Segment Analytics API that uses it.
4
- *
5
- * @see https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet
6
- */
7
- export declare const runSegmentSnippet: () => void;
1
+ /**
2
+ * This code is copypasta from the Segment documentation.
3
+ * It creates the global analytics object and loads the Segment Analytics API that uses it.
4
+ *
5
+ * @see https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet
6
+ */
7
+ export declare const runSegmentSnippet: () => void;
@@ -1,24 +1,24 @@
1
- import { Consent } from './consent';
2
- export interface UserIntegrationSummary {
3
- email: string;
4
- id: string;
5
- }
6
- export interface SegmentAnalytics {
7
- identify(id: string, details: Record<string, string>, options: SegmentAnalyticsOptions): void;
8
- initialize?: boolean;
9
- load(writeKey: string, options: SegmentAnalyticsOptions): void;
10
- page(): void;
11
- }
12
- export interface SegmentDestination {
13
- category: string;
14
- id: string;
15
- }
16
- export interface SegmentAnalyticsOptions {
17
- integrations: Record<string, boolean>;
18
- }
19
- export interface TrackingWindow {
20
- analytics?: SegmentAnalytics;
21
- dataLayer?: unknown[];
22
- OnetrustActiveGroups?: Consent[] | string;
23
- OptanonWrapper?: () => void;
24
- }
1
+ import { Consent } from './consent';
2
+ export interface UserIntegrationSummary {
3
+ email: string;
4
+ id: string;
5
+ }
6
+ export interface SegmentAnalytics {
7
+ identify(id: string, details: Record<string, string>, options: SegmentAnalyticsOptions): void;
8
+ initialize?: boolean;
9
+ load(writeKey: string, options: SegmentAnalyticsOptions): void;
10
+ page(): void;
11
+ }
12
+ export interface SegmentDestination {
13
+ category: string;
14
+ id: string;
15
+ }
16
+ export interface SegmentAnalyticsOptions {
17
+ integrations: Record<string, boolean>;
18
+ }
19
+ export interface TrackingWindow {
20
+ analytics?: SegmentAnalytics;
21
+ dataLayer?: unknown[];
22
+ OnetrustActiveGroups?: Consent[] | string;
23
+ OptanonWrapper?: () => void;
24
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@codecademy/tracking",
3
+ "description": "Tracking library for Codecademy",
4
+ "version": "1.0.2",
5
+ "author": "Codecademy Engineering <dev@codecademy.com>",
6
+ "dependencies": {
7
+ "@babel/runtime": "^7.12.1"
8
+ },
9
+ "files": [
10
+ "dist/**"
11
+ ],
12
+ "license": "MIT",
13
+ "main": "./index.cjs",
14
+ "module": "./index.js",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": "git@github.com:codecademy-engineering/mono.git",
19
+ "type": "module",
20
+ "types": "./index.d.ts"
21
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/tracking",
3
3
  "description": "Tracking library for Codecademy",
4
- "version": "1.0.2",
4
+ "version": "1.0.3-alpha.37044bcdd.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "dependencies": {
7
7
  "@babel/runtime": "^7.12.1"
@@ -16,5 +16,5 @@
16
16
  "access": "public"
17
17
  },
18
18
  "repository": "git@github.com:codecademy-engineering/mono.git",
19
- "gitHead": "017ff0d3585499135e8b73cc9d8eff1e9fc2db78"
19
+ "gitHead": "3b2cea99b429eb7bd9c9aa663e95441b2b16d0af"
20
20
  }
@@ -1,3 +0,0 @@
1
- export * from './track';
2
- export * from './user';
3
- export * from './types';
@@ -1,115 +0,0 @@
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
-
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; }
4
-
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; }
6
-
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
-
9
- 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
- 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
- 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 == 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; }
16
-
17
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
-
19
- import { getClientType } from '../integrations/device';
20
-
21
- var browserSupportsKeepalive = function browserSupportsKeepalive() {
22
- return 'keepalive' in window.Request.prototype;
23
- };
24
-
25
- export var createTracker = function createTracker(_ref) {
26
- var apiBaseUrl = _ref.apiBaseUrl,
27
- verbose = _ref.verbose;
28
-
29
- var beacon = function beacon(endpoint, data) {
30
- var uri = new URL(endpoint, apiBaseUrl).toString();
31
- var form = new FormData();
32
-
33
- for (var _i2 = 0, _Object$entries = Object.entries(data); _i2 < _Object$entries.length; _i2++) {
34
- var _ref4 = _Object$entries[_i2];
35
-
36
- var _ref3 = _slicedToArray(_ref4, 2);
37
-
38
- var k = _ref3[0];
39
- var v = _ref3[1];
40
- form.append(k, v.toString());
41
- }
42
-
43
- try {
44
- // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
45
- // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
46
- // It seems similar to this: https://github.com/vercel/next.js/issues/23856
47
- if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
48
- return;
49
- }
50
- } catch (_unused) {// Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
51
- } // Either way, we fall back to standard fetch if sendBeacon fails.
52
- // We don't mind this rejecting with an error because it's tracking, and we'll know if that starts to fail.
53
-
54
-
55
- window.fetch(uri, _objectSpread({
56
- method: 'POST',
57
- body: form
58
- }, browserSupportsKeepalive() && {
59
- keepalive: true
60
- }));
61
- };
62
-
63
- var event = function event(category, _event, userData) {
64
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
65
-
66
- var properties = _objectSpread(_objectSpread({}, userData), {}, {
67
- fullpath: window.location.pathname + window.location.search,
68
- search: window.location.search,
69
- path: window.location.pathname,
70
- title: window.document.title,
71
- url: window.location.href,
72
- referrer: userData.referrer || window.document.referrer,
73
- client: getClientType()
74
- });
75
-
76
- if (verbose) {
77
- console.groupCollapsed("%cTracking Event Fired: ".concat(category, ":").concat(_event), 'color: #4b35ef; font-style: italic;');
78
- console.log({
79
- category: category,
80
- event: _event,
81
- properties: properties
82
- });
83
- console.groupEnd();
84
- } // This allows the UTM query params to get registered in the user session.
85
-
86
-
87
- var queryParams = window.location.search;
88
- beacon("/analytics/".concat(category).concat(queryParams), {
89
- category: category,
90
- event: _event,
91
- properties: JSON.stringify(properties),
92
- gdpr_safe: "".concat(options.gdprSafe)
93
- });
94
- };
95
-
96
- return {
97
- event: event,
98
- click: function click(data) {
99
- return event('user', 'click', data);
100
- },
101
- impression: function impression(data) {
102
- return event('user', 'impression', data);
103
- },
104
- visit: function visit(data) {
105
- return event('user', 'visit', data);
106
- },
107
- pushDataLayerEvent: function pushDataLayerEvent(eventName) {
108
- var _ref5;
109
-
110
- ((_ref5 = window).dataLayer || (_ref5.dataLayer = [])).push({
111
- event: eventName
112
- });
113
- }
114
- };
115
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
-
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); } }
6
-
7
- 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); }); }; }
8
-
9
- export var fetchUser = /*#__PURE__*/function () {
10
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(apiBaseUrl) {
11
- var response;
12
- return _regeneratorRuntime().wrap(function _callee$(_context) {
13
- while (1) {
14
- switch (_context.prev = _context.next) {
15
- case 0:
16
- _context.next = 2;
17
- return fetch("".concat(apiBaseUrl, "/users/web"), {
18
- method: 'GET',
19
- headers: {
20
- 'Content-type': 'application/json',
21
- Accept: 'application/json'
22
- },
23
- credentials: 'include'
24
- });
25
-
26
- case 2:
27
- response = _context.sent;
28
- return _context.abrupt("return", response.json());
29
-
30
- case 4:
31
- case "end":
32
- return _context.stop();
33
- }
34
- }
35
- }, _callee);
36
- }));
37
-
38
- return function fetchUser(_x) {
39
- return _ref.apply(this, arguments);
40
- };
41
- }();
@@ -1,27 +0,0 @@
1
- import { getClientType } from './device';
2
- export var conditionallyLoadAnalytics = function conditionallyLoadAnalytics(_ref) {
3
- var analytics = _ref.analytics,
4
- destinationPreferences = _ref.destinationPreferences,
5
- identifyPreferences = _ref.identifyPreferences,
6
- user = _ref.user,
7
- writeKey = _ref.writeKey;
8
-
9
- if (analytics.initialize) {
10
- return;
11
- }
12
-
13
- analytics.load(writeKey, {
14
- integrations: destinationPreferences
15
- });
16
- analytics.page();
17
-
18
- if (user) {
19
- var identifyParams = {
20
- email: user.email,
21
- client: getClientType()
22
- };
23
- analytics.identify(user.id, identifyParams, {
24
- integrations: identifyPreferences
25
- });
26
- }
27
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * @see https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41
3
- */
4
- export var Consent;
5
-
6
- (function (Consent) {
7
- Consent["Functional"] = "C0003";
8
- Consent["Performance"] = "C0002";
9
- Consent["StrictlyNecessary"] = "C0001";
10
- Consent["Targeting"] = "C0004";
11
- })(Consent || (Consent = {}));
@@ -1,25 +0,0 @@
1
- /**
2
- * @returns Whether the site is running both in ChromeOS and in PWA mode.
3
- */
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
6
- window.matchMedia('(display-mode: standalone)').matches;
7
- };
8
- /**
9
- * @returns Whether the site is running in ChromeOS
10
- */
11
-
12
- export var isChromeOS = function isChromeOS() {
13
- return typeof navigator !== 'undefined' && // https://stackoverflow.com/questions/29657165/detecting-chrome-os-with-javascript
14
- /\bCrOS\b/.test(navigator.userAgent);
15
- };
16
- export var ClientTypes;
17
-
18
- (function (ClientTypes) {
19
- ClientTypes["PWA"] = "pwa";
20
- ClientTypes["Default"] = "default";
21
- })(ClientTypes || (ClientTypes = {}));
22
-
23
- export var getClientType = function getClientType() {
24
- return isChromeOSPWA() ? ClientTypes.PWA : ClientTypes.Default;
25
- };
@@ -1,88 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
-
5
- 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; } } }; }
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 _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; }
10
-
11
- 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); } }
12
-
13
- 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); }); }; }
14
-
15
- var knownFetchFailures = ['Failed to fetch', 'Load failed', 'NetworkError when attempting to fetch resource', 'Resource blocked by content blocker'];
16
- export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
17
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
18
- var writeKey, onError, filteredOnError, response, destinations, _iterator, _step, destination;
19
-
20
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21
- while (1) {
22
- switch (_context.prev = _context.next) {
23
- case 0:
24
- writeKey = _ref.writeKey, onError = _ref.onError;
25
-
26
- filteredOnError = function filteredOnError(error) {
27
- if (!knownFetchFailures.some(function (failure) {
28
- return error.includes(failure);
29
- })) {
30
- onError(error);
31
- }
32
- };
33
-
34
- _context.prev = 2;
35
- _context.next = 5;
36
- return fetch("https://cdn.segment.com/v1/projects/".concat(writeKey, "/integrations"));
37
-
38
- case 5:
39
- response = _context.sent;
40
-
41
- if (response.ok) {
42
- _context.next = 9;
43
- break;
44
- }
45
-
46
- filteredOnError("Failed to fetch integrations for write key ".concat(writeKey, ": HTTP ").concat(response.status, " ").concat(response.statusText));
47
- return _context.abrupt("return", []);
48
-
49
- case 9:
50
- _context.next = 11;
51
- return response.json();
52
-
53
- case 11:
54
- destinations = _context.sent;
55
- _iterator = _createForOfIteratorHelper(destinations);
56
-
57
- try {
58
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
- destination = _step.value;
60
- destination.id = destination.creationName;
61
- delete destination.creationName;
62
- }
63
- } catch (err) {
64
- _iterator.e(err);
65
- } finally {
66
- _iterator.f();
67
- }
68
-
69
- return _context.abrupt("return", destinations);
70
-
71
- case 17:
72
- _context.prev = 17;
73
- _context.t0 = _context["catch"](2);
74
- filteredOnError("Unknown error fetching Segment destinations for write key ".concat(writeKey, ": ").concat(_context.t0));
75
- return _context.abrupt("return", []);
76
-
77
- case 21:
78
- case "end":
79
- return _context.stop();
80
- }
81
- }
82
- }, _callee, null, [[2, 17]]);
83
- }));
84
-
85
- return function fetchDestinationsForWriteKey(_x) {
86
- return _ref2.apply(this, arguments);
87
- };
88
- }();
@@ -1,32 +0,0 @@
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 & Performance trackers
22
- */
23
- if (consentDecision.length > 2) {
24
- consentDecision = [Consent.StrictlyNecessary, Consent.Functional, Consent.Performance];
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
- };