@codecademy/tracking 0.17.1-alpha.e28253.0 → 0.17.1
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,11 +3,12 @@
|
|
|
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
|
|
6
|
+
### [0.17.1](https://github.com/Codecademy/client-modules/compare/@codecademy/tracking@0.17.0...@codecademy/tracking@0.17.1) (2021-12-17)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @codecademy/tracking
|
|
9
8
|
|
|
9
|
+
### Bug Fixes
|
|
10
10
|
|
|
11
|
+
* **tracking:** remove navigator.sendBeacon .bind and add try/catch ([b924d7e](https://github.com/Codecademy/client-modules/commit/b924d7e1ffd22d75adcaf15c9726d10f19b2924e))
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -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
|
|
package/dist/events/track.js
CHANGED
|
@@ -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
|
-
}
|
|
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
|
-
|
|
51
|
-
|
|
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
|
|
@@ -4,10 +4,10 @@ export interface UserIntegrationSummary {
|
|
|
4
4
|
id: string;
|
|
5
5
|
}
|
|
6
6
|
export interface SegmentAnalytics {
|
|
7
|
-
identify
|
|
7
|
+
identify(id: string, details: Record<string, string>, options: SegmentAnalyticsOptions): void;
|
|
8
8
|
initialize?: boolean;
|
|
9
|
-
load
|
|
10
|
-
page
|
|
9
|
+
load(writeKey: string, options: SegmentAnalyticsOptions): void;
|
|
10
|
+
page(): void;
|
|
11
11
|
}
|
|
12
12
|
export interface SegmentDestination {
|
|
13
13
|
category: string;
|
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.1
|
|
4
|
+
"version": "0.17.1",
|
|
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": "
|
|
39
|
+
"gitHead": "f07787036cf95208eb5d78a7a357674c8129fb0f"
|
|
40
40
|
}
|