humanbehavior-js 0.1.5 → 0.1.7

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.
@@ -275,7 +275,7 @@ declare class HumanBehaviorAPI {
275
275
  sendEventsChunked(events: any[], sessionId: string): Promise<any[]>;
276
276
  sendUserData(userId: string, userData: Record<string, any>, sessionId: string): Promise<any>;
277
277
  sendUserAuth(userId: string, userData: Record<string, any>, sessionId: string, authFields: string[]): Promise<any>;
278
- sendBeaconEvents(events: any[], sessionId: string): void;
278
+ sendBeaconEvents(events: any[], sessionId: string): boolean;
279
279
  sendCustomEvent(sessionId: string, eventName: string, eventProperties?: Record<string, any>): Promise<any>;
280
280
  sendCustomEventBatch(sessionId: string, events: Array<{
281
281
  eventName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
package/src/api.ts CHANGED
@@ -220,16 +220,24 @@ export class HumanBehaviorAPI {
220
220
  }
221
221
 
222
222
  public sendBeaconEvents(events: any[], sessionId: string) {
223
- const data = new URLSearchParams()
224
- data.append('events', encodeURIComponent(JSON.stringify(events)))
225
- data.append('sessionId', encodeURIComponent(sessionId))
226
- data.append('timestamp', encodeURIComponent(Date.now().toString()))
227
- data.append('apiKey', encodeURIComponent(this.apiKey))
223
+ // Create JSON payload that matches the server's expected format
224
+ const payload = {
225
+ sessionId: sessionId,
226
+ events: events,
227
+ endUserId: null // Beacon doesn't have user context
228
+ };
229
+
230
+ // Convert to Blob for sendBeacon
231
+ const blob = new Blob([JSON.stringify(payload)], {
232
+ type: 'application/json'
233
+ });
228
234
 
229
235
  const success = navigator.sendBeacon(
230
236
  `${this.baseUrl}/api/ingestion/events`,
231
- data
237
+ blob
232
238
  );
239
+
240
+ return success;
233
241
  }
234
242
 
235
243
  async sendCustomEvent(sessionId: string, eventName: string, eventProperties?: Record<string, any>) {
@@ -108,7 +108,7 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
108
108
  // Create new tracker instance with the validated apiKey
109
109
  const tracker = new HumanBehaviorTracker(
110
110
  apiKeyRef.current.trim(),
111
- process.env.NEXT_PUBLIC_INGESTION_URL || 'https://ingestion.humanbehavior.ai'
111
+ 'https://ingest.humanbehavior.co'
112
112
  );
113
113
  setHumanBehavior(tracker);
114
114