@codecademy/tracking 1.0.5-alpha.2fa35b3bd.0 → 1.0.5-alpha.4f56dceef.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.
@@ -38,26 +38,33 @@ export var createTracker = function createTracker(_ref) {
38
38
  var k = _ref3[0];
39
39
  var v = _ref3[1];
40
40
  form.append(k, v.toString());
41
- } // try {
42
- // // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
43
- // // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
44
- // // It seems similar to this: https://github.com/vercel/next.js/issues/23856
45
- // if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
46
- // return;
47
- // }
48
- // } catch {
49
- // // Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
50
- // }
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({
41
+ }
42
+
43
+ var fetchParams = {
56
44
  method: 'POST',
45
+ credentials: 'include',
57
46
  body: form
58
- }, browserSupportsKeepalive() && {
59
- keepalive: true
60
- }));
47
+ }; // Prefer fetch with keepalive because it's more reliable than sendBeacon
48
+
49
+ if (browserSupportsKeepalive()) {
50
+ window.fetch(uri, _objectSpread(_objectSpread({}, fetchParams), {}, {
51
+ keepalive: true
52
+ }));
53
+ } else {
54
+ try {
55
+ // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
56
+ // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
57
+ // It seems similar to this: https://github.com/vercel/next.js/issues/23856
58
+ if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
59
+ return;
60
+ }
61
+ } catch (_unused) {// Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
62
+ } // Either way, we fall back to standard fetch if sendBeacon fails.
63
+ // We don't mind this rejecting with an error because it's tracking, and we'll know if that starts to fail.
64
+
65
+
66
+ window.fetch(uri, fetchParams);
67
+ }
61
68
  };
62
69
 
63
70
  var event = function event(category, _event, userData) {
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.5-alpha.2fa35b3bd.0",
4
+ "version": "1.0.5-alpha.4f56dceef.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": "825fe9696bc9462f5b0b6a2462dac0f07f817b9f"
19
+ "gitHead": "5f96496858fd77c20fa156bdd5a81141a2e94518"
20
20
  }