@stacksee/analytics 0.12.0 → 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.
@@ -10,9 +10,29 @@ export interface EmitKitServerConfig {
10
10
  apiKey: string;
11
11
  /**
12
12
  * Default channel name for events
13
- * @default 'analytics'
13
+ * @default 'general'
14
14
  */
15
15
  channelName?: string;
16
+ /**
17
+ * Map event categories to specific EmitKit channels.
18
+ * Allows automatic routing of events to appropriate channels based on category.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * {
23
+ * 'user': 'user-activity',
24
+ * 'engagement': 'product-usage',
25
+ * 'error': 'alerts',
26
+ * 'conversion': 'revenue'
27
+ * }
28
+ * ```
29
+ *
30
+ * Channel resolution priority:
31
+ * 1. Event property `__emitkit_channel` (highest priority)
32
+ * 2. Category mapping via `categoryChannelMap`
33
+ * 3. Default `channelName` (fallback, default: 'general')
34
+ */
35
+ categoryChannelMap?: Record<string, string>;
16
36
  /**
17
37
  * Send notification for events
18
38
  * @default true
@@ -59,4 +79,11 @@ export declare class EmitKitServerProvider extends BaseAnalyticsProvider {
59
79
  * Get an appropriate icon for the event category
60
80
  */
61
81
  private getEventIcon;
82
+ /**
83
+ * Resolve the channel name for an event based on priority:
84
+ * 1. Event property __emitkit_channel (highest priority)
85
+ * 2. Category mapping via categoryChannelMap
86
+ * 3. Default channelName (fallback, default: 'general')
87
+ */
88
+ private resolveChannelName;
62
89
  }
@@ -1,16 +1,16 @@
1
1
  var O = Object.defineProperty;
