@brainfish-ai/web-tracker 0.0.23 → 0.0.25
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/index.d.ts +10 -0
- package/dist/tracker.cjs.js +1 -1
- package/dist/tracker.cjs.js.gz +0 -0
- package/dist/tracker.cjs.js.map +1 -1
- package/dist/tracker.d.ts +1 -1
- package/dist/tracker.es.js +95 -9
- package/dist/tracker.es.js.gz +0 -0
- package/dist/tracker.es.js.map +1 -1
- package/dist/tracker.js +1 -1
- package/dist/tracker.js.gz +0 -0
- package/dist/tracker.js.map +1 -1
- package/package.json +2 -2
package/dist/tracker.d.ts
CHANGED
package/dist/tracker.es.js
CHANGED
|
@@ -3456,6 +3456,28 @@ class TTLSet {
|
|
|
3456
3456
|
return Array.from(this.items.keys());
|
|
3457
3457
|
}
|
|
3458
3458
|
}
|
|
3459
|
+
let latestIdentifyPayload = null;
|
|
3460
|
+
if (typeof window !== "undefined") {
|
|
3461
|
+
window.addEventListener("message", (event) => {
|
|
3462
|
+
const trustedOrigin = "https://agent.brainfi.sh";
|
|
3463
|
+
if (event.origin !== trustedOrigin) {
|
|
3464
|
+
return;
|
|
3465
|
+
}
|
|
3466
|
+
if (event.data?.type === "REQUEST_USER_IDENTITY") {
|
|
3467
|
+
if (latestIdentifyPayload && event.source) {
|
|
3468
|
+
const iframe = document.querySelector("#bf-iframe-container .trigger-iframe");
|
|
3469
|
+
if (!iframe || event.source !== iframe.contentWindow) {
|
|
3470
|
+
console.warn("BrainfishWidgetWarn: Rejected REQUEST_USER_IDENTITY from untrusted iframe source:", event.origin);
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
event.source.postMessage({
|
|
3474
|
+
type: "USER_IDENTIFY",
|
|
3475
|
+
payload: latestIdentifyPayload
|
|
3476
|
+
}, event.origin);
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3459
3481
|
var NudgeCTABlockActionType;
|
|
3460
3482
|
(function(NudgeCTABlockActionType2) {
|
|
3461
3483
|
NudgeCTABlockActionType2["OpenUrl"] = "openUrl";
|
|
@@ -3468,7 +3490,7 @@ var NudgeCTABlockType;
|
|
|
3468
3490
|
NudgeCTABlockType2["Button"] = "button";
|
|
3469
3491
|
NudgeCTABlockType2["Link"] = "link";
|
|
3470
3492
|
})(NudgeCTABlockType || (NudgeCTABlockType = {}));
|
|
3471
|
-
class
|
|
3493
|
+
const _TrackerSdk = class _TrackerSdk {
|
|
3472
3494
|
constructor(options) {
|
|
3473
3495
|
__publicField(this, "options");
|
|
3474
3496
|
__publicField(this, "client");
|
|
@@ -3480,6 +3502,7 @@ class TrackerSdk {
|
|
|
3480
3502
|
__publicField(this, "eventListeners", {});
|
|
3481
3503
|
// this set is used to prevent showing the same nudge multiple times in a short period
|
|
3482
3504
|
__publicField(this, "recentNudgeIds", new TTLSet(1e3));
|
|
3505
|
+
__publicField(this, "trackingDisabled", false);
|
|
3483
3506
|
this.options = options;
|
|
3484
3507
|
const query = {
|
|
3485
3508
|
sdk_name: options.sdk || "node",
|
|
@@ -3500,6 +3523,9 @@ class TrackerSdk {
|
|
|
3500
3523
|
version: options.sdkVersion || ""
|
|
3501
3524
|
}
|
|
3502
3525
|
});
|
|
3526
|
+
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
3527
|
+
this.trackingDisabled = localStorage.getItem(_TrackerSdk.TRACKING_DISABLED_KEY) === "true";
|
|
3528
|
+
}
|
|
3503
3529
|
this.setupIncomingPayloadHandler();
|
|
3504
3530
|
}
|
|
3505
3531
|
// placeholder for future use
|
|
@@ -3552,6 +3578,9 @@ class TrackerSdk {
|
|
|
3552
3578
|
if (this.options.disabled) {
|
|
3553
3579
|
return Promise.resolve();
|
|
3554
3580
|
}
|
|
3581
|
+
if (this.trackingDisabled) {
|
|
3582
|
+
return Promise.resolve();
|
|
3583
|
+
}
|
|
3555
3584
|
if (this.options.filter && !this.options.filter(payload)) {
|
|
3556
3585
|
return Promise.resolve();
|
|
3557
3586
|
}
|
|
@@ -3605,6 +3634,7 @@ class TrackerSdk {
|
|
|
3605
3634
|
if (payload.phone && !/^\+[1-9]\d{1,14}$/.test(payload.phone)) {
|
|
3606
3635
|
console.warn("BrainfishWidgetWarn: phone should be in E.164 format (e.g., +14155552671). Providing the correct format ensures accurate user identification.");
|
|
3607
3636
|
}
|
|
3637
|
+
latestIdentifyPayload = payload;
|
|
3608
3638
|
const iframe = document.querySelector("#bf-iframe-container .trigger-iframe");
|
|
3609
3639
|
if (iframe) {
|
|
3610
3640
|
const sendMessage = () => {
|
|
@@ -3637,6 +3667,9 @@ class TrackerSdk {
|
|
|
3637
3667
|
if (this.options.disabled) {
|
|
3638
3668
|
return Promise.resolve(null);
|
|
3639
3669
|
}
|
|
3670
|
+
if (this.trackingDisabled) {
|
|
3671
|
+
return Promise.resolve(null);
|
|
3672
|
+
}
|
|
3640
3673
|
const payload = {
|
|
3641
3674
|
type: "event.record",
|
|
3642
3675
|
payload: {
|
|
@@ -3686,7 +3719,37 @@ class TrackerSdk {
|
|
|
3686
3719
|
});
|
|
3687
3720
|
this.queue = [];
|
|
3688
3721
|
}
|
|
3689
|
-
|
|
3722
|
+
/**
|
|
3723
|
+
* Disables privacy-sensitive tracking features (recording, screenshots).
|
|
3724
|
+
* This setting persists across page reloads via localStorage.
|
|
3725
|
+
*/
|
|
3726
|
+
disableTracking() {
|
|
3727
|
+
this.trackingDisabled = true;
|
|
3728
|
+
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
3729
|
+
localStorage.setItem(_TrackerSdk.TRACKING_DISABLED_KEY, "true");
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Re-enables privacy-sensitive tracking features (recording, screenshots).
|
|
3734
|
+
* Note: Full effect requires a page reload to restart recording.
|
|
3735
|
+
*/
|
|
3736
|
+
enableTracking() {
|
|
3737
|
+
this.trackingDisabled = false;
|
|
3738
|
+
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
3739
|
+
localStorage.removeItem(_TrackerSdk.TRACKING_DISABLED_KEY);
|
|
3740
|
+
}
|
|
3741
|
+
console.log("Brainfish tracking re-enabled. Refresh page for full effect.");
|
|
3742
|
+
}
|
|
3743
|
+
/**
|
|
3744
|
+
* Returns whether privacy-sensitive tracking is currently disabled.
|
|
3745
|
+
* @returns true if tracking is disabled, false otherwise
|
|
3746
|
+
*/
|
|
3747
|
+
isTrackingDisabled() {
|
|
3748
|
+
return this.trackingDisabled;
|
|
3749
|
+
}
|
|
3750
|
+
};
|
|
3751
|
+
__publicField(_TrackerSdk, "TRACKING_DISABLED_KEY", "bf_tracking_disabled");
|
|
3752
|
+
let TrackerSdk = _TrackerSdk;
|
|
3690
3753
|
var cache = {
|
|
3691
3754
|
image: /* @__PURE__ */ new Map(),
|
|
3692
3755
|
background: /* @__PURE__ */ new Map(),
|
|
@@ -38440,9 +38503,8 @@ function toCamelCase(str) {
|
|
|
38440
38503
|
($1) => $1.toUpperCase().replace("-", "").replace("_", "")
|
|
38441
38504
|
);
|
|
38442
38505
|
}
|
|
38443
|
-
const VERSION = "0.0.
|
|
38506
|
+
const VERSION = "0.0.25";
|
|
38444
38507
|
class Tracker extends TrackerSdk {
|
|
38445
|
-
// 750KB
|
|
38446
38508
|
constructor(options) {
|
|
38447
38509
|
super({
|
|
38448
38510
|
sdk: "web",
|
|
@@ -38455,6 +38517,8 @@ class Tracker extends TrackerSdk {
|
|
|
38455
38517
|
__publicField(this, "sessionManager", SessionManager.getInstance());
|
|
38456
38518
|
__publicField(this, "recordingBlocklist", []);
|
|
38457
38519
|
__publicField(this, "MAX_SCREENSHOT_SIZE", 750 * 1024);
|
|
38520
|
+
// 750KB
|
|
38521
|
+
__publicField(this, "isRecordingActive", false);
|
|
38458
38522
|
this.options = options;
|
|
38459
38523
|
this.agent = new Agent();
|
|
38460
38524
|
this.recordingBlocklist = options.recordingBlocklist || [];
|
|
@@ -38462,17 +38526,19 @@ class Tracker extends TrackerSdk {
|
|
|
38462
38526
|
this.setGlobalProperties({
|
|
38463
38527
|
__referrer: document.referrer
|
|
38464
38528
|
});
|
|
38465
|
-
|
|
38529
|
+
const trackingDisabled = this.isTrackingDisabled();
|
|
38530
|
+
if (this.options.trackOutgoingLinks && !trackingDisabled) {
|
|
38466
38531
|
this.trackOutgoingLinks();
|
|
38467
38532
|
}
|
|
38468
38533
|
if (this.options.trackScreenViews) {
|
|
38469
38534
|
this.trackScreenViews();
|
|
38470
38535
|
}
|
|
38471
|
-
if (this.options.trackAttributes) {
|
|
38536
|
+
if (this.options.trackAttributes && !trackingDisabled) {
|
|
38472
38537
|
this.trackAttributes();
|
|
38473
38538
|
}
|
|
38474
|
-
if (this.options.enableRecording && this.options._allowScreenRecording) {
|
|
38539
|
+
if (this.options.enableRecording && this.options._allowScreenRecording && !trackingDisabled) {
|
|
38475
38540
|
this.startRecording();
|
|
38541
|
+
this.isRecordingActive = true;
|
|
38476
38542
|
console.log("Brainfish has started ambient learning");
|
|
38477
38543
|
}
|
|
38478
38544
|
}
|
|
@@ -38587,7 +38653,7 @@ class Tracker extends TrackerSdk {
|
|
|
38587
38653
|
__path: path,
|
|
38588
38654
|
__title: document.title
|
|
38589
38655
|
};
|
|
38590
|
-
if (this.options.enableRecording && canDiscover(
|
|
38656
|
+
if (this.options.enableRecording && !this.isTrackingDisabled() && canDiscover(
|
|
38591
38657
|
this.recordingBlocklist,
|
|
38592
38658
|
this.options._allowLocalhostRecording
|
|
38593
38659
|
)) {
|
|
@@ -38625,6 +38691,26 @@ class Tracker extends TrackerSdk {
|
|
|
38625
38691
|
super.track("screen_view", props);
|
|
38626
38692
|
this.sessionManager.updateLastScreenViewEventTime();
|
|
38627
38693
|
}
|
|
38694
|
+
/**
|
|
38695
|
+
* Disables privacy-sensitive tracking features and stops active recording.
|
|
38696
|
+
*/
|
|
38697
|
+
disableTracking() {
|
|
38698
|
+
super.disableTracking();
|
|
38699
|
+
if (this.isRecordingActive) {
|
|
38700
|
+
if (this.agent.recordingManager.recorder.stop) {
|
|
38701
|
+
this.agent.recordingManager.recorder.stop();
|
|
38702
|
+
}
|
|
38703
|
+
this.isRecordingActive = false;
|
|
38704
|
+
console.log("Brainfish has stopped ambient learning");
|
|
38705
|
+
}
|
|
38706
|
+
}
|
|
38707
|
+
/**
|
|
38708
|
+
* Re-enables privacy-sensitive tracking features.
|
|
38709
|
+
* Note: Full effect requires a page reload to restart recording and event listeners.
|
|
38710
|
+
*/
|
|
38711
|
+
enableTracking() {
|
|
38712
|
+
super.enableTracking();
|
|
38713
|
+
}
|
|
38628
38714
|
}
|
|
38629
38715
|
((window2) => {
|
|
38630
38716
|
if (window2.BrainfishAnalytics && "q" in window2.BrainfishAnalytics) {
|
|
@@ -38644,7 +38730,7 @@ class Tracker extends TrackerSdk {
|
|
|
38644
38730
|
window2.BrainfishAnalytics = (t, ...args) => {
|
|
38645
38731
|
const fn = tracker[t] ? tracker[t].bind(tracker) : void 0;
|
|
38646
38732
|
if (typeof fn === "function") {
|
|
38647
|
-
fn(...args);
|
|
38733
|
+
return fn(...args);
|
|
38648
38734
|
} else {
|
|
38649
38735
|
console.warn(`Method ${t} does not exist on BrainfishAnalytics`);
|
|
38650
38736
|
}
|
package/dist/tracker.es.js.gz
CHANGED
|
Binary file
|