@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/index.js CHANGED
@@ -61,6 +61,28 @@ function updateUserId(userId) {
61
61
  userId
62
62
  };
63
63
  }
64
+ /**
65
+ * LocalStorage key for anonymous ID persistence
66
+ */
67
+ const ANONYMOUS_ID_KEY = "speechos_anonymous_id";
68
+ /**
69
+ * Get or generate a persistent anonymous ID for Mixpanel tracking.
70
+ *
71
+ * This ID is stored in localStorage to persist across sessions,
72
+ * allowing consistent anonymous user tracking without identifying
73
+ * the account owner's customers.
74
+ *
75
+ * @returns A UUID string for anonymous identification
76
+ */
77
+ function getAnonymousId() {
78
+ if (typeof localStorage === "undefined") return crypto.randomUUID();
79
+ let anonymousId = localStorage.getItem(ANONYMOUS_ID_KEY);
80
+ if (!anonymousId) {
81
+ anonymousId = crypto.randomUUID();
82
+ localStorage.setItem(ANONYMOUS_ID_KEY, anonymousId);
83
+ }
84
+ return anonymousId;
85
+ }
64
86
 
65
87
  //#endregion
66
88
  //#region src/events.ts
@@ -1527,10 +1549,12 @@ var WebSocketManager = class {
1527
1549
  const config = getConfig();
1528
1550
  const audioFormat = getSupportedAudioFormat();
1529
1551
  const settings = this.sessionSettings;
1552
+ const anonymousId = getAnonymousId();
1530
1553
  const authMessage = {
1531
1554
  type: MESSAGE_TYPE_AUTH,
1532
1555
  api_key: config.apiKey,
1533
1556
  user_id: config.userId || null,
1557
+ anonymous_id: anonymousId,
1534
1558
  input_language: settings.inputLanguageCode ?? "en-US",
1535
1559
  output_language: settings.outputLanguageCode ?? "en-US",
1536
1560
  smart_format: settings.smartFormat ?? true,