@stacksee/analytics 0.9.0 → 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.
@@ -1,10 +1,10 @@
1
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";
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 d {
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 s = document.createElement("script");
41
- s.src = `https://cdn.bentonow.com/v1/${this.config.siteUuid}/bento.js`, s.async = !0, s.onload = () => {
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
- }, s.onerror = () => {
43
+ }, t.onerror = () => {
44
44
  e(new Error("Failed to load Bento script"));
45
- }, document.head.appendChild(s);
45
+ }, document.head.appendChild(t);
46
46
  });
47
47
  }
48
48
  async waitForBento(i = 50, e = 100) {
49
- for (let t = 0; t < i; t++) {
49
+ for (let s = 0; s < i; s++) {
50
50
  if (window.bento)
51
51
  return;
52
- await new Promise((s) => setTimeout(s, e));
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 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);
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: t, traits: e });
63
+ this.log("Identified user", { userId: i, email: s, traits: e });
64
64
  }
65
65
  track(i, e) {
66
- var s, n;
66
+ var t, n, d;
67
67
  if (!this.isEnabled() || !this.initialized || !this.bento) return;
68
- const t = {
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
- referrer: e.page.referrer
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
- ...((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 }
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, t), this.log("Tracked event", { event: i, context: e });
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
- path: e.page.path,
96
- title: e.page.title,
97
- referrer: e.page.referrer
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 t = {
123
+ const s = {
109
124
  ...i,
125
+ date: (/* @__PURE__ */ new Date()).toISOString(),
110
126
  ...(e == null ? void 0 : e.page) && {
111
- path: e.page.path,
112
- title: e.page.title,
113
- referrer: e.page.referrer
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", t), this.log("Tracked page leave", { properties: i, context: e });
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, 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 }));
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 d {
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");
@@ -271,7 +294,7 @@ class w extends d {
271
294
  if (!this.config.identificationCode || typeof this.config.identificationCode != "string")
272
295
  throw new Error("Pirsch requires an identificationCode");
273
296
  try {
274
- const { Pirsch: i } = await import("../web-CvEQewPd.js").then((e) => e.w);
297
+ const { Pirsch: i } = await import("../web-imCcOhDC.js").then((e) => e.w);
275
298
  this.client = new i({
276
299
  identificationCode: this.config.identificationCode,
277
300
  ...this.config.hostname && { hostname: this.config.hostname }
@@ -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((t) => {
292
- console.error("[Pirsch-Client] Failed to track identify event:", t);
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 s, n;
319
+ var t, n;
297
320
  if (!this.isEnabled() || !this.initialized || !this.client) return;
298
- const t = {
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
- ...((s = e == null ? void 0 : e.user) == null ? void 0 : s.email) && { user_email: e.user.email },
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, t), this.log("Tracked event", { event: i, context: e });
315
- } catch (o) {
316
- console.error("[Pirsch-Client] Failed to track event:", o);
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((t) => {
322
- console.error("[Pirsch-Client] Failed to track page view:", t);
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 t = {
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, t).catch((s) => {
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
- s
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 t = {
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, t).catch((s) => {
353
- console.error("[Pirsch-Client] Failed to track page leave:", s);
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 d {
385
+ class y extends o {
363
386
  constructor(i) {
364
- var e, t, s, n, o;
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 = ((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", () => {
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 t = { events: i };
458
+ const s = { events: i };
436
459
  if (e && typeof navigator < "u" && navigator.sendBeacon) {
437
- const s = new Blob([JSON.stringify(t)], {
460
+ const t = new Blob([JSON.stringify(s)], {
438
461
  type: "application/json"
439
462
  });
440
- navigator.sendBeacon(this.config.endpoint, s) || console.warn("[Proxy] Failed to send events via beacon");
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(t);
466
+ await this.sendWithRetry(s);
444
467
  }
445
468
  async sendWithRetry(i, e = 0) {
446
469
  try {
447
- const t = await fetch(this.config.endpoint, {
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 (!t.ok)
458
- throw new Error(`HTTP ${t.status}: ${t.statusText}`);
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 (t) {
483
+ } catch (s) {
461
484
  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);
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:", t), t;
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
- d as BaseAnalyticsProvider,
525
+ o as BaseAnalyticsProvider,
503
526
  b as BentoClientProvider,
504
527
  w as PirschClientProvider,
505
528
  E as PostHogClientProvider,