2
- var q = (g, t, i) => t in g ? O(g, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : g[t] = i;
3
- var o = (g, t, i) => q(g, typeof t != "symbol" ? t + "" : t, i);
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
- o(this, "name", "Bento-Server");
10
- o(this, "client");
11
- o(this, "initialized", !1);
12
- o(this, "config");
13
- o(this, "currentUserEmail");
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, ...d } = this.config;
27
- this.client = new r(d), this.initialized = !0, this.log("Initialized successfully", {
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 d, p, u, l;
58
+ var l, n, p, d;
59
59
  if (!this.isEnabled() || !this.initialized || !this.client) return;
60
- const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail || ((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) || i.userId;
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
- ...((u = e == null ? void 0 : e.user) == null ? void 0 : u.userId) && { visitor: e.user.userId }
87
- }, s = ((l = e == null ? void 0 : e.user) == null ? void 0 : l.traits) || {};
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 d, p, u;
100
+ var l, n, p;
101
101
  if (!this.isEnabled() || !this.initialized || !this.client) return;
102
- const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail;
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
- ...((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) && { visitor: e.user.userId }
125
- }, s = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.traits) || {};
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((l) => {
132
- console.error("[Bento-Server] Failed to track page view:", l);
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
- o(this, "name", "Pirsch-Server");
146
- o(this, "client");
147
- o(this, "initialized", !1);
148
- o(this, "config");
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((d) => d.i), { debug: r, enabled: a, ...s } = this.config;
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, n, c, v, y, m, w, b, E, I, k, S, _, z, P, U, K, A, f, $, D, j, V;
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) || ((n = r == null ? void 0 : r.server) == null ? void 0 : n.ip), s = ((c = r == null ? void 0 : r.server) == null ? void 0 : c.userAgent) || ((v = r == null ? void 0 : r.device) == null ? void 0 : v.userAgent);
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 p = {
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
- ...((_ = (S = e == null ? void 0 : e.device) == null ? void 0 : S.screen) == null ? void 0 : _.width) && {
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
- ...((f = e == null ? void 0 : e.device) == null ? void 0 : f.type) && {
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
- }, l = {
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, p, 0, l), this.log("Tracked event", { event: i, context: e });
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 u, l, h, n, c, v, y, m, w, b, E, I, k, S, _, z, P, U, K, A;
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 = ((u = r == null ? void 0 : r.device) == null ? void 0 : u.ip) || ((l = r == null ? void 0 : r.server) == null ? void 0 : l.ip), s = ((h = r == null ? void 0 : r.server) == null ? void 0 : h.userAgent) || ((n = r == null ? void 0 : r.device) == null ? void 0 : n.userAgent);
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 p = {
265
- url: ((c = e == null ? void 0 : e.page) == null ? void 0 : c.url) || ((v = e == null ? void 0 : e.page) != null && v.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"),
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
- ...((_ = (S = e == null ? void 0 : e.device) == null ? void 0 : S.screen) == null ? void 0 : _.height) && {
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
- ([, f]) => typeof f == "string" || typeof f == "number" || typeof f == "boolean"
289
+ ([, v]) => typeof v == "string" || typeof v == "number" || typeof v == "boolean"
290
290
  )
291
291
  )
292
292
  }
293
293
  };
294
- this.client.hit(p).catch((f) => {
295
- console.error("[Pirsch-Server] Failed to track page view:", f);
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
- o(this, "name", "EmitKit-Server");
317
- o(this, "client");
318
- o(this, "initialized", !1);
319
- o(this, "config");
320
- o(this, "currentUserId");
321
- o(this, "currentUserEmail");
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 d, p, u, l, h;
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: ((p = (d = s.data.aliases) == null ? void 0 : d.created) == null ? void 0 : p.length) || 0,
359
- aliasesFailed: ((l = (u = s.data.aliases) == null ? void 0 : u.failed) == null ? void 0 : l.length) || 0
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 u, l, h;
369
+ var h, g;
370
370
  if (!this.isEnabled() || !this.initialized || !this.client) return;
371
- const r = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) || ((l = e == null ? void 0 : e.user) == null ? void 0 : l.userId) || i.userId || this.currentUserEmail || this.currentUserId, a = this.formatEventTitle(i.action), s = {
372
- ...i.properties,
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
- }, d = [];
391
- i.category && d.push(i.category), (h = i.properties) != null && h.tags && Array.isArray(i.properties.tags) && i.properties.tags.every((n) => typeof n == "string") && d.push(...i.properties.tags);
392
- const p = this.config.channelName || "analytics";
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 n = await this.client.events.create({
395
- channelName: p,
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: d.length > 0 ? d : void 0,
400
- metadata: s,
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: n.data.id,
407
+ eventId: o.data.id,
408
408
  action: i.action,
409
409
  userId: r,
410
- channelName: p
410
+ channelName: d
411
411
  });
412
- } catch (n) {
413
- throw console.error("[EmitKit-Server] Failed to track event:", n), n;
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, p, u;
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) || ((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) || this.currentUserEmail || this.currentUserId, a = {
420
- ...i,
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
- }, s = this.config.channelName || "analytics";
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: s,
442
+ channelName: p,
439
443
  title: "Page View",
440
- description: ((u = e == null ? void 0 : e.page) == null ? void 0 : u.path) || "User viewed a page",
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: a,
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((l) => {
450
- var h;
453
+ }).then((o) => {
454
+ var c;
451
455
  this.log("Tracked page view", {
452
- eventId: l.data.id,
453
- path: (h = e == null ? void 0 : e.page) == null ? void 0 : h.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((l) => {
457
- console.error("[EmitKit-Server] Failed to track page view:", l);
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 T(g, t, i) {
526
+ async function q(t, u, i) {
505
527
  var e, r, a, s;
506
528
  try {
507
- const d = await g.json();
508
- if (!d.events || !Array.isArray(d.events))
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 p = i != null && i.extractIp ? i.extractIp(g) : N(g), u = g.headers.get("user-agent"), l = i != null && i.enrichContext ? i.enrichContext(g) : {};
511
- for (const h of d.events)
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 n = {
537
+ const g = {
516
538
  ...h.context,
517
- ...l,
539
+ ...d,
518
540
  server: {
519
541
  ...(e = h.context) == null ? void 0 : e.server,
520
- ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
521
- ...u ? { userAgent: u } : {}
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
- ...p ? { ip: p } : {}
547
+ ...n ? { ip: n } : {}
526
548
  }
527
549
  };
528
- await t.track(
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: n
557
+ context: g
536
558
  }
537
559
  );
538
560
  break;
539
561
  }
540
562
  case "identify": {
541
- t.identify(h.userId, h.traits);
563
+ u.identify(h.userId, h.traits);
542
564
  break;
543
565
  }
544
566
  case "pageView": {
545
- const n = {
567
+ const g = {
546
568
  ...h.context,
547
- ...l,
569
+ ...d,
548
570
  server: {
549
571
  ...(a = h.context) == null ? void 0 : a.server,
550
- ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
551
- ...u ? { userAgent: u } : {}
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
- ...p ? { ip: p } : {}
577
+ ...n ? { ip: n } : {}
556
578
  }
557
579
  };
558
- t.pageView(h.properties, {
559
- context: n
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 (n) {
569
- i != null && i.onError ? i.onError(n) : console.error("[Proxy] Failed to process event:", n);
590
+ } catch (g) {
591
+ i != null && i.onError ? i.onError(g) : console.error("[Proxy] Failed to process event:", g);
570
592
  }
571
- } catch (d) {
572
- throw i != null && i.onError ? i.onError(d) : console.error("[Proxy] Failed to ingest events:", d), d;
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 N(g) {
597
+ function T(t) {
576
598
  var i;
577
- const t = [
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 t) {
586
- const r = g.headers.get(e);
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(g, t) {
613
+ function J(t, u) {
592
614
  return async (i) => {
593
615
  try {
594
- return await T(i, g, t), new Response("OK", { status: 200 });
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
- T as ingestProxyEvents
629
+ q as ingestProxyEvents
608
630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacksee/analytics",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "A highly typed, provider-agnostic analytics library for TypeScript applications",
5
5
  "type": "module",
6
6
  "exports": {