@cstar.help/js 0.10.0 → 0.10.2
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/dist/proactive/index.cjs +27 -11
- package/dist/proactive/index.js +27 -11
- package/package.json +1 -1
package/dist/proactive/index.cjs
CHANGED
|
@@ -286,19 +286,34 @@ var TriggerEngine = class {
|
|
|
286
286
|
}
|
|
287
287
|
return this.cooldownSeconds;
|
|
288
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Send analytics beacon (fire-and-forget).
|
|
291
|
+
* Must use application/json — SvelteKit CSRF rejects text/plain cross-origin.
|
|
292
|
+
* Falls back to fetch() if sendBeacon is unavailable or fails.
|
|
293
|
+
*/
|
|
289
294
|
sendEvent(eventType, signalType, metadata) {
|
|
295
|
+
const url = this.baseUrl + "/api/widget/proactive-events";
|
|
296
|
+
const payload = JSON.stringify({
|
|
297
|
+
teamId: this.teamId,
|
|
298
|
+
eventType,
|
|
299
|
+
signalType,
|
|
300
|
+
metadata: metadata || {}
|
|
301
|
+
});
|
|
290
302
|
try {
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
eventType,
|
|
294
|
-
signalType,
|
|
295
|
-
metadata: metadata || {}
|
|
296
|
-
});
|
|
297
|
-
navigator.sendBeacon(
|
|
298
|
-
this.baseUrl + "/api/widget/proactive-events",
|
|
299
|
-
new Blob([payload], { type: "application/json" })
|
|
300
|
-
);
|
|
303
|
+
const queued = navigator.sendBeacon?.(url, new Blob([payload], { type: "application/json" }));
|
|
304
|
+
if (!queued) throw void 0;
|
|
301
305
|
} catch {
|
|
306
|
+
try {
|
|
307
|
+
fetch(url, {
|
|
308
|
+
method: "POST",
|
|
309
|
+
body: payload,
|
|
310
|
+
headers: { "Content-Type": "application/json" },
|
|
311
|
+
keepalive: true,
|
|
312
|
+
mode: "cors"
|
|
313
|
+
}).catch(() => {
|
|
314
|
+
});
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
302
317
|
}
|
|
303
318
|
}
|
|
304
319
|
handleSignal(signal) {
|
|
@@ -446,7 +461,8 @@ var ProactiveClient = class {
|
|
|
446
461
|
};
|
|
447
462
|
if (signals.rageClick) this.detectors.push(createRageClickDetector(onSignal));
|
|
448
463
|
if (signals.exitIntent) this.detectors.push(createExitIntentDetector(onSignal));
|
|
449
|
-
if (signals.idleTimeout > 0)
|
|
464
|
+
if (signals.idleTimeout > 0)
|
|
465
|
+
this.detectors.push(createIdleDetector(onSignal, signals.idleTimeout));
|
|
450
466
|
if (signals.errorLoop) this.detectors.push(createErrorLoopDetector(onSignal));
|
|
451
467
|
if (signals.formAbandonment) this.detectors.push(createFormAbandonmentDetector(onSignal));
|
|
452
468
|
if (signals.scrollThrash) this.detectors.push(createScrollThrashDetector(onSignal));
|
package/dist/proactive/index.js
CHANGED
|
@@ -262,19 +262,34 @@ var TriggerEngine = class {
|
|
|
262
262
|
}
|
|
263
263
|
return this.cooldownSeconds;
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Send analytics beacon (fire-and-forget).
|
|
267
|
+
* Must use application/json — SvelteKit CSRF rejects text/plain cross-origin.
|
|
268
|
+
* Falls back to fetch() if sendBeacon is unavailable or fails.
|
|
269
|
+
*/
|
|
265
270
|
sendEvent(eventType, signalType, metadata) {
|
|
271
|
+
const url = this.baseUrl + "/api/widget/proactive-events";
|
|
272
|
+
const payload = JSON.stringify({
|
|
273
|
+
teamId: this.teamId,
|
|
274
|
+
eventType,
|
|
275
|
+
signalType,
|
|
276
|
+
metadata: metadata || {}
|
|
277
|
+
});
|
|
266
278
|
try {
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
eventType,
|
|
270
|
-
signalType,
|
|
271
|
-
metadata: metadata || {}
|
|
272
|
-
});
|
|
273
|
-
navigator.sendBeacon(
|
|
274
|
-
this.baseUrl + "/api/widget/proactive-events",
|
|
275
|
-
new Blob([payload], { type: "application/json" })
|
|
276
|
-
);
|
|
279
|
+
const queued = navigator.sendBeacon?.(url, new Blob([payload], { type: "application/json" }));
|
|
280
|
+
if (!queued) throw void 0;
|
|
277
281
|
} catch {
|
|
282
|
+
try {
|
|
283
|
+
fetch(url, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: payload,
|
|
286
|
+
headers: { "Content-Type": "application/json" },
|
|
287
|
+
keepalive: true,
|
|
288
|
+
mode: "cors"
|
|
289
|
+
}).catch(() => {
|
|
290
|
+
});
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
278
293
|
}
|
|
279
294
|
}
|
|
280
295
|
handleSignal(signal) {
|
|
@@ -422,7 +437,8 @@ var ProactiveClient = class {
|
|
|
422
437
|
};
|
|
423
438
|
if (signals.rageClick) this.detectors.push(createRageClickDetector(onSignal));
|
|
424
439
|
if (signals.exitIntent) this.detectors.push(createExitIntentDetector(onSignal));
|
|
425
|
-
if (signals.idleTimeout > 0)
|
|
440
|
+
if (signals.idleTimeout > 0)
|
|
441
|
+
this.detectors.push(createIdleDetector(onSignal, signals.idleTimeout));
|
|
426
442
|
if (signals.errorLoop) this.detectors.push(createErrorLoopDetector(onSignal));
|
|
427
443
|
if (signals.formAbandonment) this.detectors.push(createFormAbandonmentDetector(onSignal));
|
|
428
444
|
if (signals.scrollThrash) this.detectors.push(createScrollThrashDetector(onSignal));
|