@stacksee/analytics 0.3.4 → 0.4.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.
@@ -2,7 +2,7 @@ var c = Object.defineProperty;
2
2
  var u = (t, e, i) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
3
  var s = (t, e, i) => u(t, typeof e != "symbol" ? e + "" : e, i);
4
4
  import { i as h } from "./environment-Bnc8FqHv.js";
5
- class f {
5
+ class p {
6
6
  constructor(e) {
7
7
  s(this, "providers", []);
8
8
  s(this, "context", {});
@@ -52,7 +52,7 @@ class f {
52
52
  timestamp: Date.now(),
53
53
  userId: this.userId,
54
54
  sessionId: this.sessionId
55
- }, a = this.providers.map(async (d) => {
55
+ }, o = this.providers.map(async (d) => {
56
56
  try {
57
57
  await d.track(r, this.context);
58
58
  } catch (l) {
@@ -62,11 +62,11 @@ class f {
62
62
  );
63
63
  }
64
64
  });
65
- await Promise.all(a);
65
+ await Promise.all(o);
66
66
  }
67
- page(e) {
67
+ pageView(e) {
68
68
  this.ensureInitialized().catch((i) => {
69
- console.error("[Analytics] Failed to initialize during page:", i);
69
+ console.error("[Analytics] Failed to initialize during pageView:", i);
70
70
  }), this.updateContext({
71
71
  page: {
72
72
  path: window.location.pathname,
@@ -75,7 +75,14 @@ class f {
75
75
  }
76
76
  });
77
77
  for (const i of this.providers)
78
- i.page(e, this.context);
78
+ i.pageView(e, this.context);
79
+ }
80
+ pageLeave(e) {
81
+ this.ensureInitialized().catch((i) => {
82
+ console.error("[Analytics] Failed to initialize during pageLeave:", i);
83
+ });
84
+ for (const i of this.providers)
85
+ i.pageLeave && i.pageLeave(e, this.context);
79
86
  }
80
87
  reset() {
81
88
  this.userId = void 0, this.sessionId = this.generateSessionId();
@@ -83,14 +90,14 @@ class f {
83
90
  e.reset();
84
91
  }
85
92
  updateContext(e) {
86
- var i, r, a;
93
+ var i, r, o;
87
94
  this.context = {
88
95
  ...this.context,
89
96
  ...e,
90
97
  page: e.page ? {
91
98
  path: e.page.path || ((i = this.context.page) == null ? void 0 : i.path) || window.location.pathname,
92
99
  title: e.page.title || ((r = this.context.page) == null ? void 0 : r.title),
93
- referrer: e.page.referrer || ((a = this.context.page) == null ? void 0 : a.referrer)
100
+ referrer: e.page.referrer || ((o = this.context.page) == null ? void 0 : o.referrer)
94
101
  } : this.context.page,
95
102
  device: {
96
103
  ...this.context.device,
@@ -133,41 +140,45 @@ function m(t) {
133
140
  debug: t.debug,
134
141
  enabled: t.enabled
135
142
  };
136
- return n = new f(
143
+ return n = new p(
137
144
  e
138
145
  ), n.initialize().catch((i) => {
139
146
  console.error("[Analytics] Failed to initialize:", i);
140
147
  }), n;
141
148
  }
142
- function o() {
149
+ function a() {
143
150
  if (!n)
144
151
  throw new Error(
145
152
  "[Analytics] Not initialized. Call createAnalytics() first."
146
153
  );
147
154
  return n;
148
155
  }
156
+ function v(t, e) {
157
+ return a().track(t, e);
158
+ }
149
159
  function y(t, e) {
150
- return o().track(t, e);
160
+ a().identify(t, e);
151
161
  }
152
- function w(t, e) {
153
- o().identify(t, e);
162
+ function w(t) {
163
+ a().pageView(t);
154
164
  }
155
165
  function z(t) {
156
- o().page(t);
157
- }
158
- function v() {
159
- o().reset();
166
+ a().pageLeave(t);
160
167
  }
161
168
  function x() {
169
+ a().reset();
170
+ }
171
+ function A() {
162
172
  n = null;
163
173
  }
164
174
  export {
165
- f as B,
166
- x as a,
175
+ p as B,
176
+ z as a,
177
+ A as b,
167
178
  m as c,
168
- o as g,
169
- w as i,
170
- z as p,
171
- v as r,
172
- y as t
179
+ a as g,
180
+ y as i,
181
+ w as p,
182
+ x as r,
183
+ v as t
173
184
  };
package/dist/client.js CHANGED
@@ -1,11 +1,12 @@
1
- import { c as t, c as e, g as c, i, p as n, r, a as l, t as y } from "./client-bVe2QF_t.js";
1
+ import { c as s, c as t, g as c, i, a as n, p as r, r as l, b as y, t as g } from "./client-CyxgEISv.js";
2
2
  export {
3
- t as createAnalytics,
4
- e as createClientAnalytics,
3
+ s as createAnalytics,
4
+ t as createClientAnalytics,
5
5
  c as getAnalytics,
6
6
  i as identify,
7
- n as page,
8
- r as reset,
9
- l as resetAnalyticsInstance,
10
- y as track
7
+ n as pageLeave,
8
+ r as pageView,
9
+ l as reset,
10
+ y as resetAnalyticsInstance,
11
+ g as track
11
12
  };
package/dist/index.js CHANGED
@@ -1,17 +1,18 @@
1
- import { B as t, c as a, g as i, i as s, p as o, r as n, t as l } from "./client-bVe2QF_t.js";
2
- import { ServerAnalytics as y, createServerAnalytics as v } from "./server.js";
3
- import { BaseAnalyticsProvider as C, PostHogClientProvider as g, PostHogServerProvider as p } from "./providers.js";
1
+ import { B as r, c as t, g as s, i, a as n, p as o, r as l, t as c } from "./client-CyxgEISv.js";
2
+ import { ServerAnalytics as y, createServerAnalytics as C } from "./server.js";
3
+ import { B as p, P as A, a as P } from "./server-BKqARaUf.js";
4
4
  export {
5
- C as BaseAnalyticsProvider,
6
- t as BrowserAnalytics,
7
- g as PostHogClientProvider,
8
- p as PostHogServerProvider,
5
+ p as BaseAnalyticsProvider,
6
+ r as BrowserAnalytics,
7
+ A as PostHogClientProvider,
8
+ P as PostHogServerProvider,
9
9
  y as ServerAnalytics,
10
- a as createClientAnalytics,
11
- v as createServerAnalytics,
12
- i as getAnalytics,
13
- s as identifyClient,
14
- o as pageClient,
15
- n as resetClient,
16
- l as trackClient
10
+ t as createClientAnalytics,
11
+ C as createServerAnalytics,
12
+ s as getAnalytics,
13
+ i as identifyClient,
14
+ n as pageLeaveClient,
15
+ o as pageViewClient,
16
+ l as resetClient,
17
+ c as trackClient
17
18
  };