@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.
- package/dist/{client-yfDfetWt.js → client-CyxgEISv.js} +40 -28
- package/dist/client.js +8 -7
- package/dist/environment-Bnc8FqHv.js +6 -0
- package/dist/index.js +15 -14
- package/dist/providers.js +4 -2609
- package/dist/server-BKqARaUf.js +174 -0
- package/dist/server.js +18 -9
- package/dist/src/adapters/client/browser-analytics.d.ts +2 -1
- package/dist/src/adapters/server/server-analytics.d.ts +4 -1
- package/dist/src/client/index.d.ts +2 -2
- package/dist/src/client.d.ts +5 -1
- package/dist/src/core/events/types.d.ts +2 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/providers/base.provider.d.ts +2 -1
- package/dist/src/providers/index.d.ts +2 -1
- package/dist/src/providers/posthog/client.d.ts +5 -9
- package/dist/src/providers/posthog/server.d.ts +5 -3
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/utils/environment.d.ts +18 -0
- package/dist/test/mock-provider.d.ts +7 -2
- package/dist/test/utils.test.d.ts +1 -0
- package/package.json +3 -3
- package/readme.md +40 -2
- package/dist/module-BfXpy-Wp.js +0 -4198
- package/dist/src/providers/posthog/types.d.ts +0 -27
|
@@ -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
|
-
|
|
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
|
-
},
|
|
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(
|
|
65
|
+
await Promise.all(o);
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
pageView(e) {
|
|
67
68
|
this.ensureInitialized().catch((i) => {
|
|
68
|
-
console.error("[Analytics] Failed to initialize during
|
|
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.
|
|
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,
|
|
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 || ((
|
|
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
|
|
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
|
|
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
|
|
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
|
|
149
|
-
return
|
|
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
|
|
152
|
-
|
|
162
|
+
function w(t) {
|
|
163
|
+
a().pageView(t);
|
|
153
164
|
}
|
|
154
|
-
function
|
|
155
|
-
|
|
165
|
+
function z(t) {
|
|
166
|
+
a().pageLeave(t);
|
|
156
167
|
}
|
|
157
|
-
function
|
|
158
|
-
|
|
168
|
+
function x() {
|
|
169
|
+
a().reset();
|
|
159
170
|
}
|
|
160
|
-
function
|
|
171
|
+
function A() {
|
|
161
172
|
n = null;
|
|
162
173
|
}
|
|
163
174
|
export {
|
|
164
|
-
|
|
175
|
+
p as B,
|
|
165
176
|
z as a,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
y as
|
|
170
|
-
w as
|
|
171
|
-
|
|
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
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
s as createAnalytics,
|
|
4
|
+
t as createClientAnalytics,
|
|
5
5
|
c as getAnalytics,
|
|
6
6
|
i as identify,
|
|
7
|
-
n as
|
|
8
|
-
r as
|
|
9
|
-
l as
|
|
10
|
-
y as
|
|
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
|
|
2
|
-
import { ServerAnalytics as y, createServerAnalytics as
|
|
3
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
p as BaseAnalyticsProvider,
|
|
6
|
+
r as BrowserAnalytics,
|
|
7
|
+
A as PostHogClientProvider,
|
|
8
|
+
P as PostHogServerProvider,
|
|
9
9
|
y as ServerAnalytics,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
l as
|
|
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
|
};
|