humanbehavior-js 0.1.6 → 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.
package/dist/cjs/index.js CHANGED
@@ -4372,12 +4372,18 @@ class HumanBehaviorAPI {
4372
4372
  });
4373
4373
  }
4374
4374
  sendBeaconEvents(events, sessionId) {
4375
- const data = new URLSearchParams();
4376
- data.append('events', encodeURIComponent(JSON.stringify(events)));
4377
- data.append('sessionId', encodeURIComponent(sessionId));
4378
- data.append('timestamp', encodeURIComponent(Date.now().toString()));
4379
- data.append('apiKey', encodeURIComponent(this.apiKey));
4380
- navigator.sendBeacon(`${this.baseUrl}/api/ingestion/events`, data);
4375
+ // Create JSON payload that matches the server's expected format
4376
+ const payload = {
4377
+ sessionId: sessionId,
4378
+ events: events,
4379
+ endUserId: null // Beacon doesn't have user context
4380
+ };
4381
+ // Convert to Blob for sendBeacon
4382
+ const blob = new Blob([JSON.stringify(payload)], {
4383
+ type: 'application/json'
4384
+ });
4385
+ const success = navigator.sendBeacon(`${this.baseUrl}/api/ingestion/events`, blob);
4386
+ return success;
4381
4387
  }
4382
4388
  sendCustomEvent(sessionId, eventName, eventProperties) {
4383
4389
  return __awaiter$1(this, void 0, void 0, function* () {