@plasius/analytics 1.3.2 → 1.3.3
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/README.md +7 -0
- package/dist/index.cjs +17 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @plasius/analytics
|
|
2
2
|
|
|
3
|
+
For optional analytics, construct clients only after the host has obtained consent.
|
|
4
|
+
On withdrawal call `client.destroy({ discard: true })` to cancel pending transport
|
|
5
|
+
and remove its retained events and issue aggregates. Custom transports must honour
|
|
6
|
+
the provided `request.signal`. A late transport completion cannot recreate the
|
|
7
|
+
discarded queue; requests already received by a server cannot be recalled.
|
|
8
|
+
The semantic journey client's existing `destroy()` already aborts and discards.
|
|
9
|
+
|
|
3
10
|
[](https://www.npmjs.com/package/@plasius/analytics)
|
|
4
11
|
[](https://github.com/Plasius-LTD/analytics/actions/workflows/ci.yml)
|
|
5
12
|
[](https://codecov.io/gh/Plasius-LTD/analytics)
|
package/dist/index.cjs
CHANGED
|
@@ -290,7 +290,8 @@ async function defaultTransport({
|
|
|
290
290
|
endpoint,
|
|
291
291
|
body,
|
|
292
292
|
headers,
|
|
293
|
-
keepalive
|
|
293
|
+
keepalive,
|
|
294
|
+
signal
|
|
294
295
|
}) {
|
|
295
296
|
if (typeof fetch !== "function") {
|
|
296
297
|
return;
|
|
@@ -299,7 +300,8 @@ async function defaultTransport({
|
|
|
299
300
|
method: "POST",
|
|
300
301
|
headers,
|
|
301
302
|
body,
|
|
302
|
-
keepalive
|
|
303
|
+
keepalive,
|
|
304
|
+
signal
|
|
303
305
|
});
|
|
304
306
|
if (!response.ok) {
|
|
305
307
|
throw new Error(`Analytics transport failed with status ${response.status}.`);
|
|
@@ -853,6 +855,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
853
855
|
let isFlushing = false;
|
|
854
856
|
let flushQueuedAfterCurrent = false;
|
|
855
857
|
let isDestroyed = false;
|
|
858
|
+
const transportController = new AbortController();
|
|
856
859
|
const issueAggregates = /* @__PURE__ */ new Map();
|
|
857
860
|
const persistQueue = () => writeQueue(resolvedConfig.storageKey, queue);
|
|
858
861
|
const trimQueue = () => {
|
|
@@ -1019,12 +1022,14 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1019
1022
|
body,
|
|
1020
1023
|
headers: resolvedConfig.headers,
|
|
1021
1024
|
// Normal flushes do not need fetch keepalive; unload/pagehide uses sendBeacon.
|
|
1022
|
-
keepalive: false
|
|
1025
|
+
keepalive: false,
|
|
1026
|
+
signal: transportController.signal
|
|
1023
1027
|
});
|
|
1028
|
+
if (transportController.signal.aborted) return;
|
|
1024
1029
|
queue = queue.slice(events.length);
|
|
1025
1030
|
persistQueue();
|
|
1026
1031
|
} catch (error) {
|
|
1027
|
-
resolvedConfig.onError?.(error);
|
|
1032
|
+
if (!transportController.signal.aborted) resolvedConfig.onError?.(error);
|
|
1028
1033
|
} finally {
|
|
1029
1034
|
isFlushing = false;
|
|
1030
1035
|
if (flushQueuedAfterCurrent) {
|
|
@@ -1197,7 +1202,14 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1197
1202
|
getConfig() {
|
|
1198
1203
|
return resolvedConfig;
|
|
1199
1204
|
},
|
|
1200
|
-
destroy() {
|
|
1205
|
+
destroy(options) {
|
|
1206
|
+
if (options?.discard) {
|
|
1207
|
+
transportController.abort();
|
|
1208
|
+
queue = [];
|
|
1209
|
+
flushQueuedAfterCurrent = false;
|
|
1210
|
+
issueAggregates.clear();
|
|
1211
|
+
writeQueue(resolvedConfig.storageKey, []);
|
|
1212
|
+
}
|
|
1201
1213
|
if (isDestroyed) {
|
|
1202
1214
|
return;
|
|
1203
1215
|
}
|