@stacksee/analytics 0.11.1 → 0.13.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/adapters/client/browser-analytics.d.ts +4 -0
- package/dist/adapters/server/server-analytics.d.ts +4 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +122 -100
- package/dist/core/events/types.d.ts +73 -2
- package/dist/providers/emitkit/server.d.ts +28 -1
- package/dist/providers/server.js +130 -108
- package/dist/server.d.ts +2 -2
- package/dist/server.js +96 -74
- package/package.json +1 -1
package/dist/providers/server.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var O = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var N = (t, u, i) => u in t ? O(t, u, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[u] = i;
|
|
3
|
+
var f = (t, u, i) => N(t, typeof u != "symbol" ? u + "" : u, i);
|
|
4
4
|
import { B } from "../base.provider-AfFL5W_P.js";
|
|
5
5
|
import { P as X } from "../server-DjEk1fUD.js";
|
|
6
6
|
class H extends B {
|
|
7
7
|
constructor(i) {
|
|
8
8
|
super({ debug: i.debug, enabled: i.enabled });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
f(this, "name", "Bento-Server");
|
|
10
|
+
f(this, "client");
|
|
11
|
+
f(this, "initialized", !1);
|
|
12
|
+
f(this, "config");
|
|
13
|
+
f(this, "currentUserEmail");
|
|
14
14
|
this.config = i;
|
|
15
15
|
}
|
|
16
16
|
async initialize() {
|
|
@@ -23,8 +23,8 @@ class H extends B {
|
|
|
23
23
|
if (!((e = this.config.authentication) != null && e.secretKey) || typeof this.config.authentication.secretKey != "string")
|
|
24
24
|
throw new Error("Bento requires authentication.secretKey");
|
|
25
25
|
try {
|
|
26
|
-
const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: a, enabled: s, ...
|
|
27
|
-
this.client = new r(
|
|
26
|
+
const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: a, enabled: s, ...l } = this.config;
|
|
27
|
+
this.client = new r(l), this.initialized = !0, this.log("Initialized successfully", {
|
|
28
28
|
siteUuid: this.config.siteUuid
|
|
29
29
|
});
|
|
30
30
|
} catch (r) {
|
|
@@ -55,9 +55,9 @@ class H extends B {
|
|
|
55
55
|
}), this.log("Identified user", { userId: i, email: r, traits: e });
|
|
56
56
|
}
|
|
57
57
|
async track(i, e) {
|
|
58
|
-
var
|
|
58
|
+
var l, n, p, d;
|
|
59
59
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
60
|
-
const r = ((
|
|
60
|
+
const r = ((l = e == null ? void 0 : e.user) == null ? void 0 : l.email) || this.currentUserEmail || ((n = e == null ? void 0 : e.user) == null ? void 0 : n.userId) || i.userId;
|
|
61
61
|
if (!r || !r.includes("@")) {
|
|
62
62
|
console.warn(
|
|
63
63
|
"[Bento-Server] Skipping event - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
|
|
@@ -83,8 +83,8 @@ class H extends B {
|
|
|
83
83
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
84
84
|
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
85
85
|
site: this.config.siteUuid,
|
|
86
|
-
...((
|
|
87
|
-
}, s = ((
|
|
86
|
+
...((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) && { visitor: e.user.userId }
|
|
87
|
+
}, s = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.traits) || {};
|
|
88
88
|
try {
|
|
89
89
|
await this.client.V1.track({
|
|
90
90
|
email: r,
|
|
@@ -97,9 +97,9 @@ class H extends B {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
pageView(i, e) {
|
|
100
|
-
var
|
|
100
|
+
var l, n, p;
|
|
101
101
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
102
|
-
const r = ((
|
|
102
|
+
const r = ((l = e == null ? void 0 : e.user) == null ? void 0 : l.email) || this.currentUserEmail;
|
|
103
103
|
if (!r || !r.includes("@")) {
|
|
104
104
|
console.warn(
|
|
105
105
|
"[Bento-Server] Skipping pageView - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
|
|
@@ -121,15 +121,15 @@ class H extends B {
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
site: this.config.siteUuid,
|
|
124
|
-
...((
|
|
125
|
-
}, s = ((
|
|
124
|
+
...((n = e == null ? void 0 : e.user) == null ? void 0 : n.userId) && { visitor: e.user.userId }
|
|
125
|
+
}, s = ((p = e == null ? void 0 : e.user) == null ? void 0 : p.traits) || {};
|
|
126
126
|
this.client.V1.track({
|
|
127
127
|
email: r,
|
|
128
128
|
type: "$view",
|
|
129
129
|
details: a,
|
|
130
130
|
fields: s
|
|
131
|
-
}).catch((
|
|
132
|
-
console.error("[Bento-Server] Failed to track page view:",
|
|
131
|
+
}).catch((d) => {
|
|
132
|
+
console.error("[Bento-Server] Failed to track page view:", d);
|
|
133
133
|
}), this.log("Tracked page view", { properties: i, context: e });
|
|
134
134
|
}
|
|
135
135
|
async reset() {
|
|
@@ -142,10 +142,10 @@ class H extends B {
|
|
|
142
142
|
class W extends B {
|
|
143
143
|
constructor(i) {
|
|
144
144
|
super({ debug: i.debug, enabled: i.enabled });
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
f(this, "name", "Pirsch-Server");
|
|
146
|
+
f(this, "client");
|
|
147
|
+
f(this, "initialized", !1);
|
|
148
|
+
f(this, "config");
|
|
149
149
|
this.config = i;
|
|
150
150
|
}
|
|
151
151
|
async initialize() {
|
|
@@ -160,7 +160,7 @@ class W extends B {
|
|
|
160
160
|
"Pirsch requires a clientId when using OAuth authentication (clientSecret doesn't start with 'pa_'). Either provide a clientId or use an access key (starts with 'pa_') as clientSecret."
|
|
161
161
|
);
|
|
162
162
|
try {
|
|
163
|
-
const { Pirsch: e } = await import("../index-zS7gy63J.js").then((
|
|
163
|
+
const { Pirsch: e } = await import("../index-zS7gy63J.js").then((l) => l.i), { debug: r, enabled: a, ...s } = this.config;
|
|
164
164
|
this.client = new e(s), this.initialized = !0, this.log("Initialized successfully", {
|
|
165
165
|
hostname: this.config.hostname,
|
|
166
166
|
authMode: i ? "access-key" : "oauth"
|
|
@@ -191,9 +191,9 @@ class W extends B {
|
|
|
191
191
|
}), this.log("Identified user via event", { userId: i, traits: e });
|
|
192
192
|
}
|
|
193
193
|
async track(i, e) {
|
|
194
|
-
var h,
|
|
194
|
+
var h, g, o, c, y, m, w, b, E, I, k, _, S, z, P, U, K, A, v, $, D, j, V;
|
|
195
195
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
196
|
-
const r = e, a = ((h = r == null ? void 0 : r.device) == null ? void 0 : h.ip) || ((
|
|
196
|
+
const r = e, a = ((h = r == null ? void 0 : r.device) == null ? void 0 : h.ip) || ((g = r == null ? void 0 : r.server) == null ? void 0 : g.ip), s = ((o = r == null ? void 0 : r.server) == null ? void 0 : o.userAgent) || ((c = r == null ? void 0 : r.device) == null ? void 0 : c.userAgent);
|
|
197
197
|
if (!a || !s) {
|
|
198
198
|
this.log(
|
|
199
199
|
"Skipping event - missing required IP or user-agent from context",
|
|
@@ -205,13 +205,13 @@ class W extends B {
|
|
|
205
205
|
);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
const
|
|
208
|
+
const n = {
|
|
209
209
|
url: ((y = e == null ? void 0 : e.page) == null ? void 0 : y.url) || ((m = e == null ? void 0 : e.page) != null && m.protocol && ((w = e == null ? void 0 : e.page) != null && w.host) && ((b = e == null ? void 0 : e.page) != null && b.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (E = e == null ? void 0 : e.page) != null && E.path ? `https://${this.config.hostname}${e.page.path}` : "https://event"),
|
|
210
210
|
ip: a,
|
|
211
211
|
user_agent: s,
|
|
212
212
|
...((I = e == null ? void 0 : e.page) == null ? void 0 : I.title) && { title: e.page.title },
|
|
213
213
|
...((k = e == null ? void 0 : e.page) == null ? void 0 : k.referrer) && { referrer: e.page.referrer },
|
|
214
|
-
...((
|
|
214
|
+
...((S = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : S.width) && {
|
|
215
215
|
screen_width: e.device.screen.width
|
|
216
216
|
},
|
|
217
217
|
...((P = (z = e == null ? void 0 : e.device) == null ? void 0 : z.screen) == null ? void 0 : P.height) && {
|
|
@@ -223,11 +223,11 @@ class W extends B {
|
|
|
223
223
|
...((A = e == null ? void 0 : e.device) == null ? void 0 : A.language) && {
|
|
224
224
|
accept_language: e.device.language
|
|
225
225
|
},
|
|
226
|
-
...((
|
|
226
|
+
...((v = e == null ? void 0 : e.device) == null ? void 0 : v.type) && {
|
|
227
227
|
sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0"
|
|
228
228
|
},
|
|
229
229
|
...(($ = e == null ? void 0 : e.device) == null ? void 0 : $.os) && { sec_ch_ua_platform: e.device.os }
|
|
230
|
-
},
|
|
230
|
+
}, d = {
|
|
231
231
|
...Object.fromEntries(
|
|
232
232
|
Object.entries(i.properties).filter(
|
|
233
233
|
([, F]) => typeof F == "string" || typeof F == "number" || typeof F == "boolean"
|
|
@@ -242,15 +242,15 @@ class W extends B {
|
|
|
242
242
|
...((V = e == null ? void 0 : e.device) == null ? void 0 : V.browser) && { browser: e.device.browser }
|
|
243
243
|
};
|
|
244
244
|
try {
|
|
245
|
-
await this.client.event(i.action,
|
|
245
|
+
await this.client.event(i.action, n, 0, d), this.log("Tracked event", { event: i, context: e });
|
|
246
246
|
} catch (F) {
|
|
247
247
|
console.error("[Pirsch-Server] Failed to track event:", F);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
pageView(i, e) {
|
|
251
|
-
var
|
|
251
|
+
var p, d, h, g, o, c, y, m, w, b, E, I, k, _, S, z, P, U, K, A;
|
|
252
252
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
253
|
-
const r = e, a = ((
|
|
253
|
+
const r = e, a = ((p = r == null ? void 0 : r.device) == null ? void 0 : p.ip) || ((d = r == null ? void 0 : r.server) == null ? void 0 : d.ip), s = ((h = r == null ? void 0 : r.server) == null ? void 0 : h.userAgent) || ((g = r == null ? void 0 : r.device) == null ? void 0 : g.userAgent);
|
|
254
254
|
if (!a || !s) {
|
|
255
255
|
this.log(
|
|
256
256
|
"Skipping pageView - missing required IP or user-agent from context",
|
|
@@ -261,8 +261,8 @@ class W extends B {
|
|
|
261
261
|
);
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
-
const
|
|
265
|
-
url: ((
|
|
264
|
+
const n = {
|
|
265
|
+
url: ((o = e == null ? void 0 : e.page) == null ? void 0 : o.url) || ((c = e == null ? void 0 : e.page) != null && c.protocol && ((y = e == null ? void 0 : e.page) != null && y.host) && ((m = e == null ? void 0 : e.page) != null && m.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (w = e == null ? void 0 : e.page) != null && w.path ? `https://${this.config.hostname}${e.page.path}` : "https://pageview"),
|
|
266
266
|
ip: a,
|
|
267
267
|
user_agent: s,
|
|
268
268
|
...((b = e == null ? void 0 : e.page) == null ? void 0 : b.title) && { title: e.page.title },
|
|
@@ -270,7 +270,7 @@ class W extends B {
|
|
|
270
270
|
...((k = (I = e == null ? void 0 : e.device) == null ? void 0 : I.screen) == null ? void 0 : k.width) && {
|
|
271
271
|
screen_width: e.device.screen.width
|
|
272
272
|
},
|
|
273
|
-
...((
|
|
273
|
+
...((S = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : S.height) && {
|
|
274
274
|
screen_height: e.device.screen.height
|
|
275
275
|
},
|
|
276
276
|
...((P = (z = e == null ? void 0 : e.device) == null ? void 0 : z.viewport) == null ? void 0 : P.width) && {
|
|
@@ -286,13 +286,13 @@ class W extends B {
|
|
|
286
286
|
...i && {
|
|
287
287
|
tags: Object.fromEntries(
|
|
288
288
|
Object.entries(i).filter(
|
|
289
|
-
([,
|
|
289
|
+
([, v]) => typeof v == "string" || typeof v == "number" || typeof v == "boolean"
|
|
290
290
|
)
|
|
291
291
|
)
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
|
-
this.client.hit(
|
|
295
|
-
console.error("[Pirsch-Server] Failed to track page view:",
|
|
294
|
+
this.client.hit(n).catch((v) => {
|
|
295
|
+
console.error("[Pirsch-Server] Failed to track page view:", v);
|
|
296
296
|
}), this.log("Tracked page view", { properties: i, context: e });
|
|
297
297
|
}
|
|
298
298
|
async reset() {
|
|
@@ -313,12 +313,12 @@ class W extends B {
|
|
|
313
313
|
class G extends B {
|
|
314
314
|
constructor(i) {
|
|
315
315
|
super({ debug: i.debug, enabled: i.enabled });
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
f(this, "name", "EmitKit-Server");
|
|
317
|
+
f(this, "client");
|
|
318
|
+
f(this, "initialized", !1);
|
|
319
|
+
f(this, "config");
|
|
320
|
+
f(this, "currentUserId");
|
|
321
|
+
f(this, "currentUserEmail");
|
|
322
322
|
this.config = i;
|
|
323
323
|
}
|
|
324
324
|
async initialize() {
|
|
@@ -343,20 +343,20 @@ class G extends B {
|
|
|
343
343
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
344
344
|
this.currentUserId = i;
|
|
345
345
|
const r = (e == null ? void 0 : e.email) || i;
|
|
346
|
-
r && r.includes("@") && (this.currentUserEmail = r);
|
|
346
|
+
r != null && r.includes("@") && (this.currentUserEmail = r);
|
|
347
347
|
const a = [];
|
|
348
348
|
i && a.push(i), r && r !== i && a.push(r), e != null && e.username && typeof e.username == "string" && a.push(e.username), this.client.identify({
|
|
349
349
|
user_id: i,
|
|
350
350
|
properties: e || {},
|
|
351
351
|
aliases: a.length > 0 ? a : void 0
|
|
352
352
|
}).then((s) => {
|
|
353
|
-
var
|
|
353
|
+
var l, n, p, d, h;
|
|
354
354
|
this.log("Identified user", {
|
|
355
355
|
userId: i,
|
|
356
356
|
email: r,
|
|
357
357
|
identityId: s.data.id,
|
|
358
|
-
aliasesCreated: ((
|
|
359
|
-
aliasesFailed: ((
|
|
358
|
+
aliasesCreated: ((n = (l = s.data.aliases) == null ? void 0 : l.created) == null ? void 0 : n.length) || 0,
|
|
359
|
+
aliasesFailed: ((d = (p = s.data.aliases) == null ? void 0 : p.failed) == null ? void 0 : d.length) || 0
|
|
360
360
|
}), (h = s.data.aliases) != null && h.failed && s.data.aliases.failed.length > 0 && console.warn(
|
|
361
361
|
"[EmitKit-Server] Some aliases failed to create:",
|
|
362
362
|
s.data.aliases.failed
|
|
@@ -366,10 +366,10 @@ class G extends B {
|
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
async track(i, e) {
|
|
369
|
-
var
|
|
369
|
+
var h, g;
|
|
370
370
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
371
|
-
const r = ((
|
|
372
|
-
...
|
|
371
|
+
const r = ((h = e == null ? void 0 : e.user) == null ? void 0 : h.email) || ((g = e == null ? void 0 : e.user) == null ? void 0 : g.userId) || i.userId || this.currentUserEmail || this.currentUserId, a = this.formatEventTitle(i.action), { __emitkit_channel: s, ...l } = i.properties || {}, n = {
|
|
372
|
+
...l,
|
|
373
373
|
category: i.category,
|
|
374
374
|
timestamp: i.timestamp || Date.now(),
|
|
375
375
|
...i.sessionId && { sessionId: i.sessionId },
|
|
@@ -387,37 +387,37 @@ class G extends B {
|
|
|
387
387
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
388
388
|
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
389
389
|
...(e == null ? void 0 : e.server) && { server: e.server }
|
|
390
|
-
},
|
|
391
|
-
i.category &&
|
|
392
|
-
const
|
|
390
|
+
}, p = [];
|
|
391
|
+
i.category && p.push(i.category), l != null && l.tags && Array.isArray(l.tags) && l.tags.every((o) => typeof o == "string") && p.push(...l.tags);
|
|
392
|
+
const d = this.resolveChannelName(i);
|
|
393
393
|
try {
|
|
394
|
-
const
|
|
395
|
-
channelName:
|
|
394
|
+
const o = await this.client.events.create({
|
|
395
|
+
channelName: d,
|
|
396
396
|
title: a,
|
|
397
397
|
description: this.getEventDescription(i, e),
|
|
398
398
|
icon: this.getEventIcon(i.category),
|
|
399
|
-
tags:
|
|
400
|
-
metadata:
|
|
399
|
+
tags: p.length > 0 ? p : void 0,
|
|
400
|
+
metadata: n,
|
|
401
401
|
userId: r || null,
|
|
402
402
|
notify: this.config.notify ?? !0,
|
|
403
403
|
displayAs: this.config.displayAs || "notification",
|
|
404
404
|
source: "stacksee-analytics"
|
|
405
405
|
});
|
|
406
406
|
this.log("Tracked event", {
|
|
407
|
-
eventId:
|
|
407
|
+
eventId: o.data.id,
|
|
408
408
|
action: i.action,
|
|
409
409
|
userId: r,
|
|
410
|
-
channelName:
|
|
410
|
+
channelName: d
|
|
411
411
|
});
|
|
412
|
-
} catch (
|
|
413
|
-
throw console.error("[EmitKit-Server] Failed to track event:",
|
|
412
|
+
} catch (o) {
|
|
413
|
+
throw console.error("[EmitKit-Server] Failed to track event:", o), o;
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
pageView(i, e) {
|
|
417
|
-
var d,
|
|
417
|
+
var d, h, g;
|
|
418
418
|
if (!this.isEnabled() || !this.initialized || !this.client) return;
|
|
419
|
-
const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || ((
|
|
420
|
-
...
|
|
419
|
+
const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || ((h = e == null ? void 0 : e.user) == null ? void 0 : h.userId) || this.currentUserEmail || this.currentUserId, { __emitkit_channel: a, ...s } = i || {}, l = {
|
|
420
|
+
...s,
|
|
421
421
|
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
422
422
|
...(e == null ? void 0 : e.page) && {
|
|
423
423
|
page: {
|
|
@@ -433,28 +433,33 @@ class G extends B {
|
|
|
433
433
|
...(e == null ? void 0 : e.device) && { device: e.device },
|
|
434
434
|
...(e == null ? void 0 : e.utm) && { utm: e.utm },
|
|
435
435
|
...(e == null ? void 0 : e.server) && { server: e.server }
|
|
436
|
-
},
|
|
436
|
+
}, n = {
|
|
437
|
+
action: "page_view",
|
|
438
|
+
category: "navigation",
|
|
439
|
+
properties: i || {}
|
|
440
|
+
}, p = this.resolveChannelName(n);
|
|
437
441
|
this.client.events.create({
|
|
438
|
-
channelName:
|
|
442
|
+
channelName: p,
|
|
439
443
|
title: "Page View",
|
|
440
|
-
description: ((
|
|
444
|
+
description: ((g = e == null ? void 0 : e.page) == null ? void 0 : g.path) || "User viewed a page",
|
|
441
445
|
icon: "👁️",
|
|
442
446
|
tags: ["page_view", "navigation"],
|
|
443
|
-
metadata:
|
|
447
|
+
metadata: l,
|
|
444
448
|
userId: r || null,
|
|
445
449
|
notify: !1,
|
|
446
450
|
// Don't notify for page views by default
|
|
447
451
|
displayAs: "message",
|
|
448
452
|
source: "stacksee-analytics"
|
|
449
|
-
}).then((
|
|
450
|
-
var
|
|
453
|
+
}).then((o) => {
|
|
454
|
+
var c;
|
|
451
455
|
this.log("Tracked page view", {
|
|
452
|
-
eventId:
|
|
453
|
-
path: (
|
|
454
|
-
userId: r
|
|
456
|
+
eventId: o.data.id,
|
|
457
|
+
path: (c = e == null ? void 0 : e.page) == null ? void 0 : c.path,
|
|
458
|
+
userId: r,
|
|
459
|
+
channelName: p
|
|
455
460
|
});
|
|
456
|
-
}).catch((
|
|
457
|
-
console.error("[EmitKit-Server] Failed to track page view:",
|
|
461
|
+
}).catch((o) => {
|
|
462
|
+
console.error("[EmitKit-Server] Failed to track page view:", o);
|
|
458
463
|
});
|
|
459
464
|
}
|
|
460
465
|
async reset() {
|
|
@@ -500,63 +505,80 @@ class G extends B {
|
|
|
500
505
|
conversion: "💰"
|
|
501
506
|
}[i];
|
|
502
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Resolve the channel name for an event based on priority:
|
|
510
|
+
* 1. Event property __emitkit_channel (highest priority)
|
|
511
|
+
* 2. Category mapping via categoryChannelMap
|
|
512
|
+
* 3. Default channelName (fallback, default: 'general')
|
|
513
|
+
*/
|
|
514
|
+
resolveChannelName(i, e) {
|
|
515
|
+
var r;
|
|
516
|
+
if ((r = i.properties) != null && r.__emitkit_channel && typeof i.properties.__emitkit_channel == "string")
|
|
517
|
+
return i.properties.__emitkit_channel;
|
|
518
|
+
if (this.config.categoryChannelMap && i.category) {
|
|
519
|
+
const a = this.config.categoryChannelMap[i.category];
|
|
520
|
+
if (a)
|
|
521
|
+
return a;
|
|
522
|
+
}
|
|
523
|
+
return e || this.config.channelName || "general";
|
|
524
|
+
}
|
|
503
525
|
}
|
|
504
|
-
async function
|
|
526
|
+
async function q(t, u, i) {
|
|
505
527
|
var e, r, a, s;
|
|
506
528
|
try {
|
|
507
|
-
const
|
|
508
|
-
if (!
|
|
529
|
+
const l = await t.json();
|
|
530
|
+
if (!l.events || !Array.isArray(l.events))
|
|
509
531
|
throw new Error("Invalid payload: missing events array");
|
|
510
|
-
const
|
|
511
|
-
for (const h of
|
|
532
|
+
const n = i != null && i.extractIp ? i.extractIp(t) : T(t), p = t.headers.get("user-agent"), d = i != null && i.enrichContext ? i.enrichContext(t) : {};
|
|
533
|
+
for (const h of l.events)
|
|
512
534
|
try {
|
|
513
535
|
switch (h.type) {
|
|
514
536
|
case "track": {
|
|
515
|
-
const
|
|
537
|
+
const g = {
|
|
516
538
|
...h.context,
|
|
517
|
-
...
|
|
539
|
+
...d,
|
|
518
540
|
server: {
|
|
519
541
|
...(e = h.context) == null ? void 0 : e.server,
|
|
520
|
-
...typeof (
|
|
521
|
-
...
|
|
542
|
+
...typeof (d == null ? void 0 : d.server) == "object" && d.server !== null ? d.server : {},
|
|
543
|
+
...p ? { userAgent: p } : {}
|
|
522
544
|
},
|
|
523
545
|
device: {
|
|
524
546
|
...(r = h.context) == null ? void 0 : r.device,
|
|
525
|
-
...
|
|
547
|
+
...n ? { ip: n } : {}
|
|
526
548
|
}
|
|
527
549
|
};
|
|
528
|
-
await
|
|
550
|
+
await u.track(
|
|
529
551
|
h.event.action,
|
|
530
552
|
// biome-ignore lint/suspicious/noExplicitAny: Properties from JSON cannot be type-checked against TEventMap at compile time
|
|
531
553
|
h.event.properties,
|
|
532
554
|
{
|
|
533
555
|
userId: h.event.userId,
|
|
534
556
|
sessionId: h.event.sessionId,
|
|
535
|
-
context:
|
|
557
|
+
context: g
|
|
536
558
|
}
|
|
537
559
|
);
|
|
538
560
|
break;
|
|
539
561
|
}
|
|
540
562
|
case "identify": {
|
|
541
|
-
|
|
563
|
+
u.identify(h.userId, h.traits);
|
|
542
564
|
break;
|
|
543
565
|
}
|
|
544
566
|
case "pageView": {
|
|
545
|
-
const
|
|
567
|
+
const g = {
|
|
546
568
|
...h.context,
|
|
547
|
-
...
|
|
569
|
+
...d,
|
|
548
570
|
server: {
|
|
549
571
|
...(a = h.context) == null ? void 0 : a.server,
|
|
550
|
-
...typeof (
|
|
551
|
-
...
|
|
572
|
+
...typeof (d == null ? void 0 : d.server) == "object" && d.server !== null ? d.server : {},
|
|
573
|
+
...p ? { userAgent: p } : {}
|
|
552
574
|
},
|
|
553
575
|
device: {
|
|
554
576
|
...(s = h.context) == null ? void 0 : s.device,
|
|
555
|
-
...
|
|
577
|
+
...n ? { ip: n } : {}
|
|
556
578
|
}
|
|
557
579
|
};
|
|
558
|
-
|
|
559
|
-
context:
|
|
580
|
+
u.pageView(h.properties, {
|
|
581
|
+
context: g
|
|
560
582
|
});
|
|
561
583
|
break;
|
|
562
584
|
}
|
|
@@ -565,16 +587,16 @@ async function T(g, t, i) {
|
|
|
565
587
|
default:
|
|
566
588
|
console.warn("[Proxy] Unknown event type:", h);
|
|
567
589
|
}
|
|
568
|
-
} catch (
|
|
569
|
-
i != null && i.onError ? i.onError(
|
|
590
|
+
} catch (g) {
|
|
591
|
+
i != null && i.onError ? i.onError(g) : console.error("[Proxy] Failed to process event:", g);
|
|
570
592
|
}
|
|
571
|
-
} catch (
|
|
572
|
-
throw i != null && i.onError ? i.onError(
|
|
593
|
+
} catch (l) {
|
|
594
|
+
throw i != null && i.onError ? i.onError(l) : console.error("[Proxy] Failed to ingest events:", l), l;
|
|
573
595
|
}
|
|
574
596
|
}
|
|
575
|
-
function
|
|
597
|
+
function T(t) {
|
|
576
598
|
var i;
|
|
577
|
-
const
|
|
599
|
+
const u = [
|
|
578
600
|
"x-forwarded-for",
|
|
579
601
|
"x-real-ip",
|
|
580
602
|
"cf-connecting-ip",
|
|
@@ -582,16 +604,16 @@ function N(g) {
|
|
|
582
604
|
"x-client-ip",
|
|
583
605
|
"x-cluster-client-ip"
|
|
584
606
|
];
|
|
585
|
-
for (const e of
|
|
586
|
-
const r =
|
|
607
|
+
for (const e of u) {
|
|
608
|
+
const r = t.headers.get(e);
|
|
587
609
|
if (r)
|
|
588
610
|
return (i = r.split(",")[0]) == null ? void 0 : i.trim();
|
|
589
611
|
}
|
|
590
612
|
}
|
|
591
|
-
function J(
|
|
613
|
+
function J(t, u) {
|
|
592
614
|
return async (i) => {
|
|
593
615
|
try {
|
|
594
|
-
return await
|
|
616
|
+
return await q(i, t, u), new Response("OK", { status: 200 });
|
|
595
617
|
} catch (e) {
|
|
596
618
|
return console.error("[Proxy] Handler error:", e), new Response("Internal Server Error", { status: 500 });
|
|
597
619
|
}
|
|
@@ -604,5 +626,5 @@ export {
|
|
|
604
626
|
W as PirschServerProvider,
|
|
605
627
|
X as PostHogServerProvider,
|
|
606
628
|
J as createProxyHandler,
|
|
607
|
-
|
|
629
|
+
q as ingestProxyEvents
|
|
608
630
|
};
|
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ServerAnalytics } from './adapters/server/server-analytics.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderConfigOrProvider } from './core/events/types.js';
|
|
3
3
|
import { EventMapFromCollection } from './core/events/index.js';
|
|
4
4
|
export interface ServerAnalyticsConfig {
|
|
5
|
-
providers?:
|
|
5
|
+
providers?: ProviderConfigOrProvider[];
|
|
6
6
|
debug?: boolean;
|
|
7
7
|
enabled?: boolean;
|
|
8
8
|
}
|