@stacksee/analytics 0.9.2 → 0.9.4
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/core/events/types.d.ts +4 -0
- package/dist/providers/client.js +88 -65
- package/dist/providers/server.js +125 -92
- package/package.json +1 -1
package/dist/providers/client.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var r = (l, h, i) =>
|
|
4
|
-
import { B as
|
|
2
|
+
var g = (l, h, i) => h in l ? u(l, h, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[h] = i;
|
|
3
|
+
var r = (l, h, i) => g(l, typeof h != "symbol" ? h + "" : h, i);
|
|
4
|
+
import { B as o } from "../base.provider-AfFL5W_P.js";
|
|
5
5
|
import { i as a } from "../client-DTHZYkxx.js";
|
|
6
6
|
import { P as E } from "../client-DTHZYkxx.js";
|
|
7
|
-
class b extends
|
|
7
|
+
class b extends o {
|
|
8
8
|
constructor(i) {
|
|
9
9
|
super({ debug: i.debug, enabled: i.enabled });
|
|
10
10
|
r(this, "name", "Bento-Client");
|
|
@@ -37,35 +37,35 @@ class b extends d {
|
|
|
37
37
|
this.scriptLoaded = !0, i();
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const t = document.createElement("script");
|
|
41
|
+
t.src = `https://fast.bentonow.com?site_uuid=${this.config.siteUuid}`, t.async = !0, t.defer = !0, t.onload = () => {
|
|
42
42
|
this.scriptLoaded = !0, i();
|
|
43
|
-
},
|
|
43
|
+
}, t.onerror = () => {
|
|
44
44
|
e(new Error("Failed to load Bento script"));
|
|
45
|
-
}, document.head.appendChild(
|
|
45
|
+
}, document.head.appendChild(t);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
async waitForBento(i = 50, e = 100) {
|
|
49
|
-
for (let
|
|
49
|
+
for (let s = 0; s < i; s++) {
|
|
50
50
|
if (window.bento)
|
|
51
51
|
return;
|
|
52
|
-
await new Promise((
|
|
52
|
+
await new Promise((t) => setTimeout(t, e));
|
|
53
53
|
}
|
|
54
54
|
throw new Error("Bento SDK not available after loading script");
|
|
55
55
|
}
|
|
56
56
|
identify(i, e) {
|
|
57
57
|
if (!this.isEnabled() || !this.initialized || !this.bento) return;
|
|
58
|
-
const
|
|
59
|
-
if (this.bento.identify(
|
|
60
|
-
const
|
|
61
|
-
delete
|
|
58
|
+
const s = (e == null ? void 0 : e.email) || i;
|
|
59
|
+
if (this.bento.identify(s), e) {
|
|
60
|
+
const t = { ...e };
|
|
61
|
+
delete t.email, Object.keys(t).length > 0 && this.bento.updateFields(t);
|
|
62
62
|
}
|
|
63
|
-
this.log("Identified user", { userId: i, email:
|
|
63
|
+
this.log("Identified user", { userId: i, email: s, traits: e });
|
|
64
64
|
}
|
|
65
65
|
track(i, e) {
|
|
66
|
-
var
|
|
66
|
+
var t, n, d;
|
|
67
67
|
if (!this.isEnabled() || !this.initialized || !this.bento) return;
|
|
68
|
-
const
|
|
68
|
+
const s = {
|
|
69
69
|
...i.properties,
|
|
70
70
|
category: i.category,
|
|
71
71
|
timestamp: i.timestamp || Date.now(),
|
|
@@ -73,29 +73,43 @@ class b extends d {
|
|
|
73
73
|
...i.sessionId && { sessionId: i.sessionId },
|
|
74
74
|
...(e == null ? void 0 : e.page) && {
|
|
75
75
|
page: {
|
|
76
|
+
url: e.page.url,
|
|
77
|
+
host: e.page.host,
|
|
76
78
|
path: e.page.path,
|
|
77
79
|
title: e.page.title,
|
|
78
|
-
|
|
80
|
+
protocol: e.page.protocol,
|
|
81
|
+
referrer: e.page.referrer,
|
|
82
|
+
...e.page.search && { search: e.page.search }
|
|
79
83
|
}
|
|
80
84
|
},
|
|
81
85
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
82
86
|
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
83
87
|
// Include user email and traits as regular event properties
|
|
84
|
-
...((
|
|
85
|
-
...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits }
|
|
88
|
+
...((t = e == null ? void 0 : e.user) == null ? void 0 : t.email) && { user_email: e.user.email },
|
|
89
|
+
...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits },
|
|
90
|
+
...((d = e == null ? void 0 : e.user) == null ? void 0 : d.userId) && { visitor: e.user.userId }
|
|
86
91
|
};
|
|
87
|
-
this.bento.track(i.action,
|
|
92
|
+
this.bento.track(i.action, s), this.log("Tracked event", { event: i, context: e });
|
|
88
93
|
}
|
|
89
94
|
pageView(i, e) {
|
|
95
|
+
var s;
|
|
90
96
|
if (!(!this.isEnabled() || !this.initialized || !this.bento || !a())) {
|
|
91
97
|
if (this.bento.view(), i || e != null && e.page) {
|
|
92
98
|
const t = {
|
|
93
99
|
...i,
|
|
100
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
94
101
|
...(e == null ? void 0 : e.page) && {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
page: {
|
|
103
|
+
url: e.page.url,
|
|
104
|
+
host: e.page.host,
|
|
105
|
+
path: e.page.path,
|
|
106
|
+
title: e.page.title,
|
|
107
|
+
protocol: e.page.protocol,
|
|
108
|
+
referrer: e.page.referrer,
|
|
109
|
+
...e.page.search && { search: e.page.search }
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
...((s = e == null ? void 0 : e.user) == null ? void 0 : s.userId) && { visitor: e.user.userId }
|
|
99
113
|
};
|
|
100
114
|
this.bento.track("$view", t);
|
|
101
115
|
}
|
|
@@ -103,17 +117,26 @@ class b extends d {
|
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
119
|
pageLeave(i, e) {
|
|
120
|
+
var t;
|
|
106
121
|
if (!this.isEnabled() || !this.initialized || !this.bento || !a())
|
|
107
122
|
return;
|
|
108
|
-
const
|
|
123
|
+
const s = {
|
|
109
124
|
...i,
|
|
125
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
110
126
|
...(e == null ? void 0 : e.page) && {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
page: {
|
|
128
|
+
url: e.page.url,
|
|
129
|
+
host: e.page.host,
|
|
130
|
+
path: e.page.path,
|
|
131
|
+
title: e.page.title,
|
|
132
|
+
protocol: e.page.protocol,
|
|
133
|
+
referrer: e.page.referrer,
|
|
134
|
+
...e.page.search && { search: e.page.search }
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
...((t = e == null ? void 0 : e.user) == null ? void 0 : t.userId) && { visitor: e.user.userId }
|
|
115
138
|
};
|
|
116
|
-
this.bento.track("$pageleave",
|
|
139
|
+
this.bento.track("$pageleave", s), this.log("Tracked page leave", { properties: i, context: e });
|
|
117
140
|
}
|
|
118
141
|
reset() {
|
|
119
142
|
!this.isEnabled() || !this.initialized || !this.bento || !a() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
|
|
@@ -183,8 +206,8 @@ class b extends d {
|
|
|
183
206
|
* }
|
|
184
207
|
* ```
|
|
185
208
|
*/
|
|
186
|
-
showSurveyForm(i, e,
|
|
187
|
-
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.showSurveyForm(i, e,
|
|
209
|
+
showSurveyForm(i, e, s = "popup") {
|
|
210
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.showSurveyForm(i, e, s), this.log("Showed survey form", { surveyId: e, type: s }));
|
|
188
211
|
}
|
|
189
212
|
/**
|
|
190
213
|
* Validate an email address using Bento's spam check
|
|
@@ -253,7 +276,7 @@ class b extends d {
|
|
|
253
276
|
));
|
|
254
277
|
}
|
|
255
278
|
}
|
|
256
|
-
class w extends
|
|
279
|
+
class w extends o {
|
|
257
280
|
constructor(i) {
|
|
258
281
|
super({ debug: i.debug, enabled: i.enabled });
|
|
259
282
|
r(this, "name", "Pirsch-Client");
|
|
@@ -288,14 +311,14 @@ class w extends d {
|
|
|
288
311
|
!this.isEnabled() || !this.initialized || !this.client || (this.client.event("user_identified", 0, {
|
|
289
312
|
userId: i,
|
|
290
313
|
...e
|
|
291
|
-
}).catch((
|
|
292
|
-
console.error("[Pirsch-Client] Failed to track identify event:",
|
|
314
|
+
}).catch((s) => {
|
|
315
|
+
console.error("[Pirsch-Client] Failed to track identify event:", s);
|
|
293
316
|
}), this.log("Identified user via event", { userId: i, traits: e }));
|
|
294
317
|
}
|
|
295
318
|
async track(i, e) {
|
|
296
|
-
var
|
|
319
|
+
var t, n;
|
|
297
320
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
298
|
-
const
|
|
321
|
+
const s = {
|
|
299
322
|
...i.properties,
|
|
300
323
|
category: i.category,
|
|
301
324
|
...i.userId && { userId: i.userId },
|
|
@@ -307,21 +330,21 @@ class w extends d {
|
|
|
307
330
|
},
|
|
308
331
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
309
332
|
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
310
|
-
...((
|
|
333
|
+
...((t = e == null ? void 0 : e.user) == null ? void 0 : t.email) && { user_email: e.user.email },
|
|
311
334
|
...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits }
|
|
312
335
|
};
|
|
313
336
|
try {
|
|
314
|
-
await this.client.event(i.action, 0,
|
|
315
|
-
} catch (
|
|
316
|
-
console.error("[Pirsch-Client] Failed to track event:",
|
|
337
|
+
await this.client.event(i.action, 0, s), this.log("Tracked event", { event: i, context: e });
|
|
338
|
+
} catch (d) {
|
|
339
|
+
console.error("[Pirsch-Client] Failed to track event:", d);
|
|
317
340
|
}
|
|
318
341
|
}
|
|
319
342
|
pageView(i, e) {
|
|
320
343
|
if (!(!this.isEnabled() || !this.initialized || !this.client || !a())) {
|
|
321
|
-
if (this.client.hit().catch((
|
|
322
|
-
console.error("[Pirsch-Client] Failed to track page view:",
|
|
344
|
+
if (this.client.hit().catch((s) => {
|
|
345
|
+
console.error("[Pirsch-Client] Failed to track page view:", s);
|
|
323
346
|
}), i && Object.keys(i).length > 0) {
|
|
324
|
-
const
|
|
347
|
+
const s = {
|
|
325
348
|
...i,
|
|
326
349
|
...(e == null ? void 0 : e.page) && {
|
|
327
350
|
path: e.page.path,
|
|
@@ -329,10 +352,10 @@ class w extends d {
|
|
|
329
352
|
referrer: e.page.referrer
|
|
330
353
|
}
|
|
331
354
|
};
|
|
332
|
-
this.client.event("page_view", 0,
|
|
355
|
+
this.client.event("page_view", 0, s).catch((t) => {
|
|
333
356
|
console.error(
|
|
334
357
|
"[Pirsch-Client] Failed to track page view event:",
|
|
335
|
-
|
|
358
|
+
t
|
|
336
359
|
);
|
|
337
360
|
});
|
|
338
361
|
}
|
|
@@ -342,15 +365,15 @@ class w extends d {
|
|
|
342
365
|
pageLeave(i, e) {
|
|
343
366
|
if (!this.isEnabled() || !this.initialized || !this.client || !a())
|
|
344
367
|
return;
|
|
345
|
-
const
|
|
368
|
+
const s = {
|
|
346
369
|
...i,
|
|
347
370
|
...(e == null ? void 0 : e.page) && {
|
|
348
371
|
path: e.page.path,
|
|
349
372
|
title: e.page.title
|
|
350
373
|
}
|
|
351
374
|
};
|
|
352
|
-
this.client.event("page_leave", 0,
|
|
353
|
-
console.error("[Pirsch-Client] Failed to track page leave:",
|
|
375
|
+
this.client.event("page_leave", 0, s).catch((t) => {
|
|
376
|
+
console.error("[Pirsch-Client] Failed to track page leave:", t);
|
|
354
377
|
}), this.log("Tracked page leave", { properties: i, context: e });
|
|
355
378
|
}
|
|
356
379
|
reset() {
|
|
@@ -359,9 +382,9 @@ class w extends d {
|
|
|
359
382
|
}), this.log("Reset user session"));
|
|
360
383
|
}
|
|
361
384
|
}
|
|
362
|
-
class y extends
|
|
385
|
+
class y extends o {
|
|
363
386
|
constructor(i) {
|
|
364
|
-
var e,
|
|
387
|
+
var e, s, t, n, d;
|
|
365
388
|
super({ debug: i.debug, enabled: i.enabled });
|
|
366
389
|
r(this, "name", "Proxy");
|
|
367
390
|
r(this, "config");
|
|
@@ -372,7 +395,7 @@ class y extends d {
|
|
|
372
395
|
r(this, "retryAttempts");
|
|
373
396
|
r(this, "retryBackoff");
|
|
374
397
|
r(this, "retryInitialDelay");
|
|
375
|
-
this.config = i, this.batchSize = ((e = i.batch) == null ? void 0 : e.size) ?? 10, this.batchInterval = ((
|
|
398
|
+
this.config = i, this.batchSize = ((e = i.batch) == null ? void 0 : e.size) ?? 10, this.batchInterval = ((s = i.batch) == null ? void 0 : s.interval) ?? 5e3, this.retryAttempts = ((t = i.retry) == null ? void 0 : t.attempts) ?? 3, this.retryBackoff = ((n = i.retry) == null ? void 0 : n.backoff) ?? "exponential", this.retryInitialDelay = ((d = i.retry) == null ? void 0 : d.initialDelay) ?? 1e3, typeof window < "u" && (window.addEventListener("beforeunload", () => {
|
|
376
399
|
this.flush(!0);
|
|
377
400
|
}), document.addEventListener("visibilitychange", () => {
|
|
378
401
|
document.visibilityState === "hidden" && this.flush(!0);
|
|
@@ -432,19 +455,19 @@ class y extends d {
|
|
|
432
455
|
}, this.batchInterval));
|
|
433
456
|
}
|
|
434
457
|
async sendEvents(i, e = !1) {
|
|
435
|
-
const
|
|
458
|
+
const s = { events: i };
|
|
436
459
|
if (e && typeof navigator < "u" && navigator.sendBeacon) {
|
|
437
|
-
const
|
|
460
|
+
const t = new Blob([JSON.stringify(s)], {
|
|
438
461
|
type: "application/json"
|
|
439
462
|
});
|
|
440
|
-
navigator.sendBeacon(this.config.endpoint,
|
|
463
|
+
navigator.sendBeacon(this.config.endpoint, t) || console.warn("[Proxy] Failed to send events via beacon");
|
|
441
464
|
return;
|
|
442
465
|
}
|
|
443
|
-
await this.sendWithRetry(
|
|
466
|
+
await this.sendWithRetry(s);
|
|
444
467
|
}
|
|
445
468
|
async sendWithRetry(i, e = 0) {
|
|
446
469
|
try {
|
|
447
|
-
const
|
|
470
|
+
const s = await fetch(this.config.endpoint, {
|
|
448
471
|
method: "POST",
|
|
449
472
|
headers: {
|
|
450
473
|
"Content-Type": "application/json",
|
|
@@ -454,15 +477,15 @@ class y extends d {
|
|
|
454
477
|
// Don't include credentials by default
|
|
455
478
|
credentials: "same-origin"
|
|
456
479
|
});
|
|
457
|
-
if (!
|
|
458
|
-
throw new Error(`HTTP ${
|
|
480
|
+
if (!s.ok)
|
|
481
|
+
throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
459
482
|
this.log(`Sent ${i.events.length} events successfully`);
|
|
460
|
-
} catch (
|
|
483
|
+
} catch (s) {
|
|
461
484
|
if (e < this.retryAttempts) {
|
|
462
|
-
const
|
|
463
|
-
return this.log(`Retry attempt ${e + 1} after ${
|
|
485
|
+
const t = this.calculateRetryDelay(e);
|
|
486
|
+
return this.log(`Retry attempt ${e + 1} after ${t}ms`, { error: s }), await new Promise((n) => setTimeout(n, t)), this.sendWithRetry(i, e + 1);
|
|
464
487
|
}
|
|
465
|
-
throw console.error("[Proxy] Failed to send events after retries:",
|
|
488
|
+
throw console.error("[Proxy] Failed to send events after retries:", s), s;
|
|
466
489
|
}
|
|
467
490
|
}
|
|
468
491
|
calculateRetryDelay(i) {
|
|
@@ -499,7 +522,7 @@ class y extends d {
|
|
|
499
522
|
}
|
|
500
523
|
}
|
|
501
524
|
export {
|
|
502
|
-
|
|
525
|
+
o as BaseAnalyticsProvider,
|
|
503
526
|
b as BentoClientProvider,
|
|
504
527
|
w as PirschClientProvider,
|
|
505
528
|
E as PostHogClientProvider,
|
package/dist/providers/server.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var f = Object.defineProperty;
|
|
2
2
|
var y = (l, n, i) => n in l ? f(l, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[n] = i;
|
|
3
3
|
var d = (l, n, i) => y(l, typeof n != "symbol" ? n + "" : n, i);
|
|
4
|
-
import { B as
|
|
5
|
-
import { P
|
|
6
|
-
class
|
|
4
|
+
import { B as c } from "../base.provider-AfFL5W_P.js";
|
|
5
|
+
import { P } from "../server-DjEk1fUD.js";
|
|
6
|
+
class w extends c {
|
|
7
7
|
constructor(i) {
|
|
8
8
|
super({ debug: i.debug, enabled: i.enabled });
|
|
9
9
|
d(this, "name", "Bento-Server");
|
|
@@ -23,77 +23,110 @@ class v extends p {
|
|
|
23
23
|
if (!((e = this.config.authentication) != null && e.secretKey) || typeof this.config.authentication.secretKey != "string")
|
|
24
24
|
throw new Error("Bento requires authentication.secretKey");
|
|
25
25
|
try {
|
|
26
|
-
const { Analytics:
|
|
27
|
-
this.client = new
|
|
26
|
+
const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: t, enabled: a, ...o } = this.config;
|
|
27
|
+
this.client = new r(o), this.initialized = !0, this.log("Initialized successfully", {
|
|
28
28
|
siteUuid: this.config.siteUuid
|
|
29
29
|
});
|
|
30
|
-
} catch (
|
|
30
|
+
} catch (r) {
|
|
31
31
|
throw console.error(
|
|
32
32
|
"[Bento-Server] Failed to initialize. Make sure @bentonow/bento-node-sdk is installed:",
|
|
33
|
-
|
|
34
|
-
),
|
|
33
|
+
r
|
|
34
|
+
), r;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
identify(i, e) {
|
|
39
39
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const r = (e == null ? void 0 : e.email) || i;
|
|
41
|
+
if (!r || !r.includes("@")) {
|
|
42
|
+
this.log("Skipping identify - invalid or missing email", { userId: i, traits: e });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.currentUserEmail = r;
|
|
46
|
+
const t = e ? { ...e } : {};
|
|
47
|
+
delete t.email, this.client.V1.addSubscriber({
|
|
48
|
+
email: r,
|
|
49
|
+
fields: t
|
|
50
|
+
}).catch((a) => {
|
|
51
|
+
console.error("[Bento-Server] Failed to identify user:", a);
|
|
52
|
+
}), this.log("Identified user", { userId: i, email: r, traits: e });
|
|
49
53
|
}
|
|
50
54
|
async track(i, e) {
|
|
51
|
-
var o,
|
|
55
|
+
var o, s, h, u;
|
|
52
56
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
53
|
-
const
|
|
57
|
+
const r = ((o = e == null ? void 0 : e.user) == null ? void 0 : o.email) || this.currentUserEmail || ((s = e == null ? void 0 : e.user) == null ? void 0 : s.userId) || i.userId;
|
|
58
|
+
if (!r || !r.includes("@")) {
|
|
59
|
+
console.warn(
|
|
60
|
+
"[Bento-Server] Skipping event - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const t = {
|
|
54
65
|
...i.properties,
|
|
55
66
|
category: i.category,
|
|
56
67
|
timestamp: i.timestamp || Date.now(),
|
|
57
68
|
...i.sessionId && { sessionId: i.sessionId },
|
|
58
69
|
...(e == null ? void 0 : e.page) && {
|
|
59
70
|
page: {
|
|
71
|
+
url: e.page.url,
|
|
72
|
+
host: e.page.host,
|
|
60
73
|
path: e.page.path,
|
|
61
74
|
title: e.page.title,
|
|
62
|
-
|
|
75
|
+
protocol: e.page.protocol,
|
|
76
|
+
referrer: e.page.referrer,
|
|
77
|
+
...e.page.search && { search: e.page.search }
|
|
63
78
|
}
|
|
64
79
|
},
|
|
65
80
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
66
|
-
...(e == null ? void 0 : e.utm) && { utm: e.utm }
|
|
67
|
-
|
|
81
|
+
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
82
|
+
site: this.config.siteUuid,
|
|
83
|
+
...((h = e == null ? void 0 : e.user) == null ? void 0 : h.userId) && { visitor: e.user.userId }
|
|
84
|
+
}, a = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.traits) || {};
|
|
68
85
|
try {
|
|
69
86
|
await this.client.V1.track({
|
|
70
|
-
email:
|
|
87
|
+
email: r,
|
|
71
88
|
type: `$${i.action}`,
|
|
72
|
-
details:
|
|
73
|
-
fields:
|
|
89
|
+
details: t,
|
|
90
|
+
fields: a
|
|
74
91
|
}), this.log("Tracked event", { event: i, context: e });
|
|
75
|
-
} catch (
|
|
76
|
-
console.error("[Bento-Server] Failed to track event:",
|
|
92
|
+
} catch (p) {
|
|
93
|
+
console.error("[Bento-Server] Failed to track event:", p);
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
pageView(i, e) {
|
|
80
|
-
var o,
|
|
97
|
+
var o, s, h;
|
|
81
98
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
82
|
-
const
|
|
99
|
+
const r = ((o = e == null ? void 0 : e.user) == null ? void 0 : o.email) || this.currentUserEmail;
|
|
100
|
+
if (!r || !r.includes("@")) {
|
|
101
|
+
console.warn(
|
|
102
|
+
"[Bento-Server] Skipping pageView - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const t = {
|
|
83
107
|
...i,
|
|
108
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
84
109
|
...(e == null ? void 0 : e.page) && {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
page: {
|
|
111
|
+
url: e.page.url,
|
|
112
|
+
host: e.page.host,
|
|
113
|
+
path: e.page.path,
|
|
114
|
+
title: e.page.title,
|
|
115
|
+
protocol: e.page.protocol,
|
|
116
|
+
referrer: e.page.referrer,
|
|
117
|
+
...e.page.search && { search: e.page.search }
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
site: this.config.siteUuid,
|
|
121
|
+
...((s = e == null ? void 0 : e.user) == null ? void 0 : s.userId) && { visitor: e.user.userId }
|
|
122
|
+
}, a = ((h = e == null ? void 0 : e.user) == null ? void 0 : h.traits) || {};
|
|
90
123
|
this.client.V1.track({
|
|
91
|
-
email:
|
|
124
|
+
email: r,
|
|
92
125
|
type: "$view",
|
|
93
|
-
details:
|
|
94
|
-
fields:
|
|
95
|
-
}).catch((
|
|
96
|
-
console.error("[Bento-Server] Failed to track page view:",
|
|
126
|
+
details: t,
|
|
127
|
+
fields: a
|
|
128
|
+
}).catch((u) => {
|
|
129
|
+
console.error("[Bento-Server] Failed to track page view:", u);
|
|
97
130
|
}), this.log("Tracked page view", { properties: i, context: e });
|
|
98
131
|
}
|
|
99
132
|
async reset() {
|
|
@@ -103,7 +136,7 @@ class v extends p {
|
|
|
103
136
|
this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
|
|
104
137
|
}
|
|
105
138
|
}
|
|
106
|
-
class
|
|
139
|
+
class k extends c {
|
|
107
140
|
constructor(i) {
|
|
108
141
|
super({ debug: i.debug, enabled: i.enabled });
|
|
109
142
|
d(this, "name", "Pirsch-Server");
|
|
@@ -119,8 +152,8 @@ class E extends p {
|
|
|
119
152
|
if (!this.config.clientSecret || typeof this.config.clientSecret != "string")
|
|
120
153
|
throw new Error("Pirsch requires a clientSecret (or access key)");
|
|
121
154
|
try {
|
|
122
|
-
const { Pirsch: i } = await import("../index-zS7gy63J.js").then((
|
|
123
|
-
this.client = new i(
|
|
155
|
+
const { Pirsch: i } = await import("../index-zS7gy63J.js").then((a) => a.i), { debug: e, enabled: r, ...t } = this.config;
|
|
156
|
+
this.client = new i(t), this.initialized = !0, this.log("Initialized successfully", {
|
|
124
157
|
hostname: this.config.hostname
|
|
125
158
|
});
|
|
126
159
|
} catch (i) {
|
|
@@ -133,37 +166,37 @@ class E extends p {
|
|
|
133
166
|
}
|
|
134
167
|
identify(i, e) {
|
|
135
168
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
136
|
-
const
|
|
169
|
+
const r = {
|
|
137
170
|
url: "https://identify",
|
|
138
171
|
ip: "0.0.0.0",
|
|
139
172
|
user_agent: "analytics-library"
|
|
140
|
-
},
|
|
173
|
+
}, t = {
|
|
141
174
|
userId: i,
|
|
142
175
|
...e && Object.fromEntries(
|
|
143
176
|
Object.entries(e).filter(
|
|
144
|
-
([,
|
|
177
|
+
([, a]) => typeof a == "string" || typeof a == "number" || typeof a == "boolean"
|
|
145
178
|
)
|
|
146
179
|
)
|
|
147
180
|
};
|
|
148
|
-
this.client.event("user_identified",
|
|
149
|
-
console.error("[Pirsch-Server] Failed to track identify event:",
|
|
181
|
+
this.client.event("user_identified", r, 0, t).catch((a) => {
|
|
182
|
+
console.error("[Pirsch-Server] Failed to track identify event:", a);
|
|
150
183
|
}), this.log("Identified user via event", { userId: i, traits: e });
|
|
151
184
|
}
|
|
152
185
|
async track(i, e) {
|
|
153
|
-
var o,
|
|
186
|
+
var o, s, h, u;
|
|
154
187
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
155
|
-
const
|
|
188
|
+
const r = {
|
|
156
189
|
url: ((o = e == null ? void 0 : e.page) == null ? void 0 : o.path) || "https://event",
|
|
157
190
|
ip: "0.0.0.0",
|
|
158
191
|
// Server-side should provide real IP if available
|
|
159
192
|
user_agent: "analytics-library",
|
|
160
193
|
// Server-side should provide real UA if available
|
|
161
|
-
...((
|
|
194
|
+
...((s = e == null ? void 0 : e.page) == null ? void 0 : s.title) && { title: e.page.title },
|
|
162
195
|
...((h = e == null ? void 0 : e.page) == null ? void 0 : h.referrer) && { referrer: e.page.referrer }
|
|
163
|
-
},
|
|
196
|
+
}, a = {
|
|
164
197
|
...Object.fromEntries(
|
|
165
198
|
Object.entries(i.properties).filter(
|
|
166
|
-
([,
|
|
199
|
+
([, p]) => typeof p == "string" || typeof p == "number" || typeof p == "boolean"
|
|
167
200
|
)
|
|
168
201
|
),
|
|
169
202
|
category: i.category,
|
|
@@ -173,32 +206,32 @@ class E extends p {
|
|
|
173
206
|
...((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) && { user_email: e.user.email }
|
|
174
207
|
};
|
|
175
208
|
try {
|
|
176
|
-
await this.client.event(i.action,
|
|
177
|
-
} catch (
|
|
178
|
-
console.error("[Pirsch-Server] Failed to track event:",
|
|
209
|
+
await this.client.event(i.action, r, 0, a), this.log("Tracked event", { event: i, context: e });
|
|
210
|
+
} catch (p) {
|
|
211
|
+
console.error("[Pirsch-Server] Failed to track event:", p);
|
|
179
212
|
}
|
|
180
213
|
}
|
|
181
214
|
pageView(i, e) {
|
|
182
|
-
var
|
|
215
|
+
var t, a, o;
|
|
183
216
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
184
|
-
const
|
|
185
|
-
url: ((
|
|
217
|
+
const r = {
|
|
218
|
+
url: ((t = e == null ? void 0 : e.page) == null ? void 0 : t.path) || "https://pageview",
|
|
186
219
|
ip: "0.0.0.0",
|
|
187
220
|
// Server-side should provide real IP if available
|
|
188
221
|
user_agent: "analytics-library",
|
|
189
222
|
// Server-side should provide real UA if available
|
|
190
|
-
...((
|
|
223
|
+
...((a = e == null ? void 0 : e.page) == null ? void 0 : a.title) && { title: e.page.title },
|
|
191
224
|
...((o = e == null ? void 0 : e.page) == null ? void 0 : o.referrer) && { referrer: e.page.referrer },
|
|
192
225
|
...i && {
|
|
193
226
|
tags: Object.fromEntries(
|
|
194
227
|
Object.entries(i).filter(
|
|
195
|
-
([,
|
|
228
|
+
([, s]) => typeof s == "string" || typeof s == "number" || typeof s == "boolean"
|
|
196
229
|
)
|
|
197
230
|
)
|
|
198
231
|
}
|
|
199
232
|
};
|
|
200
|
-
this.client.hit(
|
|
201
|
-
console.error("[Pirsch-Server] Failed to track page view:",
|
|
233
|
+
this.client.hit(r).catch((s) => {
|
|
234
|
+
console.error("[Pirsch-Server] Failed to track page view:", s);
|
|
202
235
|
}), this.log("Tracked page view", { properties: i, context: e });
|
|
203
236
|
}
|
|
204
237
|
async reset() {
|
|
@@ -217,65 +250,65 @@ class E extends p {
|
|
|
217
250
|
}
|
|
218
251
|
}
|
|
219
252
|
async function g(l, n, i) {
|
|
220
|
-
var e,
|
|
253
|
+
var e, r;
|
|
221
254
|
try {
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
255
|
+
const t = await l.json();
|
|
256
|
+
if (!t.events || !Array.isArray(t.events))
|
|
224
257
|
throw new Error("Invalid payload: missing events array");
|
|
225
|
-
const
|
|
226
|
-
for (const
|
|
258
|
+
const a = i != null && i.extractIp ? i.extractIp(l) : b(l), o = i != null && i.enrichContext ? i.enrichContext(l) : {};
|
|
259
|
+
for (const s of t.events)
|
|
227
260
|
try {
|
|
228
|
-
switch (
|
|
261
|
+
switch (s.type) {
|
|
229
262
|
case "track": {
|
|
230
263
|
const h = {
|
|
231
|
-
...
|
|
264
|
+
...s.context,
|
|
232
265
|
...o,
|
|
233
266
|
device: {
|
|
234
|
-
...(e =
|
|
267
|
+
...(e = s.context) == null ? void 0 : e.device,
|
|
235
268
|
// Add IP (using type assertion for extended fields)
|
|
236
269
|
// biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
|
|
237
|
-
...
|
|
270
|
+
...a ? { ip: a } : {}
|
|
238
271
|
}
|
|
239
272
|
};
|
|
240
|
-
await n.track(
|
|
241
|
-
userId:
|
|
242
|
-
sessionId:
|
|
273
|
+
await n.track(s.event.action, s.event.properties, {
|
|
274
|
+
userId: s.event.userId,
|
|
275
|
+
sessionId: s.event.sessionId,
|
|
243
276
|
// biome-ignore lint/suspicious/noExplicitAny: Generic context forwarding requires type assertion
|
|
244
277
|
context: h
|
|
245
278
|
});
|
|
246
279
|
break;
|
|
247
280
|
}
|
|
248
281
|
case "identify": {
|
|
249
|
-
n.identify(
|
|
282
|
+
n.identify(s.userId, s.traits);
|
|
250
283
|
break;
|
|
251
284
|
}
|
|
252
285
|
case "pageView": {
|
|
253
286
|
const h = {
|
|
254
|
-
...
|
|
287
|
+
...s.context,
|
|
255
288
|
...o,
|
|
256
289
|
device: {
|
|
257
|
-
...(
|
|
290
|
+
...(r = s.context) == null ? void 0 : r.device,
|
|
258
291
|
// biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
|
|
259
292
|
// Add IP (using type assertion for extended fields)
|
|
260
|
-
...
|
|
293
|
+
...a ? { ip: a } : {}
|
|
261
294
|
}
|
|
262
295
|
};
|
|
263
|
-
n.pageView(
|
|
296
|
+
n.pageView(s.properties, h);
|
|
264
297
|
break;
|
|
265
298
|
}
|
|
266
299
|
case "reset":
|
|
267
300
|
break;
|
|
268
301
|
default:
|
|
269
|
-
console.warn("[Proxy] Unknown event type:",
|
|
302
|
+
console.warn("[Proxy] Unknown event type:", s);
|
|
270
303
|
}
|
|
271
304
|
} catch (h) {
|
|
272
305
|
i != null && i.onError ? i.onError(h) : console.error("[Proxy] Failed to process event:", h);
|
|
273
306
|
}
|
|
274
|
-
} catch (
|
|
275
|
-
throw i != null && i.onError ? i.onError(
|
|
307
|
+
} catch (t) {
|
|
308
|
+
throw i != null && i.onError ? i.onError(t) : console.error("[Proxy] Failed to ingest events:", t), t;
|
|
276
309
|
}
|
|
277
310
|
}
|
|
278
|
-
function
|
|
311
|
+
function b(l) {
|
|
279
312
|
var i;
|
|
280
313
|
const n = [
|
|
281
314
|
"x-forwarded-for",
|
|
@@ -286,12 +319,12 @@ function m(l) {
|
|
|
286
319
|
"x-cluster-client-ip"
|
|
287
320
|
];
|
|
288
321
|
for (const e of n) {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
return (i =
|
|
322
|
+
const r = l.headers.get(e);
|
|
323
|
+
if (r)
|
|
324
|
+
return (i = r.split(",")[0]) == null ? void 0 : i.trim();
|
|
292
325
|
}
|
|
293
326
|
}
|
|
294
|
-
function
|
|
327
|
+
function S(l, n) {
|
|
295
328
|
return async (i) => {
|
|
296
329
|
try {
|
|
297
330
|
return await g(i, l, n), new Response("OK", { status: 200 });
|
|
@@ -301,10 +334,10 @@ function k(l, n) {
|
|
|
301
334
|
};
|
|
302
335
|
}
|
|
303
336
|
export {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
337
|
+
c as BaseAnalyticsProvider,
|
|
338
|
+
w as BentoServerProvider,
|
|
339
|
+
k as PirschServerProvider,
|
|
340
|
+
P as PostHogServerProvider,
|
|
341
|
+
S as createProxyHandler,
|
|
309
342
|
g as ingestProxyEvents
|
|
310
343
|
};
|