@speechos/core 0.2.2 → 0.2.4

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/config.d.cts CHANGED
@@ -39,4 +39,14 @@ export declare function resetConfig(): void;
39
39
  * @param userId - The user identifier to set
40
40
  */
41
41
  export declare function updateUserId(userId: string): void;
42
+ /**
43
+ * Get or generate a persistent anonymous ID for Mixpanel tracking.
44
+ *
45
+ * This ID is stored in localStorage to persist across sessions,
46
+ * allowing consistent anonymous user tracking without identifying
47
+ * the account owner's customers.
48
+ *
49
+ * @returns A UUID string for anonymous identification
50
+ */
51
+ export declare function getAnonymousId(): string;
42
52
  export {};
package/dist/config.d.ts CHANGED
@@ -39,4 +39,14 @@ export declare function resetConfig(): void;
39
39
  * @param userId - The user identifier to set
40
40
  */
41
41
  export declare function updateUserId(userId: string): void;
42
+ /**
43
+ * Get or generate a persistent anonymous ID for Mixpanel tracking.
44
+ *
45
+ * This ID is stored in localStorage to persist across sessions,
46
+ * allowing consistent anonymous user tracking without identifying
47
+ * the account owner's customers.
48
+ *
49
+ * @returns A UUID string for anonymous identification
50
+ */
51
+ export declare function getAnonymousId(): string;
42
52
  export {};
package/dist/index.cjs CHANGED
@@ -84,6 +84,28 @@ function updateUserId(userId) {
84
84
  userId
85
85
  };
86
86
  }
87
+ /**
88
+ * LocalStorage key for anonymous ID persistence
89
+ */
90
+ const ANONYMOUS_ID_KEY = "speechos_anonymous_id";
91
+ /**
92
+ * Get or generate a persistent anonymous ID for Mixpanel tracking.
93
+ *
94
+ * This ID is stored in localStorage to persist across sessions,
95
+ * allowing consistent anonymous user tracking without identifying
96
+ * the account owner's customers.
97
+ *
98
+ * @returns A UUID string for anonymous identification
99
+ */
100
+ function getAnonymousId() {
101
+ if (typeof localStorage === "undefined") return crypto.randomUUID();
102
+ let anonymousId = localStorage.getItem(ANONYMOUS_ID_KEY);
103
+ if (!anonymousId) {
104
+ anonymousId = crypto.randomUUID();
105
+ localStorage.setItem(ANONYMOUS_ID_KEY, anonymousId);
106
+ }
107
+ return anonymousId;
108
+ }
87
109
 
88
110
  //#endregion
89
111
  //#region src/events.ts
@@ -1550,10 +1572,12 @@ var WebSocketManager = class {
1550
1572
  const config = getConfig();
1551
1573
  const audioFormat = getSupportedAudioFormat();
1552
1574
  const settings = this.sessionSettings;
1575
+ const anonymousId = getAnonymousId();
1553
1576
  const authMessage = {
1554
1577
  type: MESSAGE_TYPE_AUTH,
1555
1578
  api_key: config.apiKey,
1556
1579
  user_id: config.userId || null,
1580
+ anonymous_id: anonymousId,
1557
1581
  input_language: settings.inputLanguageCode ?? "en-US",
1558
1582
  output_language: settings.outputLanguageCode ?? "en-US",
1559
1583
  smart_format: settings.smartFormat ?? true,