@koolbase/core 10.2.0 → 10.3.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.
@@ -4,13 +4,27 @@ export declare class KoolbaseAnalytics {
4
4
  private queue;
5
5
  private deviceId;
6
6
  private userId?;
7
+ private getSignedInUser?;
7
8
  private environmentId?;
8
9
  private userProperties;
9
10
  private sessionId;
10
11
  private appVersion;
11
12
  private flushTimer?;
12
13
  private initialized;
13
- constructor(config: KoolbaseConfig);
14
+ /**
15
+ * getSignedInUser lets events carry the signed-in user without the app
16
+ * having to say so.
17
+ *
18
+ * identify() existed and nothing errored when an app never called it, so
19
+ * every event landed anonymous and retention, funnels and per-user
20
+ * analysis were quietly worthless — found in a real project as 53 events,
21
+ * 8 registered users and not one event carrying a user id. The Flutter SDK
22
+ * fixed this in 11.2.0; the TypeScript SDKs kept the bug until now.
23
+ *
24
+ * identify() still wins, for an app with its own identity system, and
25
+ * reset() releases that override.
26
+ */
27
+ constructor(config: KoolbaseConfig, getSignedInUser?: () => string | null);
14
28
  init(appVersion?: string): Promise<void>;
15
29
  track(eventName: string, properties?: Record<string, unknown>): void;
16
30
  screenView(screenName: string, properties?: Record<string, unknown>): void;
@@ -9,7 +9,20 @@ const DEVICE_ID_KEY = 'koolbase:device_id';
9
9
  const FLUSH_INTERVAL_MS = 30000;
10
10
  const MAX_BATCH_SIZE = 20;
11
11
  class KoolbaseAnalytics {
12
- constructor(config) {
12
+ /**
13
+ * getSignedInUser lets events carry the signed-in user without the app
14
+ * having to say so.
15
+ *
16
+ * identify() existed and nothing errored when an app never called it, so
17
+ * every event landed anonymous and retention, funnels and per-user
18
+ * analysis were quietly worthless — found in a real project as 53 events,
19
+ * 8 registered users and not one event carrying a user id. The Flutter SDK
20
+ * fixed this in 11.2.0; the TypeScript SDKs kept the bug until now.
21
+ *
22
+ * identify() still wins, for an app with its own identity system, and
23
+ * reset() releases that override.
24
+ */
25
+ constructor(config, getSignedInUser) {
13
26
  this.queue = [];
14
27
  this.deviceId = '';
15
28
  this.userProperties = {};
@@ -17,6 +30,7 @@ class KoolbaseAnalytics {
17
30
  this.appVersion = '1.0.0';
18
31
  this.initialized = false;
19
32
  this.config = config;
33
+ this.getSignedInUser = getSignedInUser;
20
34
  }
21
35
  // ─── Init ─────────────────────────────────────────────────────────────────
22
36
  async init(appVersion) {
@@ -42,7 +56,8 @@ class KoolbaseAnalytics {
42
56
  track(eventName, properties) {
43
57
  const event = {
44
58
  device_id: this.deviceId,
45
- user_id: this.userId,
59
+ // The explicit override first, then whoever is signed in.
60
+ user_id: this.userId ?? this.getSignedInUser?.() ?? undefined,
46
61
  environment_id: this.environmentId,
47
62
  event_name: eventName,
48
63
  properties: properties ?? {},
@@ -4,13 +4,27 @@ export declare class KoolbaseAnalytics {
4
4
  private queue;
5
5
  private deviceId;
6
6
  private userId?;
7
+ private getSignedInUser?;
7
8
  private environmentId?;
8
9
  private userProperties;
9
10
  private sessionId;
10
11
  private appVersion;
11
12
  private flushTimer?;
12
13
  private initialized;
13
- constructor(config: KoolbaseConfig);
14
+ /**
15
+ * getSignedInUser lets events carry the signed-in user without the app
16
+ * having to say so.
17
+ *
18
+ * identify() existed and nothing errored when an app never called it, so
19
+ * every event landed anonymous and retention, funnels and per-user
20
+ * analysis were quietly worthless — found in a real project as 53 events,
21
+ * 8 registered users and not one event carrying a user id. The Flutter SDK
22
+ * fixed this in 11.2.0; the TypeScript SDKs kept the bug until now.
23
+ *
24
+ * identify() still wins, for an app with its own identity system, and
25
+ * reset() releases that override.
26
+ */
27
+ constructor(config: KoolbaseConfig, getSignedInUser?: () => string | null);
14
28
  init(appVersion?: string): Promise<void>;
15
29
  track(eventName: string, properties?: Record<string, unknown>): void;
16
30
  screenView(screenName: string, properties?: Record<string, unknown>): void;
@@ -6,7 +6,20 @@ const DEVICE_ID_KEY = 'koolbase:device_id';
6
6
  const FLUSH_INTERVAL_MS = 30000;
7
7
  const MAX_BATCH_SIZE = 20;
8
8
  export class KoolbaseAnalytics {
9
- constructor(config) {
9
+ /**
10
+ * getSignedInUser lets events carry the signed-in user without the app
11
+ * having to say so.
12
+ *
13
+ * identify() existed and nothing errored when an app never called it, so
14
+ * every event landed anonymous and retention, funnels and per-user
15
+ * analysis were quietly worthless — found in a real project as 53 events,
16
+ * 8 registered users and not one event carrying a user id. The Flutter SDK
17
+ * fixed this in 11.2.0; the TypeScript SDKs kept the bug until now.
18
+ *
19
+ * identify() still wins, for an app with its own identity system, and
20
+ * reset() releases that override.
21
+ */
22
+ constructor(config, getSignedInUser) {
10
23
  this.queue = [];
11
24
  this.deviceId = '';
12
25
  this.userProperties = {};
@@ -14,6 +27,7 @@ export class KoolbaseAnalytics {
14
27
  this.appVersion = '1.0.0';
15
28
  this.initialized = false;
16
29
  this.config = config;
30
+ this.getSignedInUser = getSignedInUser;
17
31
  }
18
32
  // ─── Init ─────────────────────────────────────────────────────────────────
19
33
  async init(appVersion) {
@@ -39,7 +53,8 @@ export class KoolbaseAnalytics {
39
53
  track(eventName, properties) {
40
54
  const event = {
41
55
  device_id: this.deviceId,
42
- user_id: this.userId,
56
+ // The explicit override first, then whoever is signed in.
57
+ user_id: this.userId ?? this.getSignedInUser?.() ?? undefined,
43
58
  environment_id: this.environmentId,
44
59
  event_name: eventName,
45
60
  properties: properties ?? {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",