@stacksee/analytics 0.3.3 → 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.
@@ -1,7 +1,8 @@
1
1
  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
- class h {
4
+ import { i as h } from "./environment-Bnc8FqHv.js";
5
+ class p {
5
6
  constructor(e) {
6
7
  s(this, "providers", []);
7
8
  s(this, "context", {});
@@ -12,7 +13,7 @@ class h {
12
13
  this.providers = e.providers, e.defaultContext && (this.context = { ...e.defaultContext }), this.sessionId = this.generateSessionId();
13
14
  }
14
15
  async initialize() {
15
- if (!this.initialized)
16
+ if (h() && !this.initialized)
16
17
  return this.initializePromise ? this.initializePromise : (this.initializePromise = this._doInitialize(), this.initializePromise);
17
18
  }
18
19
  async _doInitialize() {
@@ -51,7 +52,7 @@ class h {
51
52
  timestamp: Date.now(),
52
53
  userId: this.userId,
53
54
  sessionId: this.sessionId
54
- }, a = this.providers.map(async (d) => {
55
+ }, o = this.providers.map(async (d) => {
55
56
  try {
56
57
  await d.track(r, this.context);
57
58
  } catch (l) {
@@ -61,11 +62,11 @@ class h {
61
62
  );
62
63
  }
63
64
  });
64
- await Promise.all(a);
65
+ await Promise.all(o);
65
66
  }
66
- page(e) {
67
+ pageView(e) {
67
68
  this.ensureInitialized().catch((i) => {
68
- console.error("[Analytics] Failed to initialize during page:", i);
69
+ console.error("[Analytics] Failed to initialize during pageView:", i);
69
70
  }), this.updateContext({
70
71
  page: {
71
72
  path: window.location.pathname,
@@ -74,7 +75,14 @@ class h {
74
75
  }
75
76
  });
76
77
  for (const i of this.providers)
77
- 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);
78
86
  }
79
87
  reset() {
80
88
  this.userId = void 0, this.sessionId = this.generateSessionId();
@@ -82,14 +90,14 @@ class h {
82
90
  e.reset();
83
91
  }
84
92
  updateContext(e) {
85
- var i, r, a;
93
+ var i, r, o;
86
94
  this.context = {
87
95
  ...this.context,
88
96
  ...e,
89
97
  page: e.page ? {
90
98
  path: e.page.path || ((i = this.context.page) == null ? void 0 : i.path) || window.location.pathname,
91
99
  title: e.page.title || ((r = this.context.page) == null ? void 0 : r.title),
92
- 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)
93
101
  } : this.context.page,
94
102
  device: {
95
103
  ...this.context.device,
@@ -124,7 +132,7 @@ class h {
124
132
  }
125
133
  }
126
134
  let n = null;
127
- function p(t) {
135
+ function m(t) {
128
136
  if (n)
129
137
  return console.warn("[Analytics] Already initialized"), n;
130
138
  const e = {
@@ -132,41 +140,45 @@ function p(t) {
132
140
  debug: t.debug,
133
141
  enabled: t.enabled
134
142
  };
135
- return n = new h(
143
+ return n = new p(
136
144
  e
137
145
  ), n.initialize().catch((i) => {
138
146
  console.error("[Analytics] Failed to initialize:", i);
139
147
  }), n;
140
148
  }
141
- function o() {
149
+ function a() {
142
150
  if (!n)
143
151
  throw new Error(
144
152
  "[Analytics] Not initialized. Call createAnalytics() first."
145
153
  );
146
154
  return n;
147
155
  }
148
- function g(t, e) {
149
- return o().track(t, e);
156
+ function v(t, e) {
157
+ return a().track(t, e);
158
+ }
159
+ function y(t, e) {
160
+ a().identify(t, e);
150
161
  }
151
- function m(t, e) {
152
- o().identify(t, e);
162
+ function w(t) {
163
+ a().pageView(t);
153
164
  }
154
- function y(t) {
155
- o().page(t);
165
+ function z(t) {
166
+ a().pageLeave(t);
156
167
  }
157
- function w() {
158
- o().reset();
168
+ function x() {
169
+ a().reset();
159
170
  }
160
- function z() {
171
+ function A() {
161
172
  n = null;
162
173
  }
163
174
  export {
164
- h as B,
175
+ p as B,
165
176
  z as a,
166
- p as c,
167
- o as g,
168
- m as i,
169
- y as p,
170
- w as r,
171
- g as t
177
+ A as b,
178
+ m as c,
179
+ a as g,
180
+ y as i,
181
+ w as p,
182
+ x as r,
183
+ v as t
172
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-yfDfetWt.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
  };
@@ -0,0 +1,6 @@
1
+ function e() {
2
+ return typeof window < "u" && typeof window.document < "u";
3
+ }
4
+ export {
5
+ e as i
6
+ };
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-yfDfetWt.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
  };