@trakoo/emitkit 1.0.0 → 1.1.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/README.md CHANGED
@@ -32,6 +32,8 @@ export const serverAnalytics = createServerAnalytics({
32
32
  });
33
33
  ```
34
34
 
35
+ Set `__emitkit_channel` or a boolean `__emitkit_notify` in an event's properties to send that event to another channel or to turn its push notification on or off. The provider strips both before sending.
36
+
35
37
  EmitKit is server-only. To send browser events to it, forward them through trakoo's [Proxy provider](https://trakoo.co/docs/providers/proxy).
36
38
 
37
39
  The provider also sends page views, as silent events. EmitKit allows 100 requests per minute per API key by default, so if you only want explicit events in your feeds, register it as `{ provider: new EmitKitServerProvider({ ... }), exclude: ['pageView'] }`.
package/dist/server.d.ts CHANGED
@@ -39,7 +39,8 @@ export interface EmitKitServerConfig {
39
39
  */
40
40
  categoryChannelMap?: Record<string, string>;
41
41
  /**
42
- * Send notification for events
42
+ * Send a push notification for events. An event overrides it with a boolean
43
+ * `__emitkit_notify` property.
43
44
  * @default true
44
45
  */
45
46
  notify?: boolean;
package/dist/server.js CHANGED
@@ -81,8 +81,8 @@ export class EmitKitServerProvider extends BaseAnalyticsProvider {
81
81
  // Generate event title from action (convert snake_case to Title Case)
82
82
  const title = this.formatEventTitle(event.action);
83
83
  // Build metadata from event properties and context
84
- // Strip __emitkit_channel from properties as it's internal routing metadata
85
- const { __emitkit_channel, ...cleanProperties } = event.properties || {};
84
+ // Strip the __emitkit_* hints from properties: they are delivery settings
85
+ const { __emitkit_channel, __emitkit_notify, ...cleanProperties } = event.properties || {};
86
86
  const metadata = {
87
87
  ...cleanProperties,
88
88
  category: event.category,
@@ -113,7 +113,7 @@ export class EmitKitServerProvider extends BaseAnalyticsProvider {
113
113
  tags: uniqueTags.length > 0 ? uniqueTags : undefined,
114
114
  metadata: asJsonObject(metadata),
115
115
  userId: userId || null,
116
- notify: this.config.notify ?? true,
116
+ notify: notifyHint(__emitkit_notify, this.config.notify ?? true),
117
117
  displayAs: this.config.displayAs || "notification",
118
118
  source: EVENT_SOURCE,
119
119
  });
@@ -129,8 +129,8 @@ export class EmitKitServerProvider extends BaseAnalyticsProvider {
129
129
  return;
130
130
  // Page views may only use identity supplied in the current context.
131
131
  const userId = context?.user?.email || context?.user?.userId;
132
- // Strip __emitkit_channel from properties if present
133
- const { __emitkit_channel, ...cleanProperties } = properties || {};
132
+ // Strip the __emitkit_* hints from properties if present
133
+ const { __emitkit_channel, __emitkit_notify, ...cleanProperties } = properties || {};
134
134
  // Build page view metadata
135
135
  const metadata = {
136
136
  ...cleanProperties,
@@ -155,7 +155,8 @@ export class EmitKitServerProvider extends BaseAnalyticsProvider {
155
155
  tags: ["page_view", "navigation"],
156
156
  metadata: asJsonObject(metadata),
157
157
  userId: userId || null,
158
- notify: false, // Don't notify for page views by default
158
+ // Page views are silent unless the page view asks otherwise
159
+ notify: notifyHint(__emitkit_notify, false),
159
160
  displayAs: "message",
160
161
  source: EVENT_SOURCE,
161
162
  });
@@ -301,6 +302,10 @@ export class EmitKitServerProvider extends BaseAnalyticsProvider {
301
302
  return defaultChannel || this.config.channelName || "general";
302
303
  }
303
304
  }
305
+ /** A boolean `__emitkit_notify` hint, or `fallback` when there is none. */
306
+ function notifyHint(hint, fallback) {
307
+ return typeof hint === "boolean" ? hint : fallback;
308
+ }
304
309
  /**
305
310
  * The SDK types metadata and properties as JSON values and serializes them
306
311
  * with `JSON.stringify`, so trakoo's properties pass through unchanged.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trakoo/emitkit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "EmitKit provider for trakoo",
5
5
  "type": "module",
6
6
  "exports": {
@@ -41,11 +41,11 @@
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@emitkit/js": "^3.0.0",
44
- "trakoo": "^2.0.0"
44
+ "trakoo": "^2.1.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@emitkit/js": "^3.0.0",
48
- "trakoo": "2.0.0"
48
+ "trakoo": "2.1.0"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsc -p tsconfig.build.json",