@stacksee/analytics 0.7.0 → 0.9.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.
@@ -1,22 +1,22 @@
1
- var g = Object.defineProperty;
2
- var p = (d, t, e) => t in d ? g(d, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[t] = e;
3
- var a = (d, t, e) => p(d, typeof t != "symbol" ? t + "" : t, e);
4
- import { B as h } from "../base.provider-AfFL5W_P.js";
5
- import { i as l } from "../client-DTHZYkxx.js";
6
- import { P as y } from "../client-DTHZYkxx.js";
7
- class m extends h {
8
- constructor(e) {
9
- super({ debug: e.debug, enabled: e.enabled });
10
- a(this, "name", "Bento-Client");
11
- a(this, "bento");
12
- a(this, "initialized", !1);
13
- a(this, "config");
14
- a(this, "scriptLoaded", !1);
15
- this.config = e;
1
+ var u = Object.defineProperty;
2
+ var f = (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) => f(l, typeof h != "symbol" ? h + "" : h, i);
4
+ import { B as d } from "../base.provider-AfFL5W_P.js";
5
+ import { i as a } from "../client-DTHZYkxx.js";
6
+ import { P as E } from "../client-DTHZYkxx.js";
7
+ class b extends d {
8
+ constructor(i) {
9
+ super({ debug: i.debug, enabled: i.enabled });
10
+ r(this, "name", "Bento-Client");
11
+ r(this, "bento");
12
+ r(this, "initialized", !1);
13
+ r(this, "config");
14
+ r(this, "scriptLoaded", !1);
15
+ this.config = i;
16
16
  }
17
17
  async initialize() {
18
18
  if (this.isEnabled() && !this.initialized) {
19
- if (!l()) {
19
+ if (!a()) {
20
20
  this.log("Skipping initialization - not in browser environment");
21
21
  return;
22
22
  }
@@ -24,210 +24,484 @@ class m extends h {
24
24
  throw new Error("Bento requires a siteUuid");
25
25
  try {
26
26
  this.scriptLoaded || await this.loadBentoScript(), await this.waitForBento(), this.bento = window.bento, this.initialized = !0, this.log("Initialized successfully", this.config);
27
- } catch (e) {
28
- throw console.error("[Bento-Client] Failed to initialize:", e), e;
27
+ } catch (i) {
28
+ throw console.error("[Bento-Client] Failed to initialize:", i), i;
29
29
  }
30
30
  }
31
31
  }
32
32
  async loadBentoScript() {
33
- return new Promise((e, i) => {
33
+ return new Promise((i, e) => {
34
34
  if (document.querySelector(
35
35
  'script[src*="bentonow.com"]'
36
36
  )) {
37
- this.scriptLoaded = !0, e();
37
+ this.scriptLoaded = !0, i();
38
38
  return;
39
39
  }
40
- const r = document.createElement("script");
41
- r.src = `https://cdn.bentonow.com/v1/${this.config.siteUuid}/bento.js`, r.async = !0, r.onload = () => {
42
- this.scriptLoaded = !0, e();
43
- }, r.onerror = () => {
44
- i(new Error("Failed to load Bento script"));
45
- }, document.head.appendChild(r);
40
+ const s = document.createElement("script");
41
+ s.src = `https://cdn.bentonow.com/v1/${this.config.siteUuid}/bento.js`, s.async = !0, s.onload = () => {
42
+ this.scriptLoaded = !0, i();
43
+ }, s.onerror = () => {
44
+ e(new Error("Failed to load Bento script"));
45
+ }, document.head.appendChild(s);
46
46
  });
47
47
  }
48
- async waitForBento(e = 50, i = 100) {
49
- for (let s = 0; s < e; s++) {
48
+ async waitForBento(i = 50, e = 100) {
49
+ for (let t = 0; t < i; t++) {
50
50
  if (window.bento)
51
51
  return;
52
- await new Promise((r) => setTimeout(r, i));
52
+ await new Promise((s) => setTimeout(s, e));
53
53
  }
54
54
  throw new Error("Bento SDK not available after loading script");
55
55
  }
56
- identify(e, i) {
56
+ identify(i, e) {
57
57
  if (!this.isEnabled() || !this.initialized || !this.bento) return;
58
- const s = (i == null ? void 0 : i.email) || e;
59
- if (this.bento.identify(s), i) {
60
- const r = { ...i };
61
- delete r.email, Object.keys(r).length > 0 && this.bento.updateFields(r);
58
+ const t = (e == null ? void 0 : e.email) || i;
59
+ if (this.bento.identify(t), e) {
60
+ const s = { ...e };
61
+ delete s.email, Object.keys(s).length > 0 && this.bento.updateFields(s);
62
62
  }
63
- this.log("Identified user", { userId: e, email: s, traits: i });
63
+ this.log("Identified user", { userId: i, email: t, traits: e });
64
64
  }
65
- track(e, i) {
66
- var r, n;
65
+ track(i, e) {
66
+ var s, n;
67
67
  if (!this.isEnabled() || !this.initialized || !this.bento) return;
68
- const s = {
69
- ...e.properties,
70
- category: e.category,
71
- timestamp: e.timestamp || Date.now(),
72
- ...e.userId && { userId: e.userId },
73
- ...e.sessionId && { sessionId: e.sessionId },
74
- ...(i == null ? void 0 : i.page) && {
68
+ const t = {
69
+ ...i.properties,
70
+ category: i.category,
71
+ timestamp: i.timestamp || Date.now(),
72
+ ...i.userId && { userId: i.userId },
73
+ ...i.sessionId && { sessionId: i.sessionId },
74
+ ...(e == null ? void 0 : e.page) && {
75
75
  page: {
76
- path: i.page.path,
77
- title: i.page.title,
78
- referrer: i.page.referrer
76
+ path: e.page.path,
77
+ title: e.page.title,
78
+ referrer: e.page.referrer
79
79
  }
80
80
  },
81
- ...(i == null ? void 0 : i.device) && { device: i.device },
82
- ...(i == null ? void 0 : i.utm) && { utm: i.utm },
81
+ ...(e == null ? void 0 : e.device) && { device: e.device },
82
+ ...(e == null ? void 0 : e.utm) && { utm: e.utm },
83
83
  // Include user email and traits as regular event properties
84
- ...((r = i == null ? void 0 : i.user) == null ? void 0 : r.email) && { user_email: i.user.email },
85
- ...((n = i == null ? void 0 : i.user) == null ? void 0 : n.traits) && { user_traits: i.user.traits }
84
+ ...((s = e == null ? void 0 : e.user) == null ? void 0 : s.email) && { user_email: e.user.email },
85
+ ...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits }
86
86
  };
87
- this.bento.track(e.action, s), this.log("Tracked event", { event: e, context: i });
88
- }
89
- pageView(e, i) {
90
- if (!(!this.isEnabled() || !this.initialized || !this.bento || !l())) {
91
- if (this.bento.view(), e || i != null && i.page) {
92
- const s = {
93
- ...e,
94
- ...(i == null ? void 0 : i.page) && {
95
- path: i.page.path,
96
- title: i.page.title,
97
- referrer: i.page.referrer
87
+ this.bento.track(i.action, t), this.log("Tracked event", { event: i, context: e });
88
+ }
89
+ pageView(i, e) {
90
+ if (!(!this.isEnabled() || !this.initialized || !this.bento || !a())) {
91
+ if (this.bento.view(), i || e != null && e.page) {
92
+ const t = {
93
+ ...i,
94
+ ...(e == null ? void 0 : e.page) && {
95
+ path: e.page.path,
96
+ title: e.page.title,
97
+ referrer: e.page.referrer
98
98
  }
99
99
  };
100
- this.bento.track("$pageview", s);
100
+ this.bento.track("$view", t);
101
101
  }
102
- this.log("Tracked page view", { properties: e, context: i });
102
+ this.log("Tracked page view", { properties: i, context: e });
103
103
  }
104
104
  }
105
- pageLeave(e, i) {
106
- if (!this.isEnabled() || !this.initialized || !this.bento || !l())
105
+ pageLeave(i, e) {
106
+ if (!this.isEnabled() || !this.initialized || !this.bento || !a())
107
107
  return;
108
- const s = {
109
- ...e,
110
- ...(i == null ? void 0 : i.page) && {
111
- path: i.page.path,
112
- title: i.page.title,
113
- referrer: i.page.referrer
108
+ const t = {
109
+ ...i,
110
+ ...(e == null ? void 0 : e.page) && {
111
+ path: e.page.path,
112
+ title: e.page.title,
113
+ referrer: e.page.referrer
114
114
  }
115
115
  };
116
- this.bento.track("$pageleave", s), this.log("Tracked page leave", { properties: e, context: i });
116
+ this.bento.track("$pageleave", t), this.log("Tracked page leave", { properties: i, context: e });
117
117
  }
118
118
  reset() {
119
- !this.isEnabled() || !this.initialized || !this.bento || !l() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
119
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
120
+ }
121
+ // ============================================================================
122
+ // Bento-Specific Utility Methods
123
+ // ============================================================================
124
+ /**
125
+ * Add a tag to the current user
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * bentoProvider.tag('premium_user');
130
+ * bentoProvider.tag('beta_tester');
131
+ * ```
132
+ */
133
+ tag(i) {
134
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.tag(i), this.log("Added tag to user", { tag: i }));
135
+ }
136
+ /**
137
+ * Get the current user's email address
138
+ *
139
+ * @returns The user's email or null if not identified
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const email = bentoProvider.getEmail();
144
+ * if (email) {
145
+ * console.log('Current user:', email);
146
+ * }
147
+ * ```
148
+ */
149
+ getEmail() {
150
+ return !this.isEnabled() || !this.initialized || !this.bento || !a() ? null : this.bento.getEmail();
151
+ }
152
+ /**
153
+ * Get the current user's name
154
+ *
155
+ * @returns The user's name or null if not set
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const name = bentoProvider.getName();
160
+ * if (name) {
161
+ * console.log('Welcome back,', name);
162
+ * }
163
+ * ```
164
+ */
165
+ getName() {
166
+ return !this.isEnabled() || !this.initialized || !this.bento || !a() ? null : this.bento.getName();
167
+ }
168
+ // ============================================================================
169
+ // Survey Methods
170
+ // ============================================================================
171
+ /**
172
+ * Show a Bento survey form
173
+ *
174
+ * @param element - The HTML element to render the survey in
175
+ * @param surveyId - The survey ID from your Bento account
176
+ * @param type - Display type: 'popup' or 'inline' (default: 'popup')
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const container = document.getElementById('survey-container');
181
+ * if (container) {
182
+ * bentoProvider.showSurveyForm(container, 'survey-123', 'popup');
183
+ * }
184
+ * ```
185
+ */
186
+ showSurveyForm(i, e, t = "popup") {
187
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.showSurveyForm(i, e, t), this.log("Showed survey form", { surveyId: e, type: t }));
188
+ }
189
+ /**
190
+ * Validate an email address using Bento's spam check
191
+ *
192
+ * @param email - The email address to validate
193
+ * @returns Promise that resolves to true if email is valid, false if spam
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const isValid = await bentoProvider.spamCheck('user@example.com');
198
+ * if (!isValid) {
199
+ * console.log('Invalid or spam email detected');
200
+ * }
201
+ * ```
202
+ */
203
+ async spamCheck(i) {
204
+ if (!this.isEnabled() || !this.initialized || !this.bento || !a())
205
+ return !1;
206
+ try {
207
+ const e = await this.bento.spamCheck(i);
208
+ return this.log("Spam check completed", { email: i, result: e }), e;
209
+ } catch (e) {
210
+ return console.error("[Bento-Client] Spam check failed:", e), !1;
211
+ }
212
+ }
213
+ // ============================================================================
214
+ // Chat Methods (if chat is enabled in Bento)
215
+ // ============================================================================
216
+ /**
217
+ * Show the Bento chat widget
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * bentoProvider.showChat();
222
+ * ```
223
+ */
224
+ showChat() {
225
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.showChat ? (this.bento.showChat(), this.log("Showed chat widget")) : console.warn(
226
+ "[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
227
+ ));
228
+ }
229
+ /**
230
+ * Hide the Bento chat widget
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * bentoProvider.hideChat();
235
+ * ```
236
+ */
237
+ hideChat() {
238
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.hideChat ? (this.bento.hideChat(), this.log("Hid chat widget")) : console.warn(
239
+ "[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
240
+ ));
241
+ }
242
+ /**
243
+ * Open the Bento chat widget
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * bentoProvider.openChat();
248
+ * ```
249
+ */
250
+ openChat() {
251
+ !this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.openChat ? (this.bento.openChat(), this.log("Opened chat widget")) : console.warn(
252
+ "[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
253
+ ));
120
254
  }
121
255
  }
122
- class b extends h {
123
- constructor(e) {
124
- super({ debug: e.debug, enabled: e.enabled });
125
- a(this, "name", "Pirsch-Client");
126
- a(this, "client");
127
- a(this, "initialized", !1);
128
- a(this, "config");
129
- this.config = e;
256
+ class w extends d {
257
+ constructor(i) {
258
+ super({ debug: i.debug, enabled: i.enabled });
259
+ r(this, "name", "Pirsch-Client");
260
+ r(this, "client");
261
+ r(this, "initialized", !1);
262
+ r(this, "config");
263
+ this.config = i;
130
264
  }
131
265
  async initialize() {
132
266
  if (this.isEnabled() && !this.initialized) {
133
- if (!l()) {
267
+ if (!a()) {
134
268
  this.log("Skipping initialization - not in browser environment");
135
269
  return;
136
270
  }
137
271
  if (!this.config.identificationCode || typeof this.config.identificationCode != "string")
138
272
  throw new Error("Pirsch requires an identificationCode");
139
273
  try {
140
- const { Pirsch: e } = await import("../web-CvEQewPd.js").then((i) => i.w);
141
- this.client = new e({
274
+ const { Pirsch: i } = await import("../web-CvEQewPd.js").then((e) => e.w);
275
+ this.client = new i({
142
276
  identificationCode: this.config.identificationCode,
143
277
  ...this.config.hostname && { hostname: this.config.hostname }
144
278
  }), this.initialized = !0, this.log("Initialized successfully", this.config);
145
- } catch (e) {
279
+ } catch (i) {
146
280
  throw console.error(
147
281
  "[Pirsch-Client] Failed to initialize. Make sure pirsch-sdk is installed:",
148
- e
149
- ), e;
282
+ i
283
+ ), i;
150
284
  }
151
285
  }
152
286
  }
153
- identify(e, i) {
287
+ identify(i, e) {
154
288
  !this.isEnabled() || !this.initialized || !this.client || (this.client.event("user_identified", 0, {
155
- userId: e,
156
- ...i
157
- }).catch((s) => {
158
- console.error("[Pirsch-Client] Failed to track identify event:", s);
159
- }), this.log("Identified user via event", { userId: e, traits: i }));
160
- }
161
- async track(e, i) {
162
- var r, n;
289
+ userId: i,
290
+ ...e
291
+ }).catch((t) => {
292
+ console.error("[Pirsch-Client] Failed to track identify event:", t);
293
+ }), this.log("Identified user via event", { userId: i, traits: e }));
294
+ }
295
+ async track(i, e) {
296
+ var s, n;
163
297
  if (!this.isEnabled() || !this.initialized || !this.client) return;
164
- const s = {
165
- ...e.properties,
166
- category: e.category,
167
- ...e.userId && { userId: e.userId },
168
- ...e.sessionId && { sessionId: e.sessionId },
169
- ...(i == null ? void 0 : i.page) && {
170
- page_path: i.page.path,
171
- page_title: i.page.title,
172
- page_referrer: i.page.referrer
298
+ const t = {
299
+ ...i.properties,
300
+ category: i.category,
301
+ ...i.userId && { userId: i.userId },
302
+ ...i.sessionId && { sessionId: i.sessionId },
303
+ ...(e == null ? void 0 : e.page) && {
304
+ page_path: e.page.path,
305
+ page_title: e.page.title,
306
+ page_referrer: e.page.referrer
173
307
  },
174
- ...(i == null ? void 0 : i.device) && { device: i.device },
175
- ...(i == null ? void 0 : i.utm) && { utm: i.utm },
176
- ...((r = i == null ? void 0 : i.user) == null ? void 0 : r.email) && { user_email: i.user.email },
177
- ...((n = i == null ? void 0 : i.user) == null ? void 0 : n.traits) && { user_traits: i.user.traits }
308
+ ...(e == null ? void 0 : e.device) && { device: e.device },
309
+ ...(e == null ? void 0 : e.utm) && { utm: e.utm },
310
+ ...((s = e == null ? void 0 : e.user) == null ? void 0 : s.email) && { user_email: e.user.email },
311
+ ...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits }
178
312
  };
179
313
  try {
180
- await this.client.event(e.action, 0, s), this.log("Tracked event", { event: e, context: i });
314
+ await this.client.event(i.action, 0, t), this.log("Tracked event", { event: i, context: e });
181
315
  } catch (o) {
182
316
  console.error("[Pirsch-Client] Failed to track event:", o);
183
317
  }
184
318
  }
185
- pageView(e, i) {
186
- if (!(!this.isEnabled() || !this.initialized || !this.client || !l())) {
187
- if (this.client.hit().catch((s) => {
188
- console.error("[Pirsch-Client] Failed to track page view:", s);
189
- }), e && Object.keys(e).length > 0) {
190
- const s = {
191
- ...e,
192
- ...(i == null ? void 0 : i.page) && {
193
- path: i.page.path,
194
- title: i.page.title,
195
- referrer: i.page.referrer
319
+ pageView(i, e) {
320
+ if (!(!this.isEnabled() || !this.initialized || !this.client || !a())) {
321
+ if (this.client.hit().catch((t) => {
322
+ console.error("[Pirsch-Client] Failed to track page view:", t);
323
+ }), i && Object.keys(i).length > 0) {
324
+ const t = {
325
+ ...i,
326
+ ...(e == null ? void 0 : e.page) && {
327
+ path: e.page.path,
328
+ title: e.page.title,
329
+ referrer: e.page.referrer
196
330
  }
197
331
  };
198
- this.client.event("page_view", 0, s).catch((r) => {
332
+ this.client.event("page_view", 0, t).catch((s) => {
199
333
  console.error(
200
334
  "[Pirsch-Client] Failed to track page view event:",
201
- r
335
+ s
202
336
  );
203
337
  });
204
338
  }
205
- this.log("Tracked page view", { properties: e, context: i });
339
+ this.log("Tracked page view", { properties: i, context: e });
206
340
  }
207
341
  }
208
- pageLeave(e, i) {
209
- if (!this.isEnabled() || !this.initialized || !this.client || !l())
342
+ pageLeave(i, e) {
343
+ if (!this.isEnabled() || !this.initialized || !this.client || !a())
210
344
  return;
211
- const s = {
212
- ...e,
213
- ...(i == null ? void 0 : i.page) && {
214
- path: i.page.path,
215
- title: i.page.title
345
+ const t = {
346
+ ...i,
347
+ ...(e == null ? void 0 : e.page) && {
348
+ path: e.page.path,
349
+ title: e.page.title
216
350
  }
217
351
  };
218
- this.client.event("page_leave", 0, s).catch((r) => {
219
- console.error("[Pirsch-Client] Failed to track page leave:", r);
220
- }), this.log("Tracked page leave", { properties: e, context: i });
352
+ this.client.event("page_leave", 0, t).catch((s) => {
353
+ console.error("[Pirsch-Client] Failed to track page leave:", s);
354
+ }), this.log("Tracked page leave", { properties: i, context: e });
221
355
  }
222
356
  reset() {
223
- !this.isEnabled() || !this.initialized || !this.client || !l() || (this.client.event("session_reset", 0, {}).catch((e) => {
224
- console.error("[Pirsch-Client] Failed to track session reset:", e);
357
+ !this.isEnabled() || !this.initialized || !this.client || !a() || (this.client.event("session_reset", 0, {}).catch((i) => {
358
+ console.error("[Pirsch-Client] Failed to track session reset:", i);
225
359
  }), this.log("Reset user session"));
226
360
  }
227
361
  }
362
+ class y extends d {
363
+ constructor(i) {
364
+ var e, t, s, n, o;
365
+ super({ debug: i.debug, enabled: i.enabled });
366
+ r(this, "name", "Proxy");
367
+ r(this, "config");
368
+ r(this, "queue", []);
369
+ r(this, "flushTimer");
370
+ r(this, "batchSize");
371
+ r(this, "batchInterval");
372
+ r(this, "retryAttempts");
373
+ r(this, "retryBackoff");
374
+ r(this, "retryInitialDelay");
375
+ this.config = i, this.batchSize = ((e = i.batch) == null ? void 0 : e.size) ?? 10, this.batchInterval = ((t = i.batch) == null ? void 0 : t.interval) ?? 5e3, this.retryAttempts = ((s = i.retry) == null ? void 0 : s.attempts) ?? 3, this.retryBackoff = ((n = i.retry) == null ? void 0 : n.backoff) ?? "exponential", this.retryInitialDelay = ((o = i.retry) == null ? void 0 : o.initialDelay) ?? 1e3, typeof window < "u" && (window.addEventListener("beforeunload", () => {
376
+ this.flush(!0);
377
+ }), document.addEventListener("visibilitychange", () => {
378
+ document.visibilityState === "hidden" && this.flush(!0);
379
+ }));
380
+ }
381
+ async initialize() {
382
+ this.isEnabled() && this.log("Initialized successfully", { endpoint: this.config.endpoint });
383
+ }
384
+ identify(i, e) {
385
+ this.isEnabled() && (this.queueEvent({
386
+ type: "identify",
387
+ userId: i,
388
+ traits: e
389
+ }), this.log("Queued identify event", { userId: i, traits: e }));
390
+ }
391
+ async track(i, e) {
392
+ this.isEnabled() && (this.queueEvent({
393
+ type: "track",
394
+ event: i,
395
+ context: this.enrichContext(e)
396
+ }), this.log("Queued track event", { event: i, context: e }));
397
+ }
398
+ pageView(i, e) {
399
+ this.isEnabled() && (this.queueEvent({
400
+ type: "pageView",
401
+ properties: i,
402
+ context: this.enrichContext(e)
403
+ }), this.log("Queued page view event", { properties: i, context: e }));
404
+ }
405
+ async reset() {
406
+ this.isEnabled() && (this.queueEvent({
407
+ type: "reset"
408
+ }), this.log("Queued reset event"));
409
+ }
410
+ async shutdown() {
411
+ await this.flush(!0), this.log("Shutdown complete");
412
+ }
413
+ /**
414
+ * Manually flush all queued events
415
+ */
416
+ async flush(i = !1) {
417
+ if (this.queue.length === 0) return;
418
+ const e = [...this.queue];
419
+ this.queue = [], this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = void 0), await this.sendEvents(e, i);
420
+ }
421
+ queueEvent(i) {
422
+ if (this.queue.push(i), this.queue.length >= this.batchSize) {
423
+ this.flush().catch((e) => {
424
+ console.error("[Proxy] Failed to flush events:", e);
425
+ });
426
+ return;
427
+ }
428
+ this.flushTimer || (this.flushTimer = setTimeout(() => {
429
+ this.flush().catch((e) => {
430
+ console.error("[Proxy] Failed to flush events:", e);
431
+ });
432
+ }, this.batchInterval));
433
+ }
434
+ async sendEvents(i, e = !1) {
435
+ const t = { events: i };
436
+ if (e && typeof navigator < "u" && navigator.sendBeacon) {
437
+ const s = new Blob([JSON.stringify(t)], {
438
+ type: "application/json"
439
+ });
440
+ navigator.sendBeacon(this.config.endpoint, s) || console.warn("[Proxy] Failed to send events via beacon");
441
+ return;
442
+ }
443
+ await this.sendWithRetry(t);
444
+ }
445
+ async sendWithRetry(i, e = 0) {
446
+ try {
447
+ const t = await fetch(this.config.endpoint, {
448
+ method: "POST",
449
+ headers: {
450
+ "Content-Type": "application/json",
451
+ ...this.config.headers
452
+ },
453
+ body: JSON.stringify(i),
454
+ // Don't include credentials by default
455
+ credentials: "same-origin"
456
+ });
457
+ if (!t.ok)
458
+ throw new Error(`HTTP ${t.status}: ${t.statusText}`);
459
+ this.log(`Sent ${i.events.length} events successfully`);
460
+ } catch (t) {
461
+ if (e < this.retryAttempts) {
462
+ const s = this.calculateRetryDelay(e);
463
+ return this.log(`Retry attempt ${e + 1} after ${s}ms`, { error: t }), await new Promise((n) => setTimeout(n, s)), this.sendWithRetry(i, e + 1);
464
+ }
465
+ throw console.error("[Proxy] Failed to send events after retries:", t), t;
466
+ }
467
+ }
468
+ calculateRetryDelay(i) {
469
+ return this.retryBackoff === "exponential" ? this.retryInitialDelay * 2 ** i : this.retryInitialDelay * (i + 1);
470
+ }
471
+ enrichContext(i) {
472
+ return typeof window > "u" ? i || {} : {
473
+ ...i,
474
+ page: {
475
+ path: window.location.pathname,
476
+ title: document.title,
477
+ referrer: document.referrer,
478
+ ...i == null ? void 0 : i.page,
479
+ url: window.location.href
480
+ },
481
+ user: {
482
+ ...i == null ? void 0 : i.user
483
+ },
484
+ device: {
485
+ ...i == null ? void 0 : i.device,
486
+ userAgent: navigator.userAgent,
487
+ language: navigator.language,
488
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
489
+ screen: {
490
+ width: window.screen.width,
491
+ height: window.screen.height
492
+ },
493
+ viewport: {
494
+ width: window.innerWidth,
495
+ height: window.innerHeight
496
+ }
497
+ }
498
+ };
499
+ }
500
+ }
228
501
  export {
229
- h as BaseAnalyticsProvider,
230
- m as BentoClientProvider,
231
- b as PirschClientProvider,
232
- y as PostHogClientProvider
502
+ d as BaseAnalyticsProvider,
503
+ b as BentoClientProvider,
504
+ w as PirschClientProvider,
505
+ E as PostHogClientProvider,
506
+ y as ProxyProvider
233
507
  };