@stacksee/analytics 0.7.0 → 0.9.0
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/providers/bento/client.d.ts +101 -0
- package/dist/providers/client.d.ts +3 -0
- package/dist/providers/client.js +415 -141
- package/dist/providers/proxy/client.d.ts +56 -0
- package/dist/providers/proxy/server.d.ts +55 -0
- package/dist/providers/proxy/types.d.ts +64 -0
- package/dist/providers/server.d.ts +2 -0
- package/dist/providers/server.js +209 -123
- package/package.json +5 -1
package/dist/providers/client.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { B as
|
|
5
|
-
import { i as
|
|
6
|
-
import { P as
|
|
7
|
-
class
|
|
8
|
-
constructor(
|
|
9
|
-
super({ debug:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.config =
|
|
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";
|
|
5
|
+
import { i as a } from "../client-DTHZYkxx.js";
|
|
6
|
+
import { P as E } from "../client-DTHZYkxx.js";
|
|
7
|
+
class b extends d {
|
|
8
|
+
constructor(i) {
|
|
9
|
+
super({ debug: i.debug, enabled: i.enabled });
|
|
10
|
+
r(this, "name", "Bento-Client");
|
|
11
|
+
r(this, "bento");
|
|
12
|
+
r(this, "initialized", !1);
|
|
13
|
+
r(this, "config");
|
|
14
|
+
r(this, "scriptLoaded", !1);
|
|
15
|
+
this.config = i;
|
|
16
16
|
}
|
|
17
17
|
async initialize() {
|
|
18
18
|
if (this.isEnabled() && !this.initialized) {
|
|
19
|
-
if (!
|
|
19
|
+
if (!a()) {
|
|
20
20
|
this.log("Skipping initialization - not in browser environment");
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -24,210 +24,484 @@ class m extends h {
|
|
|
24
24
|
throw new Error("Bento requires a siteUuid");
|
|
25
25
|
try {
|
|
26
26
|
this.scriptLoaded || await this.loadBentoScript(), await this.waitForBento(), this.bento = window.bento, this.initialized = !0, this.log("Initialized successfully", this.config);
|
|
27
|
-
} catch (
|
|
28
|
-
throw console.error("[Bento-Client] Failed to initialize:",
|
|
27
|
+
} catch (i) {
|
|
28
|
+
throw console.error("[Bento-Client] Failed to initialize:", i), i;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
async loadBentoScript() {
|
|
33
|
-
return new Promise((
|
|
33
|
+
return new Promise((i, e) => {
|
|
34
34
|
if (document.querySelector(
|
|
35
35
|
'script[src*="bentonow.com"]'
|
|
36
36
|
)) {
|
|
37
|
-
this.scriptLoaded = !0,
|
|
37
|
+
this.scriptLoaded = !0, i();
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
this.scriptLoaded = !0,
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
}, document.head.appendChild(
|
|
40
|
+
const s = document.createElement("script");
|
|
41
|
+
s.src = `https://cdn.bentonow.com/v1/${this.config.siteUuid}/bento.js`, s.async = !0, s.onload = () => {
|
|
42
|
+
this.scriptLoaded = !0, i();
|
|
43
|
+
}, s.onerror = () => {
|
|
44
|
+
e(new Error("Failed to load Bento script"));
|
|
45
|
+
}, document.head.appendChild(s);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
async waitForBento(
|
|
49
|
-
for (let
|
|
48
|
+
async waitForBento(i = 50, e = 100) {
|
|
49
|
+
for (let t = 0; t < i; t++) {
|
|
50
50
|
if (window.bento)
|
|
51
51
|
return;
|
|
52
|
-
await new Promise((
|
|
52
|
+
await new Promise((s) => setTimeout(s, e));
|
|
53
53
|
}
|
|
54
54
|
throw new Error("Bento SDK not available after loading script");
|
|
55
55
|
}
|
|
56
|
-
identify(
|
|
56
|
+
identify(i, e) {
|
|
57
57
|
if (!this.isEnabled() || !this.initialized || !this.bento) return;
|
|
58
|
-
const
|
|
59
|
-
if (this.bento.identify(
|
|
60
|
-
const
|
|
61
|
-
delete
|
|
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);
|
|
62
62
|
}
|
|
63
|
-
this.log("Identified user", { userId:
|
|
63
|
+
this.log("Identified user", { userId: i, email: t, traits: e });
|
|
64
64
|
}
|
|
65
|
-
track(
|
|
66
|
-
var
|
|
65
|
+
track(i, e) {
|
|
66
|
+
var s, n;
|
|
67
67
|
if (!this.isEnabled() || !this.initialized || !this.bento) return;
|
|
68
|
-
const
|
|
69
|
-
...
|
|
70
|
-
category:
|
|
71
|
-
timestamp:
|
|
72
|
-
...
|
|
73
|
-
...
|
|
74
|
-
...(
|
|
68
|
+
const t = {
|
|
69
|
+
...i.properties,
|
|
70
|
+
category: i.category,
|
|
71
|
+
timestamp: i.timestamp || Date.now(),
|
|
72
|
+
...i.userId && { userId: i.userId },
|
|
73
|
+
...i.sessionId && { sessionId: i.sessionId },
|
|
74
|
+
...(e == null ? void 0 : e.page) && {
|
|
75
75
|
page: {
|
|
76
|
-
path:
|
|
77
|
-
title:
|
|
78
|
-
referrer:
|
|
76
|
+
path: e.page.path,
|
|
77
|
+
title: e.page.title,
|
|
78
|
+
referrer: e.page.referrer
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
...(
|
|
82
|
-
...(
|
|
81
|
+
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
82
|
+
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
83
83
|
// Include user email and traits as regular event properties
|
|
84
|
-
...((
|
|
85
|
-
...((n =
|
|
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 }
|
|
86
86
|
};
|
|
87
|
-
this.bento.track(
|
|
88
|
-
}
|
|
89
|
-
pageView(
|
|
90
|
-
if (!(!this.isEnabled() || !this.initialized || !this.bento || !
|
|
91
|
-
if (this.bento.view(),
|
|
92
|
-
const
|
|
93
|
-
...
|
|
94
|
-
...(
|
|
95
|
-
path:
|
|
96
|
-
title:
|
|
97
|
-
referrer:
|
|
87
|
+
this.bento.track(i.action, t), this.log("Tracked event", { event: i, context: e });
|
|
88
|
+
}
|
|
89
|
+
pageView(i, e) {
|
|
90
|
+
if (!(!this.isEnabled() || !this.initialized || !this.bento || !a())) {
|
|
91
|
+
if (this.bento.view(), i || e != null && e.page) {
|
|
92
|
+
const t = {
|
|
93
|
+
...i,
|
|
94
|
+
...(e == null ? void 0 : e.page) && {
|
|
95
|
+
path: e.page.path,
|
|
96
|
+
title: e.page.title,
|
|
97
|
+
referrer: e.page.referrer
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
this.bento.track("$
|
|
100
|
+
this.bento.track("$view", t);
|
|
101
101
|
}
|
|
102
|
-
this.log("Tracked page view", { properties:
|
|
102
|
+
this.log("Tracked page view", { properties: i, context: e });
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
pageLeave(
|
|
106
|
-
if (!this.isEnabled() || !this.initialized || !this.bento || !
|
|
105
|
+
pageLeave(i, e) {
|
|
106
|
+
if (!this.isEnabled() || !this.initialized || !this.bento || !a())
|
|
107
107
|
return;
|
|
108
|
-
const
|
|
109
|
-
...
|
|
110
|
-
...(
|
|
111
|
-
path:
|
|
112
|
-
title:
|
|
113
|
-
referrer:
|
|
108
|
+
const t = {
|
|
109
|
+
...i,
|
|
110
|
+
...(e == null ? void 0 : e.page) && {
|
|
111
|
+
path: e.page.path,
|
|
112
|
+
title: e.page.title,
|
|
113
|
+
referrer: e.page.referrer
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
this.bento.track("$pageleave",
|
|
116
|
+
this.bento.track("$pageleave", t), this.log("Tracked page leave", { properties: i, context: e });
|
|
117
117
|
}
|
|
118
118
|
reset() {
|
|
119
|
-
!this.isEnabled() || !this.initialized || !this.bento || !
|
|
119
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
|
|
120
|
+
}
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Bento-Specific Utility Methods
|
|
123
|
+
// ============================================================================
|
|
124
|
+
/**
|
|
125
|
+
* Add a tag to the current user
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* bentoProvider.tag('premium_user');
|
|
130
|
+
* bentoProvider.tag('beta_tester');
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
tag(i) {
|
|
134
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.tag(i), this.log("Added tag to user", { tag: i }));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the current user's email address
|
|
138
|
+
*
|
|
139
|
+
* @returns The user's email or null if not identified
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const email = bentoProvider.getEmail();
|
|
144
|
+
* if (email) {
|
|
145
|
+
* console.log('Current user:', email);
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
getEmail() {
|
|
150
|
+
return !this.isEnabled() || !this.initialized || !this.bento || !a() ? null : this.bento.getEmail();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the current user's name
|
|
154
|
+
*
|
|
155
|
+
* @returns The user's name or null if not set
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const name = bentoProvider.getName();
|
|
160
|
+
* if (name) {
|
|
161
|
+
* console.log('Welcome back,', name);
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
getName() {
|
|
166
|
+
return !this.isEnabled() || !this.initialized || !this.bento || !a() ? null : this.bento.getName();
|
|
167
|
+
}
|
|
168
|
+
// ============================================================================
|
|
169
|
+
// Survey Methods
|
|
170
|
+
// ============================================================================
|
|
171
|
+
/**
|
|
172
|
+
* Show a Bento survey form
|
|
173
|
+
*
|
|
174
|
+
* @param element - The HTML element to render the survey in
|
|
175
|
+
* @param surveyId - The survey ID from your Bento account
|
|
176
|
+
* @param type - Display type: 'popup' or 'inline' (default: 'popup')
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const container = document.getElementById('survey-container');
|
|
181
|
+
* if (container) {
|
|
182
|
+
* bentoProvider.showSurveyForm(container, 'survey-123', 'popup');
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
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 }));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate an email address using Bento's spam check
|
|
191
|
+
*
|
|
192
|
+
* @param email - The email address to validate
|
|
193
|
+
* @returns Promise that resolves to true if email is valid, false if spam
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const isValid = await bentoProvider.spamCheck('user@example.com');
|
|
198
|
+
* if (!isValid) {
|
|
199
|
+
* console.log('Invalid or spam email detected');
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
async spamCheck(i) {
|
|
204
|
+
if (!this.isEnabled() || !this.initialized || !this.bento || !a())
|
|
205
|
+
return !1;
|
|
206
|
+
try {
|
|
207
|
+
const e = await this.bento.spamCheck(i);
|
|
208
|
+
return this.log("Spam check completed", { email: i, result: e }), e;
|
|
209
|
+
} catch (e) {
|
|
210
|
+
return console.error("[Bento-Client] Spam check failed:", e), !1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// ============================================================================
|
|
214
|
+
// Chat Methods (if chat is enabled in Bento)
|
|
215
|
+
// ============================================================================
|
|
216
|
+
/**
|
|
217
|
+
* Show the Bento chat widget
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* bentoProvider.showChat();
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
showChat() {
|
|
225
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.showChat ? (this.bento.showChat(), this.log("Showed chat widget")) : console.warn(
|
|
226
|
+
"[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
|
|
227
|
+
));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Hide the Bento chat widget
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* bentoProvider.hideChat();
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
hideChat() {
|
|
238
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.hideChat ? (this.bento.hideChat(), this.log("Hid chat widget")) : console.warn(
|
|
239
|
+
"[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
|
|
240
|
+
));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Open the Bento chat widget
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* bentoProvider.openChat();
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
openChat() {
|
|
251
|
+
!this.isEnabled() || !this.initialized || !this.bento || !a() || (this.bento.openChat ? (this.bento.openChat(), this.log("Opened chat widget")) : console.warn(
|
|
252
|
+
"[Bento-Client] Chat not available. Make sure chat is enabled in your Bento settings."
|
|
253
|
+
));
|
|
120
254
|
}
|
|
121
255
|
}
|
|
122
|
-
class
|
|
123
|
-
constructor(
|
|
124
|
-
super({ debug:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.config =
|
|
256
|
+
class w extends d {
|
|
257
|
+
constructor(i) {
|
|
258
|
+
super({ debug: i.debug, enabled: i.enabled });
|
|
259
|
+
r(this, "name", "Pirsch-Client");
|
|
260
|
+
r(this, "client");
|
|
261
|
+
r(this, "initialized", !1);
|
|
262
|
+
r(this, "config");
|
|
263
|
+
this.config = i;
|
|
130
264
|
}
|
|
131
265
|
async initialize() {
|
|
132
266
|
if (this.isEnabled() && !this.initialized) {
|
|
133
|
-
if (!
|
|
267
|
+
if (!a()) {
|
|
134
268
|
this.log("Skipping initialization - not in browser environment");
|
|
135
269
|
return;
|
|
136
270
|
}
|
|
137
271
|
if (!this.config.identificationCode || typeof this.config.identificationCode != "string")
|
|
138
272
|
throw new Error("Pirsch requires an identificationCode");
|
|
139
273
|
try {
|
|
140
|
-
const { Pirsch:
|
|
141
|
-
this.client = new
|
|
274
|
+
const { Pirsch: i } = await import("../web-CvEQewPd.js").then((e) => e.w);
|
|
275
|
+
this.client = new i({
|
|
142
276
|
identificationCode: this.config.identificationCode,
|
|
143
277
|
...this.config.hostname && { hostname: this.config.hostname }
|
|
144
278
|
}), this.initialized = !0, this.log("Initialized successfully", this.config);
|
|
145
|
-
} catch (
|
|
279
|
+
} catch (i) {
|
|
146
280
|
throw console.error(
|
|
147
281
|
"[Pirsch-Client] Failed to initialize. Make sure pirsch-sdk is installed:",
|
|
148
|
-
|
|
149
|
-
),
|
|
282
|
+
i
|
|
283
|
+
), i;
|
|
150
284
|
}
|
|
151
285
|
}
|
|
152
286
|
}
|
|
153
|
-
identify(
|
|
287
|
+
identify(i, e) {
|
|
154
288
|
!this.isEnabled() || !this.initialized || !this.client || (this.client.event("user_identified", 0, {
|
|
155
|
-
userId:
|
|
156
|
-
...
|
|
157
|
-
}).catch((
|
|
158
|
-
console.error("[Pirsch-Client] Failed to track identify event:",
|
|
159
|
-
}), this.log("Identified user via event", { userId:
|
|
160
|
-
}
|
|
161
|
-
async track(
|
|
162
|
-
var
|
|
289
|
+
userId: i,
|
|
290
|
+
...e
|
|
291
|
+
}).catch((t) => {
|
|
292
|
+
console.error("[Pirsch-Client] Failed to track identify event:", t);
|
|
293
|
+
}), this.log("Identified user via event", { userId: i, traits: e }));
|
|
294
|
+
}
|
|
295
|
+
async track(i, e) {
|
|
296
|
+
var s, n;
|
|
163
297
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
164
|
-
const
|
|
165
|
-
...
|
|
166
|
-
category:
|
|
167
|
-
...
|
|
168
|
-
...
|
|
169
|
-
...(
|
|
170
|
-
page_path:
|
|
171
|
-
page_title:
|
|
172
|
-
page_referrer:
|
|
298
|
+
const t = {
|
|
299
|
+
...i.properties,
|
|
300
|
+
category: i.category,
|
|
301
|
+
...i.userId && { userId: i.userId },
|
|
302
|
+
...i.sessionId && { sessionId: i.sessionId },
|
|
303
|
+
...(e == null ? void 0 : e.page) && {
|
|
304
|
+
page_path: e.page.path,
|
|
305
|
+
page_title: e.page.title,
|
|
306
|
+
page_referrer: e.page.referrer
|
|
173
307
|
},
|
|
174
|
-
...(
|
|
175
|
-
...(
|
|
176
|
-
...((
|
|
177
|
-
...((n =
|
|
308
|
+
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
309
|
+
...(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 },
|
|
311
|
+
...((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) && { user_traits: e.user.traits }
|
|
178
312
|
};
|
|
179
313
|
try {
|
|
180
|
-
await this.client.event(
|
|
314
|
+
await this.client.event(i.action, 0, t), this.log("Tracked event", { event: i, context: e });
|
|
181
315
|
} catch (o) {
|
|
182
316
|
console.error("[Pirsch-Client] Failed to track event:", o);
|
|
183
317
|
}
|
|
184
318
|
}
|
|
185
|
-
pageView(
|
|
186
|
-
if (!(!this.isEnabled() || !this.initialized || !this.client || !
|
|
187
|
-
if (this.client.hit().catch((
|
|
188
|
-
console.error("[Pirsch-Client] Failed to track page view:",
|
|
189
|
-
}),
|
|
190
|
-
const
|
|
191
|
-
...
|
|
192
|
-
...(
|
|
193
|
-
path:
|
|
194
|
-
title:
|
|
195
|
-
referrer:
|
|
319
|
+
pageView(i, e) {
|
|
320
|
+
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);
|
|
323
|
+
}), i && Object.keys(i).length > 0) {
|
|
324
|
+
const t = {
|
|
325
|
+
...i,
|
|
326
|
+
...(e == null ? void 0 : e.page) && {
|
|
327
|
+
path: e.page.path,
|
|
328
|
+
title: e.page.title,
|
|
329
|
+
referrer: e.page.referrer
|
|
196
330
|
}
|
|
197
331
|
};
|
|
198
|
-
this.client.event("page_view", 0,
|
|
332
|
+
this.client.event("page_view", 0, t).catch((s) => {
|
|
199
333
|
console.error(
|
|
200
334
|
"[Pirsch-Client] Failed to track page view event:",
|
|
201
|
-
|
|
335
|
+
s
|
|
202
336
|
);
|
|
203
337
|
});
|
|
204
338
|
}
|
|
205
|
-
this.log("Tracked page view", { properties:
|
|
339
|
+
this.log("Tracked page view", { properties: i, context: e });
|
|
206
340
|
}
|
|
207
341
|
}
|
|
208
|
-
pageLeave(
|
|
209
|
-
if (!this.isEnabled() || !this.initialized || !this.client || !
|
|
342
|
+
pageLeave(i, e) {
|
|
343
|
+
if (!this.isEnabled() || !this.initialized || !this.client || !a())
|
|
210
344
|
return;
|
|
211
|
-
const
|
|
212
|
-
...
|
|
213
|
-
...(
|
|
214
|
-
path:
|
|
215
|
-
title:
|
|
345
|
+
const t = {
|
|
346
|
+
...i,
|
|
347
|
+
...(e == null ? void 0 : e.page) && {
|
|
348
|
+
path: e.page.path,
|
|
349
|
+
title: e.page.title
|
|
216
350
|
}
|
|
217
351
|
};
|
|
218
|
-
this.client.event("page_leave", 0,
|
|
219
|
-
console.error("[Pirsch-Client] Failed to track page leave:",
|
|
220
|
-
}), this.log("Tracked page leave", { properties:
|
|
352
|
+
this.client.event("page_leave", 0, t).catch((s) => {
|
|
353
|
+
console.error("[Pirsch-Client] Failed to track page leave:", s);
|
|
354
|
+
}), this.log("Tracked page leave", { properties: i, context: e });
|
|
221
355
|
}
|
|
222
356
|
reset() {
|
|
223
|
-
!this.isEnabled() || !this.initialized || !this.client || !
|
|
224
|
-
console.error("[Pirsch-Client] Failed to track session reset:",
|
|
357
|
+
!this.isEnabled() || !this.initialized || !this.client || !a() || (this.client.event("session_reset", 0, {}).catch((i) => {
|
|
358
|
+
console.error("[Pirsch-Client] Failed to track session reset:", i);
|
|
225
359
|
}), this.log("Reset user session"));
|
|
226
360
|
}
|
|
227
361
|
}
|
|
362
|
+
class y extends d {
|
|
363
|
+
constructor(i) {
|
|
364
|
+
var e, t, s, n, o;
|
|
365
|
+
super({ debug: i.debug, enabled: i.enabled });
|
|
366
|
+
r(this, "name", "Proxy");
|
|
367
|
+
r(this, "config");
|
|
368
|
+
r(this, "queue", []);
|
|
369
|
+
r(this, "flushTimer");
|
|
370
|
+
r(this, "batchSize");
|
|
371
|
+
r(this, "batchInterval");
|
|
372
|
+
r(this, "retryAttempts");
|
|
373
|
+
r(this, "retryBackoff");
|
|
374
|
+
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", () => {
|
|
376
|
+
this.flush(!0);
|
|
377
|
+
}), document.addEventListener("visibilitychange", () => {
|
|
378
|
+
document.visibilityState === "hidden" && this.flush(!0);
|
|
379
|
+
}));
|
|
380
|
+
}
|
|
381
|
+
async initialize() {
|
|
382
|
+
this.isEnabled() && this.log("Initialized successfully", { endpoint: this.config.endpoint });
|
|
383
|
+
}
|
|
384
|
+
identify(i, e) {
|
|
385
|
+
this.isEnabled() && (this.queueEvent({
|
|
386
|
+
type: "identify",
|
|
387
|
+
userId: i,
|
|
388
|
+
traits: e
|
|
389
|
+
}), this.log("Queued identify event", { userId: i, traits: e }));
|
|
390
|
+
}
|
|
391
|
+
async track(i, e) {
|
|
392
|
+
this.isEnabled() && (this.queueEvent({
|
|
393
|
+
type: "track",
|
|
394
|
+
event: i,
|
|
395
|
+
context: this.enrichContext(e)
|
|
396
|
+
}), this.log("Queued track event", { event: i, context: e }));
|
|
397
|
+
}
|
|
398
|
+
pageView(i, e) {
|
|
399
|
+
this.isEnabled() && (this.queueEvent({
|
|
400
|
+
type: "pageView",
|
|
401
|
+
properties: i,
|
|
402
|
+
context: this.enrichContext(e)
|
|
403
|
+
}), this.log("Queued page view event", { properties: i, context: e }));
|
|
404
|
+
}
|
|
405
|
+
async reset() {
|
|
406
|
+
this.isEnabled() && (this.queueEvent({
|
|
407
|
+
type: "reset"
|
|
408
|
+
}), this.log("Queued reset event"));
|
|
409
|
+
}
|
|
410
|
+
async shutdown() {
|
|
411
|
+
await this.flush(!0), this.log("Shutdown complete");
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Manually flush all queued events
|
|
415
|
+
*/
|
|
416
|
+
async flush(i = !1) {
|
|
417
|
+
if (this.queue.length === 0) return;
|
|
418
|
+
const e = [...this.queue];
|
|
419
|
+
this.queue = [], this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = void 0), await this.sendEvents(e, i);
|
|
420
|
+
}
|
|
421
|
+
queueEvent(i) {
|
|
422
|
+
if (this.queue.push(i), this.queue.length >= this.batchSize) {
|
|
423
|
+
this.flush().catch((e) => {
|
|
424
|
+
console.error("[Proxy] Failed to flush events:", e);
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
this.flushTimer || (this.flushTimer = setTimeout(() => {
|
|
429
|
+
this.flush().catch((e) => {
|
|
430
|
+
console.error("[Proxy] Failed to flush events:", e);
|
|
431
|
+
});
|
|
432
|
+
}, this.batchInterval));
|
|
433
|
+
}
|
|
434
|
+
async sendEvents(i, e = !1) {
|
|
435
|
+
const t = { events: i };
|
|
436
|
+
if (e && typeof navigator < "u" && navigator.sendBeacon) {
|
|
437
|
+
const s = new Blob([JSON.stringify(t)], {
|
|
438
|
+
type: "application/json"
|
|
439
|
+
});
|
|
440
|
+
navigator.sendBeacon(this.config.endpoint, s) || console.warn("[Proxy] Failed to send events via beacon");
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
await this.sendWithRetry(t);
|
|
444
|
+
}
|
|
445
|
+
async sendWithRetry(i, e = 0) {
|
|
446
|
+
try {
|
|
447
|
+
const t = await fetch(this.config.endpoint, {
|
|
448
|
+
method: "POST",
|
|
449
|
+
headers: {
|
|
450
|
+
"Content-Type": "application/json",
|
|
451
|
+
...this.config.headers
|
|
452
|
+
},
|
|
453
|
+
body: JSON.stringify(i),
|
|
454
|
+
// Don't include credentials by default
|
|
455
|
+
credentials: "same-origin"
|
|
456
|
+
});
|
|
457
|
+
if (!t.ok)
|
|
458
|
+
throw new Error(`HTTP ${t.status}: ${t.statusText}`);
|
|
459
|
+
this.log(`Sent ${i.events.length} events successfully`);
|
|
460
|
+
} catch (t) {
|
|
461
|
+
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);
|
|
464
|
+
}
|
|
465
|
+
throw console.error("[Proxy] Failed to send events after retries:", t), t;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
calculateRetryDelay(i) {
|
|
469
|
+
return this.retryBackoff === "exponential" ? this.retryInitialDelay * 2 ** i : this.retryInitialDelay * (i + 1);
|
|
470
|
+
}
|
|
471
|
+
enrichContext(i) {
|
|
472
|
+
return typeof window > "u" ? i || {} : {
|
|
473
|
+
...i,
|
|
474
|
+
page: {
|
|
475
|
+
path: window.location.pathname,
|
|
476
|
+
title: document.title,
|
|
477
|
+
referrer: document.referrer,
|
|
478
|
+
...i == null ? void 0 : i.page,
|
|
479
|
+
url: window.location.href
|
|
480
|
+
},
|
|
481
|
+
user: {
|
|
482
|
+
...i == null ? void 0 : i.user
|
|
483
|
+
},
|
|
484
|
+
device: {
|
|
485
|
+
...i == null ? void 0 : i.device,
|
|
486
|
+
userAgent: navigator.userAgent,
|
|
487
|
+
language: navigator.language,
|
|
488
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
489
|
+
screen: {
|
|
490
|
+
width: window.screen.width,
|
|
491
|
+
height: window.screen.height
|
|
492
|
+
},
|
|
493
|
+
viewport: {
|
|
494
|
+
width: window.innerWidth,
|
|
495
|
+
height: window.innerHeight
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
}
|
|
228
501
|
export {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
502
|
+
d as BaseAnalyticsProvider,
|
|
503
|
+
b as BentoClientProvider,
|
|
504
|
+
w as PirschClientProvider,
|
|
505
|
+
E as PostHogClientProvider,
|
|
506
|
+
y as ProxyProvider
|
|
233
507
|
};
|