@stacksee/analytics 0.9.7 → 0.10.0

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.
@@ -58,7 +58,7 @@ class w extends u {
58
58
  const s = (i == null ? void 0 : i.email) || e;
59
59
  if (this.bento.identify(s), i) {
60
60
  const t = { ...i };
61
- delete t.email, Object.keys(t).length > 0 && this.bento.updateFields(t);
61
+ t.email = void 0, Object.keys(t).length > 0 && this.bento.updateFields(t);
62
62
  }
63
63
  this.log("Identified user", { userId: e, email: s, traits: i });
64
64
  }
@@ -139,7 +139,9 @@ class w extends u {
139
139
  this.bento.track("$pageleave", s), this.log("Tracked page leave", { properties: e, context: i });
140
140
  }
141
141
  reset() {
142
- !this.isEnabled() || !this.initialized || !this.bento || !a() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
142
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || this.log(
143
+ "Reset user session - Note: Bento doesn't have a native reset method"
144
+ );
143
145
  }
144
146
  // ============================================================================
145
147
  // Bento-Specific Utility Methods
@@ -389,7 +391,7 @@ class v extends u {
389
391
  r(this, "retryAttempts");
390
392
  r(this, "retryBackoff");
391
393
  r(this, "retryInitialDelay");
392
- this.config = e, this.batchSize = ((i = e.batch) == null ? void 0 : i.size) ?? 10, this.batchInterval = ((s = e.batch) == null ? void 0 : s.interval) ?? 5e3, this.retryAttempts = ((t = e.retry) == null ? void 0 : t.attempts) ?? 3, this.retryBackoff = ((n = e.retry) == null ? void 0 : n.backoff) ?? "exponential", this.retryInitialDelay = ((l = e.retry) == null ? void 0 : l.initialDelay) ?? 1e3, typeof window < "u" && (window.addEventListener("beforeunload", () => {
394
+ this.config = e, this.batchSize = ((i = e.batch) == null ? void 0 : i.size) ?? 10, this.batchInterval = ((s = e.batch) == null ? void 0 : s.interval) ?? 2e3, this.retryAttempts = ((t = e.retry) == null ? void 0 : t.attempts) ?? 3, this.retryBackoff = ((n = e.retry) == null ? void 0 : n.backoff) ?? "exponential", this.retryInitialDelay = ((l = e.retry) == null ? void 0 : l.initialDelay) ?? 1e3, typeof window < "u" && (window.addEventListener("beforeunload", () => {
393
395
  this.flush(!0);
394
396
  }), document.addEventListener("visibilitychange", () => {
395
397
  document.visibilityState === "hidden" && this.flush(!0);
@@ -442,11 +444,11 @@ class v extends u {
442
444
  });
443
445
  return;
444
446
  }
445
- this.flushTimer || (this.flushTimer = setTimeout(() => {
447
+ this.flushTimer && clearTimeout(this.flushTimer), this.flushTimer = setTimeout(() => {
446
448
  this.flush().catch((i) => {
447
449
  console.error("[Proxy] Failed to flush events:", i);
448
450
  });
449
- }, this.batchInterval));
451
+ }, this.batchInterval);
450
452
  }
451
453
  async sendEvents(e, i = !1) {
452
454
  const s = { events: e };
@@ -2,7 +2,7 @@ export { BaseAnalyticsProvider } from './base.provider.js';
2
2
  export { PostHogServerProvider } from './posthog/server.js';
3
3
  export type { PostHogOptions } from 'posthog-node';
4
4
  export { BentoServerProvider } from './bento/server.js';
5
- export type { BentoServerConfig, BentoAnalyticsOptions } from './bento/server.js';
5
+ export type { BentoServerConfig, BentoAnalyticsOptions, } from './bento/server.js';
6
6
  export { PirschServerProvider } from './pirsch/server.js';
7
7
  export type { PirschServerConfig } from './pirsch/server.js';
8
8
  export { ingestProxyEvents, createProxyHandler } from './proxy/server.js';
@@ -1,16 +1,16 @@
1
- var j = Object.defineProperty;
2
- var D = (d, h, i) => h in d ? j(d, h, { enumerable: !0, configurable: !0, writable: !0, value: i }) : d[h] = i;
3
- var g = (d, h, i) => D(d, typeof h != "symbol" ? h + "" : h, i);
4
- import { B as q } from "../base.provider-AfFL5W_P.js";
1
+ var q = Object.defineProperty;
2
+ var D = (p, u, i) => u in p ? q(p, u, { enumerable: !0, configurable: !0, writable: !0, value: i }) : p[u] = i;
3
+ var t = (p, u, i) => D(p, typeof u != "symbol" ? u + "" : u, i);
4
+ import { B as V } from "../base.provider-AfFL5W_P.js";
5
5
  import { P as Q } from "../server-DjEk1fUD.js";
6
- class N extends q {
6
+ class N extends V {
7
7
  constructor(i) {
8
8
  super({ debug: i.debug, enabled: i.enabled });
9
- g(this, "name", "Bento-Server");
10
- g(this, "client");
11
- g(this, "initialized", !1);
12
- g(this, "config");
13
- g(this, "currentUserEmail");
9
+ t(this, "name", "Bento-Server");
10
+ t(this, "client");
11
+ t(this, "initialized", !1);
12
+ t(this, "config");
13
+ t(this, "currentUserEmail");
14
14
  this.config = i;
15
15
  }
16
16
  async initialize() {
@@ -23,8 +23,8 @@ class N extends q {
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: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: a, enabled: s, ...u } = this.config;
27
- this.client = new r(u), this.initialized = !0, this.log("Initialized successfully", {
26
+ const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: h, enabled: s, ...d } = this.config;
27
+ this.client = new r(d), this.initialized = !0, this.log("Initialized successfully", {
28
28
  siteUuid: this.config.siteUuid
29
29
  });
30
30
  } catch (r) {
@@ -39,29 +39,32 @@ class N extends q {
39
39
  if (!this.isEnabled() || !this.initialized || !this.client) return;
40
40
  const r = (e == null ? void 0 : e.email) || i;
41
41
  if (!r || !r.includes("@")) {
42
- this.log("Skipping identify - invalid or missing email", { userId: i, traits: e });
42
+ this.log("Skipping identify - invalid or missing email", {
43
+ userId: i,
44
+ traits: e
45
+ });
43
46
  return;
44
47
  }
45
48
  this.currentUserEmail = r;
46
- const a = e ? { ...e } : {};
47
- delete a.email, this.client.V1.addSubscriber({
49
+ const h = e ? { ...e } : {};
50
+ h.email = void 0, this.client.V1.addSubscriber({
48
51
  email: r,
49
- fields: a
52
+ fields: h
50
53
  }).catch((s) => {
51
54
  console.error("[Bento-Server] Failed to identify user:", s);
52
55
  }), this.log("Identified user", { userId: i, email: r, traits: e });
53
56
  }
54
57
  async track(i, e) {
55
- var u, l, p, n;
58
+ var d, g, n, l;
56
59
  if (!this.isEnabled() || !this.initialized || !this.client) return;
57
- const r = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) || this.currentUserEmail || ((l = e == null ? void 0 : e.user) == null ? void 0 : l.userId) || i.userId;
60
+ const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail || ((g = e == null ? void 0 : e.user) == null ? void 0 : g.userId) || i.userId;
58
61
  if (!r || !r.includes("@")) {
59
62
  console.warn(
60
63
  "[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
64
  );
62
65
  return;
63
66
  }
64
- const a = {
67
+ const h = {
65
68
  ...i.properties,
66
69
  category: i.category,
67
70
  timestamp: i.timestamp || Date.now(),
@@ -80,30 +83,30 @@ class N extends q {
80
83
  ...(e == null ? void 0 : e.device) && { device: e.device },
81
84
  ...(e == null ? void 0 : e.utm) && { utm: e.utm },
82
85
  site: this.config.siteUuid,
83
- ...((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) && { visitor: e.user.userId }
84
- }, s = ((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) || {};
86
+ ...((n = e == null ? void 0 : e.user) == null ? void 0 : n.userId) && { visitor: e.user.userId }
87
+ }, s = ((l = e == null ? void 0 : e.user) == null ? void 0 : l.traits) || {};
85
88
  try {
86
89
  await this.client.V1.track({
87
90
  email: r,
88
91
  type: `$${i.action}`,
89
- details: a,
92
+ details: h,
90
93
  fields: s
91
94
  }), this.log("Tracked event", { event: i, context: e });
92
- } catch (t) {
93
- console.error("[Bento-Server] Failed to track event:", t);
95
+ } catch (a) {
96
+ console.error("[Bento-Server] Failed to track event:", a);
94
97
  }
95
98
  }
96
99
  pageView(i, e) {
97
- var u, l, p;
100
+ var d, g, n;
98
101
  if (!this.isEnabled() || !this.initialized || !this.client) return;
99
- const r = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) || this.currentUserEmail;
102
+ const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail;
100
103
  if (!r || !r.includes("@")) {
101
104
  console.warn(
102
105
  "[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
106
  );
104
107
  return;
105
108
  }
106
- const a = {
109
+ const h = {
107
110
  ...i,
108
111
  date: (/* @__PURE__ */ new Date()).toISOString(),
109
112
  ...(e == null ? void 0 : e.page) && {
@@ -118,15 +121,15 @@ class N extends q {
118
121
  }
119
122
  },
120
123
  site: this.config.siteUuid,
121
- ...((l = e == null ? void 0 : e.user) == null ? void 0 : l.userId) && { visitor: e.user.userId }
122
- }, s = ((p = e == null ? void 0 : e.user) == null ? void 0 : p.traits) || {};
124
+ ...((g = e == null ? void 0 : e.user) == null ? void 0 : g.userId) && { visitor: e.user.userId }
125
+ }, s = ((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) || {};
123
126
  this.client.V1.track({
124
127
  email: r,
125
128
  type: "$view",
126
- details: a,
129
+ details: h,
127
130
  fields: s
128
- }).catch((n) => {
129
- console.error("[Bento-Server] Failed to track page view:", n);
131
+ }).catch((l) => {
132
+ console.error("[Bento-Server] Failed to track page view:", l);
130
133
  }), this.log("Tracked page view", { properties: i, context: e });
131
134
  }
132
135
  async reset() {
@@ -136,13 +139,13 @@ class N extends q {
136
139
  this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
137
140
  }
138
141
  }
139
- class W extends q {
142
+ class W extends V {
140
143
  constructor(i) {
141
144
  super({ debug: i.debug, enabled: i.enabled });
142
- g(this, "name", "Pirsch-Server");
143
- g(this, "client");
144
- g(this, "initialized", !1);
145
- g(this, "config");
145
+ t(this, "name", "Pirsch-Server");
146
+ t(this, "client");
147
+ t(this, "initialized", !1);
148
+ t(this, "config");
146
149
  this.config = i;
147
150
  }
148
151
  async initialize() {
@@ -157,7 +160,7 @@ class W extends q {
157
160
  "Pirsch requires a clientId when using OAuth authentication (clientSecret doesn't start with 'pa_'). Either provide a clientId or use an access key (starts with 'pa_') as clientSecret."
158
161
  );
159
162
  try {
160
- const { Pirsch: e } = await import("../index-zS7gy63J.js").then((u) => u.i), { debug: r, enabled: a, ...s } = this.config;
163
+ const { Pirsch: e } = await import("../index-zS7gy63J.js").then((d) => d.i), { debug: r, enabled: h, ...s } = this.config;
161
164
  this.client = new e(s), this.initialized = !0, this.log("Initialized successfully", {
162
165
  hostname: this.config.hostname,
163
166
  authMode: i ? "access-key" : "oauth"
@@ -175,7 +178,7 @@ class W extends q {
175
178
  url: "https://identify",
176
179
  ip: "0.0.0.0",
177
180
  user_agent: "analytics-library"
178
- }, a = {
181
+ }, h = {
179
182
  userId: i,
180
183
  ...e && Object.fromEntries(
181
184
  Object.entries(e).filter(
@@ -183,35 +186,48 @@ class W extends q {
183
186
  )
184
187
  )
185
188
  };
186
- this.client.event("user_identified", r, 0, a).catch((s) => {
189
+ this.client.event("user_identified", r, 0, h).catch((s) => {
187
190
  console.error("[Pirsch-Server] Failed to track identify event:", s);
188
191
  }), this.log("Identified user via event", { userId: i, traits: e });
189
192
  }
190
193
  async track(i, e) {
191
- var t, f, v, y, w, c, m, b, S, k, I, _, E, P, z, B, A, F, o, $, K, O, V;
194
+ var a, o, f, y, c, w, m, b, S, k, I, _, E, P, z, B, A, F, v, $, K, j, O;
192
195
  if (!this.isEnabled() || !this.initialized || !this.client) return;
193
- const r = e, a = ((t = r == null ? void 0 : r.device) == null ? void 0 : t.ip) || ((f = r == null ? void 0 : r.server) == null ? void 0 : f.ip), s = ((v = r == null ? void 0 : r.server) == null ? void 0 : v.userAgent) || ((y = r == null ? void 0 : r.device) == null ? void 0 : y.userAgent);
194
- if (!a || !s) {
195
- this.log("Skipping event - missing required IP or user-agent from context", {
196
- hasIp: !!a,
197
- hasUserAgent: !!s,
198
- event: i.action
199
- });
196
+ const r = e, h = ((a = r == null ? void 0 : r.device) == null ? void 0 : a.ip) || ((o = r == null ? void 0 : r.server) == null ? void 0 : o.ip), s = ((f = r == null ? void 0 : r.server) == null ? void 0 : f.userAgent) || ((y = r == null ? void 0 : r.device) == null ? void 0 : y.userAgent);
197
+ if (!h || !s) {
198
+ this.log(
199
+ "Skipping event - missing required IP or user-agent from context",
200
+ {
201
+ hasIp: !!h,
202
+ hasUserAgent: !!s,
203
+ event: i.action
204
+ }
205
+ );
200
206
  return;
201
207
  }
202
- const l = {
203
- url: ((w = e == null ? void 0 : e.page) == null ? void 0 : w.url) || ((c = e == null ? void 0 : e.page) != null && c.protocol && ((m = e == null ? void 0 : e.page) != null && m.host) && ((b = e == null ? void 0 : e.page) != null && b.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (S = e == null ? void 0 : e.page) != null && S.path ? `https://${this.config.hostname}${e.page.path}` : "https://event"),
204
- ip: a,
208
+ const g = {
209
+ url: ((c = e == null ? void 0 : e.page) == null ? void 0 : c.url) || ((w = e == null ? void 0 : e.page) != null && w.protocol && ((m = e == null ? void 0 : e.page) != null && m.host) && ((b = e == null ? void 0 : e.page) != null && b.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (S = e == null ? void 0 : e.page) != null && S.path ? `https://${this.config.hostname}${e.page.path}` : "https://event"),
210
+ ip: h,
205
211
  user_agent: s,
206
212
  ...((k = e == null ? void 0 : e.page) == null ? void 0 : k.title) && { title: e.page.title },
207
213
  ...((I = e == null ? void 0 : e.page) == null ? void 0 : I.referrer) && { referrer: e.page.referrer },
208
- ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.width) && { screen_width: e.device.screen.width },
209
- ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.screen) == null ? void 0 : z.height) && { screen_height: e.device.screen.height },
210
- ...((A = (B = e == null ? void 0 : e.device) == null ? void 0 : B.viewport) == null ? void 0 : A.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
211
- ...((F = e == null ? void 0 : e.device) == null ? void 0 : F.language) && { accept_language: e.device.language },
212
- ...((o = e == null ? void 0 : e.device) == null ? void 0 : o.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
214
+ ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.width) && {
215
+ screen_width: e.device.screen.width
216
+ },
217
+ ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.screen) == null ? void 0 : z.height) && {
218
+ screen_height: e.device.screen.height
219
+ },
220
+ ...((A = (B = e == null ? void 0 : e.device) == null ? void 0 : B.viewport) == null ? void 0 : A.width) && {
221
+ sec_ch_viewport_width: String(e.device.viewport.width)
222
+ },
223
+ ...((F = e == null ? void 0 : e.device) == null ? void 0 : F.language) && {
224
+ accept_language: e.device.language
225
+ },
226
+ ...((v = e == null ? void 0 : e.device) == null ? void 0 : v.type) && {
227
+ sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0"
228
+ },
213
229
  ...(($ = e == null ? void 0 : e.device) == null ? void 0 : $.os) && { sec_ch_ua_platform: e.device.os }
214
- }, n = {
230
+ }, l = {
215
231
  ...Object.fromEntries(
216
232
  Object.entries(i.properties).filter(
217
233
  ([, U]) => typeof U == "string" || typeof U == "number" || typeof U == "boolean"
@@ -222,48 +238,61 @@ class W extends q {
222
238
  ...i.userId && { userId: i.userId },
223
239
  ...i.sessionId && { sessionId: i.sessionId },
224
240
  ...((K = e == null ? void 0 : e.user) == null ? void 0 : K.email) && { user_email: e.user.email },
225
- ...((O = e == null ? void 0 : e.device) == null ? void 0 : O.timezone) && { timezone: e.device.timezone },
226
- ...((V = e == null ? void 0 : e.device) == null ? void 0 : V.browser) && { browser: e.device.browser }
241
+ ...((j = e == null ? void 0 : e.device) == null ? void 0 : j.timezone) && { timezone: e.device.timezone },
242
+ ...((O = e == null ? void 0 : e.device) == null ? void 0 : O.browser) && { browser: e.device.browser }
227
243
  };
228
244
  try {
229
- await this.client.event(i.action, l, 0, n), this.log("Tracked event", { event: i, context: e });
245
+ await this.client.event(i.action, g, 0, l), this.log("Tracked event", { event: i, context: e });
230
246
  } catch (U) {
231
247
  console.error("[Pirsch-Server] Failed to track event:", U);
232
248
  }
233
249
  }
234
250
  pageView(i, e) {
235
- var p, n, t, f, v, y, w, c, m, b, S, k, I, _, E, P, z, B, A, F;
251
+ var n, l, a, o, f, y, c, w, m, b, S, k, I, _, E, P, z, B, A, F;
236
252
  if (!this.isEnabled() || !this.initialized || !this.client) return;
237
- const r = e, a = ((p = r == null ? void 0 : r.device) == null ? void 0 : p.ip) || ((n = r == null ? void 0 : r.server) == null ? void 0 : n.ip), s = ((t = r == null ? void 0 : r.server) == null ? void 0 : t.userAgent) || ((f = r == null ? void 0 : r.device) == null ? void 0 : f.userAgent);
238
- if (!a || !s) {
239
- this.log("Skipping pageView - missing required IP or user-agent from context", {
240
- hasIp: !!a,
241
- hasUserAgent: !!s
242
- });
253
+ const r = e, h = ((n = r == null ? void 0 : r.device) == null ? void 0 : n.ip) || ((l = r == null ? void 0 : r.server) == null ? void 0 : l.ip), s = ((a = r == null ? void 0 : r.server) == null ? void 0 : a.userAgent) || ((o = r == null ? void 0 : r.device) == null ? void 0 : o.userAgent);
254
+ if (!h || !s) {
255
+ this.log(
256
+ "Skipping pageView - missing required IP or user-agent from context",
257
+ {
258
+ hasIp: !!h,
259
+ hasUserAgent: !!s
260
+ }
261
+ );
243
262
  return;
244
263
  }
245
- const l = {
246
- url: ((v = e == null ? void 0 : e.page) == null ? void 0 : v.url) || ((y = e == null ? void 0 : e.page) != null && y.protocol && ((w = e == null ? void 0 : e.page) != null && w.host) && ((c = e == null ? void 0 : e.page) != null && c.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (m = e == null ? void 0 : e.page) != null && m.path ? `https://${this.config.hostname}${e.page.path}` : "https://pageview"),
247
- ip: a,
264
+ const g = {
265
+ url: ((f = e == null ? void 0 : e.page) == null ? void 0 : f.url) || ((y = e == null ? void 0 : e.page) != null && y.protocol && ((c = e == null ? void 0 : e.page) != null && c.host) && ((w = e == null ? void 0 : e.page) != null && w.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (m = e == null ? void 0 : e.page) != null && m.path ? `https://${this.config.hostname}${e.page.path}` : "https://pageview"),
266
+ ip: h,
248
267
  user_agent: s,
249
268
  ...((b = e == null ? void 0 : e.page) == null ? void 0 : b.title) && { title: e.page.title },
250
269
  ...((S = e == null ? void 0 : e.page) == null ? void 0 : S.referrer) && { referrer: e.page.referrer },
251
- ...((I = (k = e == null ? void 0 : e.device) == null ? void 0 : k.screen) == null ? void 0 : I.width) && { screen_width: e.device.screen.width },
252
- ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.height) && { screen_height: e.device.screen.height },
253
- ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.viewport) == null ? void 0 : z.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
254
- ...((B = e == null ? void 0 : e.device) == null ? void 0 : B.language) && { accept_language: e.device.language },
255
- ...((A = e == null ? void 0 : e.device) == null ? void 0 : A.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
270
+ ...((I = (k = e == null ? void 0 : e.device) == null ? void 0 : k.screen) == null ? void 0 : I.width) && {
271
+ screen_width: e.device.screen.width
272
+ },
273
+ ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.height) && {
274
+ screen_height: e.device.screen.height
275
+ },
276
+ ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.viewport) == null ? void 0 : z.width) && {
277
+ sec_ch_viewport_width: String(e.device.viewport.width)
278
+ },
279
+ ...((B = e == null ? void 0 : e.device) == null ? void 0 : B.language) && {
280
+ accept_language: e.device.language
281
+ },
282
+ ...((A = e == null ? void 0 : e.device) == null ? void 0 : A.type) && {
283
+ sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0"
284
+ },
256
285
  ...((F = e == null ? void 0 : e.device) == null ? void 0 : F.os) && { sec_ch_ua_platform: e.device.os },
257
286
  ...i && {
258
287
  tags: Object.fromEntries(
259
288
  Object.entries(i).filter(
260
- ([, o]) => typeof o == "string" || typeof o == "number" || typeof o == "boolean"
289
+ ([, v]) => typeof v == "string" || typeof v == "number" || typeof v == "boolean"
261
290
  )
262
291
  )
263
292
  }
264
293
  };
265
- this.client.hit(l).catch((o) => {
266
- console.error("[Pirsch-Server] Failed to track page view:", o);
294
+ this.client.hit(g).catch((v) => {
295
+ console.error("[Pirsch-Server] Failed to track page view:", v);
267
296
  }), this.log("Tracked page view", { properties: i, context: e });
268
297
  }
269
298
  async reset() {
@@ -281,68 +310,80 @@ class W extends q {
281
310
  this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
282
311
  }
283
312
  }
284
- async function R(d, h, i) {
285
- var e, r;
313
+ async function R(p, u, i) {
314
+ var e, r, h, s;
286
315
  try {
287
- const a = await d.json();
288
- if (!a.events || !Array.isArray(a.events))
316
+ const d = await p.json();
317
+ if (!d.events || !Array.isArray(d.events))
289
318
  throw new Error("Invalid payload: missing events array");
290
- const s = i != null && i.extractIp ? i.extractIp(d) : T(d), u = i != null && i.enrichContext ? i.enrichContext(d) : {};
291
- for (const l of a.events)
319
+ const g = i != null && i.extractIp ? i.extractIp(p) : T(p), n = p.headers.get("user-agent"), l = i != null && i.enrichContext ? i.enrichContext(p) : {};
320
+ for (const a of d.events)
292
321
  try {
293
- switch (l.type) {
322
+ switch (a.type) {
294
323
  case "track": {
295
- const p = {
296
- ...l.context,
297
- ...u,
324
+ const o = {
325
+ ...a.context,
326
+ ...l,
327
+ server: {
328
+ ...(e = a.context) == null ? void 0 : e.server,
329
+ ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
330
+ ...n ? { userAgent: n } : {}
331
+ },
298
332
  device: {
299
- ...(e = l.context) == null ? void 0 : e.device,
300
- // Add IP (using type assertion for extended fields)
301
- // biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
302
- ...s ? { ip: s } : {}
333
+ ...(r = a.context) == null ? void 0 : r.device,
334
+ ...g ? { ip: g } : {}
303
335
  }
304
336
  };
305
- await h.track(l.event.action, l.event.properties, {
306
- userId: l.event.userId,
307
- sessionId: l.event.sessionId,
308
- // biome-ignore lint/suspicious/noExplicitAny: Generic context forwarding requires type assertion
309
- context: p
310
- });
337
+ await u.track(
338
+ a.event.action,
339
+ // biome-ignore lint/suspicious/noExplicitAny: Properties from JSON cannot be type-checked against TEventMap at compile time
340
+ a.event.properties,
341
+ {
342
+ userId: a.event.userId,
343
+ sessionId: a.event.sessionId,
344
+ context: o
345
+ }
346
+ );
311
347
  break;
312
348
  }
313
349
  case "identify": {
314
- h.identify(l.userId, l.traits);
350
+ u.identify(a.userId, a.traits);
315
351
  break;
316
352
  }
317
353
  case "pageView": {
318
- const p = {
319
- ...l.context,
320
- ...u,
354
+ const o = {
355
+ ...a.context,
356
+ ...l,
357
+ server: {
358
+ ...(h = a.context) == null ? void 0 : h.server,
359
+ ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
360
+ ...n ? { userAgent: n } : {}
361
+ },
321
362
  device: {
322
- ...(r = l.context) == null ? void 0 : r.device,
323
- // biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
324
- // Add IP (using type assertion for extended fields)
325
- ...s ? { ip: s } : {}
363
+ ...(s = a.context) == null ? void 0 : s.device,
364
+ ...g ? { ip: g } : {}
326
365
  }
327
366
  };
328
- h.pageView(l.properties, p);
367
+ u.pageView(a.properties, {
368
+ context: o
369
+ });
329
370
  break;
330
371
  }
331
372
  case "reset":
332
373
  break;
333
374
  default:
334
- console.warn("[Proxy] Unknown event type:", l);
375
+ console.warn("[Proxy] Unknown event type:", a);
335
376
  }
336
- } catch (p) {
337
- i != null && i.onError ? i.onError(p) : console.error("[Proxy] Failed to process event:", p);
377
+ } catch (o) {
378
+ i != null && i.onError ? i.onError(o) : console.error("[Proxy] Failed to process event:", o);
338
379
  }
339
- } catch (a) {
340
- throw i != null && i.onError ? i.onError(a) : console.error("[Proxy] Failed to ingest events:", a), a;
380
+ } catch (d) {
381
+ throw i != null && i.onError ? i.onError(d) : console.error("[Proxy] Failed to ingest events:", d), d;
341
382
  }
342
383
  }
343
- function T(d) {
384
+ function T(p) {
344
385
  var i;
345
- const h = [
386
+ const u = [
346
387
  "x-forwarded-for",
347
388
  "x-real-ip",
348
389
  "cf-connecting-ip",
@@ -350,23 +391,23 @@ function T(d) {
350
391
  "x-client-ip",
351
392
  "x-cluster-client-ip"
352
393
  ];
353
- for (const e of h) {
354
- const r = d.headers.get(e);
394
+ for (const e of u) {
395
+ const r = p.headers.get(e);
355
396
  if (r)
356
397
  return (i = r.split(",")[0]) == null ? void 0 : i.trim();
357
398
  }
358
399
  }
359
- function G(d, h) {
400
+ function G(p, u) {
360
401
  return async (i) => {
361
402
  try {
362
- return await R(i, d, h), new Response("OK", { status: 200 });
403
+ return await R(i, p, u), new Response("OK", { status: 200 });
363
404
  } catch (e) {
364
405
  return console.error("[Proxy] Handler error:", e), new Response("Internal Server Error", { status: 500 });
365
406
  }
366
407
  };
367
408
  }
368
409
  export {
369
- q as BaseAnalyticsProvider,
410
+ V as BaseAnalyticsProvider,
370
411
  N as BentoServerProvider,
371
412
  W as PirschServerProvider,
372
413
  Q as PostHogServerProvider,