@codecademy/tracking 1.1.1-alpha.d7121cda5d.0 → 1.1.2-alpha.fa2232522c.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.
@@ -4,49 +4,48 @@ import { theme } from '@codecademy/gamut-styles';
4
4
  */
5
5
 
6
6
  const PROPERTY_ID = 'FDS-3RC5S1';
7
+ const FIDES_TIMEOUT = 10000; // 10 seconds
8
+
7
9
  const ot_fides_mapping = encodeURIComponent(JSON.stringify({
8
10
  C0001: ['essential'],
9
11
  C0002: ['analytics'],
10
12
  C0003: ['functional'],
11
13
  C0004: ['marketing']
12
14
  }));
13
- const importFides = async () => {
14
- var _win$define;
15
- const win = window;
16
- // Disable AMD globals for the Fides script
17
- const oldAmd = (_win$define = win.define) === null || _win$define === void 0 ? void 0 : _win$define.amd;
18
- if (oldAmd) {
19
- win.define.amd = undefined;
20
- }
21
- // Fides gets stored on the window object
22
- await import(/* webpackIgnore: true */"https://skillsoft-codecademy.fides-cdn.ethyca.com/fides.js?property_id=".concat(PROPERTY_ID, "&ot_fides_mapping=").concat(ot_fides_mapping));
23
- if (oldAmd) {
24
- win.define.amd = oldAmd;
25
- }
26
- if (!win.Fides) {
27
- throw new Error('Failed to import Fides');
28
- }
29
- return win.Fides;
30
- };
31
- export const initializeFides = async () => {
32
- try {
33
- const fides = await importFides();
34
- fides.gtm();
35
- const unsubscribe = fides.onFidesEvent('FidesUIShown', detail => {
36
- if (detail.extraDetails.servingComponent === 'banner') {
37
- const banner = document.getElementById('fides-banner');
38
- if (banner) {
39
- banner.setAttribute('tabIndex', '-1');
40
- }
15
+ export const initializeFides = () => {
16
+ return new Promise((resolve, reject) => {
17
+ const timeout = setTimeout(() => {
18
+ reject(new Error('Fides initialization timed out'));
19
+ }, FIDES_TIMEOUT);
20
+ window.addEventListener('FidesInitialized', () => {
21
+ clearTimeout(timeout);
22
+ const fides = window.Fides;
23
+ try {
24
+ fides.gtm();
25
+ const unsubscribe = fides.onFidesEvent('FidesUIShown', detail => {
26
+ if (detail.extraDetails.servingComponent === 'banner') {
27
+ const banner = document.getElementById('fides-banner');
28
+ if (banner) {
29
+ banner.setAttribute('tabIndex', '-1');
30
+ }
31
+ }
32
+ unsubscribe();
33
+ });
34
+ resolve();
35
+ } catch (err) {
36
+ console.error('Error initializing Fides', err);
37
+ reject(err);
41
38
  }
42
- unsubscribe();
43
39
  });
44
- } catch (err) {
45
- console.error('Error initializing Fides', err);
46
- }
47
- const style = document.createElement('style');
48
- style.textContent = rawStyles;
49
- document.body.appendChild(style);
40
+ const script = document.createElement('script');
41
+ script.setAttribute('async', 'true');
42
+ script.setAttribute('src', "https://skillsoft-codecademy.fides-cdn.ethyca.com/fides.js?property_id=".concat(PROPERTY_ID, "&ot_fides_mapping=").concat(ot_fides_mapping));
43
+ script.setAttribute('type', 'text/javascript');
44
+ document.body.appendChild(script);
45
+ const style = document.createElement('style');
46
+ style.textContent = rawStyles;
47
+ document.body.appendChild(style);
48
+ });
50
49
  };
51
50
 
52
51
  // For now, these three values duplicate theme colors from gamut-styles
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.1.1-alpha.d7121cda5d.0",
4
+ "version": "1.1.2-alpha.fa2232522c.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "dependencies": {
7
7
  "@qwik.dev/partytown": "0.11.0"