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