@codecademy/tracking 0.17.0 → 0.17.1-alpha.cb4d1f.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
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.17.1-alpha.cb4d1f.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.17.0...@codecademy/tracking@0.17.1-alpha.cb4d1f.0) (2021-12-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **tracking:** directly call navigator.sendBeacon without .bind ([3e4d58b](https://github.com/Codecademy/client-modules/commit/3e4d58bc2aa8e0832cd68401319837efa3d0ad90))
12
+
13
+
14
+
6
15
  ## [0.17.0](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.16.1...@codecademy/tracking@0.17.0) (2021-11-30)
7
16
 
8
17
 
@@ -114,6 +114,19 @@ describe('createTracker', function () {
114
114
  method: 'POST'
115
115
  });
116
116
  });
117
+ it('calls to fetch when beacon throws an error', function () {
118
+ Object.defineProperty(navigator, 'sendBeacon', {
119
+ writable: true,
120
+ value: function value() {
121
+ throw new Error('Oh no!');
122
+ }
123
+ });
124
+ tracker[event](expectedProps);
125
+ expect(fetch).toHaveBeenCalledWith('https://www.codecademy.com/analytics/user?utm_source=twitter', {
126
+ body: expect.any(FormData),
127
+ method: 'POST'
128
+ });
129
+ });
117
130
  });
118
131
  };
119
132
 
@@ -39,16 +39,17 @@ export var createTracker = function createTracker(_ref) {
39
39
  var k = _ref3[0];
40
40
  var v = _ref3[1];
41
41
  form.append(k, v.toString());
42
- } // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
43
-
44
-
45
- var sendBeacon = // [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
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
48
- navigator.sendBeacon && navigator.sendBeacon.bind(navigator);
42
+ }
49
43
 
50
- if (sendBeacon !== null && sendBeacon !== void 0 && sendBeacon(uri, form)) {
51
- return;
44
+ try {
45
+ // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
46
+ // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
47
+ // It seems similar to this: https://github.com/vercel/next.js/issues/23856
48
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
49
+ if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
50
+ return;
51
+ }
52
+ } catch (_unused) {// Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
52
53
  } // Either way, we fall back to standard fetch if sendBeacon fails.
53
54
  // We don't mind this rejecting with an error because it's tracking, and we'll know if that starts to fail.
54
55
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
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.17.0",
4
+ "version": "0.17.1-alpha.cb4d1f.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.js",
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "1d1819c91a8dcf95bbbb48bc1e297c23de374420"
39
+ "gitHead": "9d2cd2469653ea83c235bd64002d03eca34122d4"
40
40
  }