@stacksee/analytics 0.13.0 → 0.13.2

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/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var u = Object.defineProperty;
2
- var h = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var c = (i, e, t) => h(i, typeof e != "symbol" ? e + "" : e, t);
2
+ var h = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
+ var c = (a, e, t) => h(a, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { P as w } from "./server-DjEk1fUD.js";
5
5
  import { B as y } from "./base.provider-AfFL5W_P.js";
6
6
  class f {
@@ -68,25 +68,25 @@ class f {
68
68
  ), r.excludeEvents && r.eventPatterns && console.warn(
69
69
  `[Analytics] Provider ${r.provider.name} has both 'excludeEvents' and 'eventPatterns' specified. Using 'eventPatterns' and ignoring 'excludeEvents'.`
70
70
  );
71
- let a;
72
- r.methods ? a = new Set(r.methods) : r.exclude ? a = new Set(
71
+ let i;
72
+ r.methods ? i = new Set(r.methods) : r.exclude ? i = new Set(
73
73
  t.filter(
74
- (l) => {
74
+ (o) => {
75
75
  var v;
76
- return !((v = r.exclude) != null && v.includes(l));
76
+ return !((v = r.exclude) != null && v.includes(o));
77
77
  }
78
78
  )
79
- ) : a = new Set(t);
80
- let o, d, s;
81
- return r.events && r.events.length > 0 ? o = new Set(r.events) : r.eventPatterns && r.eventPatterns.length > 0 ? s = r.eventPatterns.map((l) => {
82
- const v = l.replace(/\*/g, ".*");
79
+ ) : i = new Set(t);
80
+ let s, l, d;
81
+ return r.events && r.events.length > 0 ? s = new Set(r.events) : r.eventPatterns && r.eventPatterns.length > 0 ? d = r.eventPatterns.map((o) => {
82
+ const v = o.replace(/\*/g, ".*");
83
83
  return new RegExp(`^${v}$`);
84
- }) : r.excludeEvents && r.excludeEvents.length > 0 && (d = new Set(r.excludeEvents)), {
84
+ }) : r.excludeEvents && r.excludeEvents.length > 0 && (l = new Set(r.excludeEvents)), {
85
85
  provider: r.provider,
86
- enabledMethods: a,
87
- enabledEvents: o,
88
- excludedEvents: d,
89
- eventPatterns: s
86
+ enabledMethods: i,
87
+ enabledEvents: s,
88
+ excludedEvents: l,
89
+ eventPatterns: d
90
90
  };
91
91
  });
92
92
  }
@@ -191,9 +191,11 @@ class f {
191
191
  * }
192
192
  * ```
193
193
  */
194
- identify(e, t) {
195
- for (const n of this.providerConfigs)
196
- this.shouldCallMethod(n, "identify") && n.provider.identify(e, t);
194
+ async identify(e, t) {
195
+ const n = this.providerConfigs.filter((i) => this.shouldCallMethod(i, "identify")).map((i) => i.provider.identify(e, t)), r = await Promise.allSettled(n);
196
+ for (const i of r)
197
+ if (i.status === "rejected")
198
+ throw i.reason;
197
199
  }
198
200
  /**
199
201
  * Tracks a custom event with properties and optional context.
@@ -317,7 +319,7 @@ class f {
317
319
  * ```
318
320
  */
319
321
  async track(e, t, n) {
320
- var d;
322
+ var l;
321
323
  if (!this.initialized) {
322
324
  console.warn("[Analytics] Not initialized. Call initialize() first.");
323
325
  return;
@@ -329,23 +331,23 @@ class f {
329
331
  timestamp: Date.now(),
330
332
  userId: n == null ? void 0 : n.userId,
331
333
  sessionId: n == null ? void 0 : n.sessionId
332
- }, a = {
334
+ }, i = {
333
335
  ...this.config.defaultContext,
334
336
  ...n == null ? void 0 : n.context,
335
- user: (n == null ? void 0 : n.user) || ((d = n == null ? void 0 : n.context) == null ? void 0 : d.user)
336
- }, o = this.providerConfigs.filter(
337
- (s) => this.shouldCallMethod(s, "track") && this.shouldTrackEvent(s, e)
338
- ).map(async (s) => {
337
+ user: (n == null ? void 0 : n.user) || ((l = n == null ? void 0 : n.context) == null ? void 0 : l.user)
338
+ }, s = this.providerConfigs.filter(
339
+ (d) => this.shouldCallMethod(d, "track") && this.shouldTrackEvent(d, e)
340
+ ).map(async (d) => {
339
341
  try {
340
- await s.provider.track(r, a);
341
- } catch (l) {
342
+ await d.provider.track(r, i);
343
+ } catch (o) {
342
344
  console.error(
343
- `[Analytics] Provider ${s.provider.name} failed to track event:`,
344
- l
345
+ `[Analytics] Provider ${d.provider.name} failed to track event:`,
346
+ o
345
347
  );
346
348
  }
347
349
  });
348
- await Promise.all(o);
350
+ await Promise.all(s);
349
351
  }
350
352
  /**
351
353
  * Tracks a page view event from the server side.
@@ -407,14 +409,15 @@ class f {
407
409
  * }
408
410
  * ```
409
411
  */
410
- pageView(e, t) {
412
+ async pageView(e, t) {
411
413
  if (!this.initialized) return;
412
414
  const n = {
413
415
  ...this.config.defaultContext,
414
416
  ...t == null ? void 0 : t.context
415
- };
416
- for (const r of this.providerConfigs)
417
- this.shouldCallMethod(r, "pageView") && r.provider.pageView(e, n);
417
+ }, r = this.providerConfigs.filter((s) => this.shouldCallMethod(s, "pageView")).map((s) => s.provider.pageView(e, n)), i = await Promise.allSettled(r);
418
+ for (const s of i)
419
+ if (s.status === "rejected")
420
+ throw s.reason;
418
421
  }
419
422
  /**
420
423
  * Tracks when a user leaves a page from the server side.
@@ -577,11 +580,11 @@ class f {
577
580
  return t.length > 1 && t[0] ? t[0] : "engagement";
578
581
  }
579
582
  }
580
- function x(i) {
583
+ function m(a) {
581
584
  const e = {
582
- providers: i.providers || [],
583
- debug: i.debug,
584
- enabled: i.enabled
585
+ providers: a.providers || [],
586
+ debug: a.debug,
587
+ enabled: a.enabled
585
588
  }, t = new f(e);
586
589
  return t.initialize(), t;
587
590
  }
@@ -589,5 +592,5 @@ export {
589
592
  y as BaseAnalyticsProvider,
590
593
  w as PostHogServerProvider,
591
594
  f as ServerAnalytics,
592
- x as createServerAnalytics
595
+ m as createServerAnalytics
593
596
  };